aboutsummaryrefslogtreecommitdiff
path: root/merge-recursive.c
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2017-12-21 11:19:07 -0800
committerJunio C Hamano <gitster@pobox.com>2017-12-22 12:20:38 -0800
commit65170c07d466b18364e0d2b6a360900c073b600f (patch)
treea49f75c8833813cf08d9c6b81a3bc4f6c7eafd24 /merge-recursive.c
parentb101793c431b858e49b909bb309a87145fb7348c (diff)
downloadgit-65170c07d466b18364e0d2b6a360900c073b600f.tar.gz
git-65170c07d466b18364e0d2b6a360900c073b600f.tar.xz
merge-recursive: avoid incorporating uncommitted changes in a merge
builtin/merge.c contains this important requirement for merge strategies: /* * At this point, we need a real merge. No matter what strategy * we use, it would operate on the index, possibly affecting the * working tree, and when resolved cleanly, have the desired * tree in the index -- this means that the index must be in * sync with the head commit. The strategies are responsible * to ensure this. */ merge-recursive does not do this check directly, instead it relies on unpack_trees() to do it. However, merge_trees() has a special check for the merge branch exactly matching the merge base; when it detects that situation, it returns early without calling unpack_trees(), because it knows that the HEAD commit already has the correct result. Unfortunately, it didn't check that the index matched HEAD, so after it returned, the outer logic ended up creating a merge commit that included something other than HEAD. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'merge-recursive.c')
-rw-r--r--merge-recursive.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/merge-recursive.c b/merge-recursive.c
index 9fb0b9f8f..be01f528c 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1952,6 +1952,13 @@ int merge_trees(struct merge_options *o,
}
if (oid_eq(&common->object.oid, &merge->object.oid)) {
+ struct strbuf sb = STRBUF_INIT;
+
+ if (index_has_changes(&sb)) {
+ err(o, _("Dirty index: cannot merge (dirty: %s)"),
+ sb.buf);
+ return 0;
+ }
output(o, 0, _("Already up to date!"));
*result = head;
return 1;