Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rerere.c42
-rwxr-xr-xt/t4200-rerere.sh17
2 files changed, 41 insertions, 18 deletions
diff --git a/rerere.c b/rerere.c
index fbdade8720..a1e296312b 100644
--- a/rerere.c
+++ b/rerere.c
@@ -117,7 +117,9 @@ static struct rerere_dir *find_rerere_dir(const char *hex)
static int has_rerere_resolution(const struct rerere_id *id)
{
- return (id->collection->status & RR_HAS_POSTIMAGE);
+ const int both = RR_HAS_POSTIMAGE|RR_HAS_PREIMAGE;
+
+ return ((id->collection->status & both) == both);
}
static struct rerere_id *new_rerere_id_hex(char *hex)
@@ -806,24 +808,30 @@ static int do_plain_rerere(struct string_list *rr, int fd)
string_list_insert(rr, path)->util = id;
/*
- * If the directory does not exist, create
- * it. mkdir_in_gitdir() will fail with
- * EEXIST if there already is one.
- *
- * NEEDSWORK: make sure "gc" does not remove
- * preimage without removing the directory.
+ * Ensure that the directory exists.
+ * mkdir_in_gitdir() will fail with EEXIST if there
+ * already is one.
*/
- if (mkdir_in_gitdir(rerere_path(id, NULL)))
- continue;
+ if (mkdir_in_gitdir(rerere_path(id, NULL)) &&
+ errno != EEXIST)
+ continue; /* NEEDSWORK: perhaps we should die? */
- /*
- * We are the first to encounter this
- * conflict. Ask handle_file() to write the
- * normalized contents to the "preimage" file.
- */
- handle_file(path, NULL, rerere_path(id, "preimage"));
- id->collection->status |= RR_HAS_PREIMAGE;
- fprintf(stderr, "Recorded preimage for '%s'\n", path);
+ if (id->collection->status & RR_HAS_PREIMAGE) {
+ ;
+ } else {
+ /*
+ * We are the first to encounter this
+ * conflict. Ask handle_file() to write the
+ * normalized contents to the "preimage" file.
+ *
+ * NEEDSWORK: what should happen if we had a
+ * leftover postimage that is totally
+ * unrelated? Perhaps we should unlink it?
+ */
+ handle_file(path, NULL, rerere_path(id, "preimage"));
+ id->collection->status |= RR_HAS_PREIMAGE;
+ fprintf(stderr, "Recorded preimage for '%s'\n", path);
+ }
}
for (i = 0; i < rr->nr; i++)
diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
index ed9c91e25b..c4280110bc 100755
--- a/t/t4200-rerere.sh
+++ b/t/t4200-rerere.sh
@@ -184,12 +184,27 @@ test_expect_success 'rerere updates postimage timestamp' '
'
test_expect_success 'rerere clear' '
- rm $rr/postimage &&
+ mv $rr/postimage .git/post-saved &&
echo "$sha1 a1" | perl -pe "y/\012/\000/" >.git/MERGE_RR &&
git rerere clear &&
! test -d $rr
'
+test_expect_success 'leftover directory' '
+ git reset --hard &&
+ mkdir -p $rr &&
+ test_must_fail git merge first &&
+ test -f $rr/preimage
+'
+
+test_expect_success 'missing preimage' '
+ git reset --hard &&
+ mkdir -p $rr &&
+ cp .git/post-saved $rr/postimage &&
+ test_must_fail git merge first &&
+ test -f $rr/preimage
+'
+
test_expect_success 'set up for garbage collection tests' '
mkdir -p $rr &&
echo Hello >$rr/preimage &&