]> git.ipfire.org Git - thirdparty/git.git/blobdiff - rerere.c
rerere: make sure it works even in a workdir attached to a young repository
[thirdparty/git.git] / rerere.c
index d1d3e753955146cadfaf6da274487a4a369f0521..2d8de616347bae80e03cd7dd09bf2dd475ab3e59 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -364,7 +364,7 @@ static int find_conflict(struct string_list *conflict)
 static int merge(const char *name, const char *path)
 {
        int ret;
-       mmfile_t cur, base, other;
+       mmfile_t cur = {NULL, 0}, base = {NULL, 0}, other = {NULL, 0};
        mmbuffer_t result = {NULL, 0};
 
        if (handle_file(path, NULL, rerere_path(name, "thisimage")) < 0)
@@ -372,8 +372,10 @@ static int merge(const char *name, const char *path)
 
        if (read_mmfile(&cur, rerere_path(name, "thisimage")) ||
                        read_mmfile(&base, rerere_path(name, "preimage")) ||
-                       read_mmfile(&other, rerere_path(name, "postimage")))
-               return 1;
+                       read_mmfile(&other, rerere_path(name, "postimage"))) {
+               ret = 1;
+               goto out;
+       }
        ret = ll_merge(&result, path, &base, &cur, "", &other, "", 0);
        if (!ret) {
                FILE *f = fopen(path, "w");
@@ -387,6 +389,7 @@ static int merge(const char *name, const char *path)
                                     strerror(errno));
        }
 
+out:
        free(cur.ptr);
        free(base.ptr);
        free(other.ptr);
@@ -519,8 +522,7 @@ static int is_rerere_enabled(void)
        if (rerere_enabled < 0)
                return rr_cache_exists;
 
-       if (!rr_cache_exists &&
-           (mkdir(rr_cache, 0777) || adjust_shared_perm(rr_cache)))
+       if (!rr_cache_exists && mkdir_in_gitdir(rr_cache))
                die("Could not create directory %s", rr_cache);
        return 1;
 }