]> git.ipfire.org Git - thirdparty/git.git/commitdiff
rebase -r: do not write MERGE_HEAD unless needed
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Mon, 12 Nov 2018 23:25:58 +0000 (15:25 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 13 Nov 2018 03:04:00 +0000 (12:04 +0900)
When we detect that a `merge` can be skipped because the merged commit
is already an ancestor of HEAD, we do not need to commit, therefore
writing the MERGE_HEAD file is useless.

It is actually worse than useless: a subsequent `git commit` will pick
it up and think that we want to merge that commit, still.

To avoid that, move the code that writes the MERGE_HEAD file to a
location where we already know that the `merge` cannot be skipped.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c
t/t3430-rebase-merges.sh

index 9e1ab3a2a7e3f65cc444cded7f3330bb27be2db8..7a9cd81afb2e3988c3b199738a741e49741489a1 100644 (file)
@@ -3191,10 +3191,6 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
        }
 
        merge_commit = to_merge->item;
-       write_message(oid_to_hex(&merge_commit->object.oid), GIT_SHA1_HEXSZ,
-                     git_path_merge_head(the_repository), 0);
-       write_message("no-ff", 5, git_path_merge_mode(the_repository), 0);
-
        bases = get_merge_bases(head_commit, merge_commit);
        if (bases && oideq(&merge_commit->object.oid,
                           &bases->item->object.oid)) {
@@ -3203,6 +3199,10 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
                goto leave_merge;
        }
 
+       write_message(oid_to_hex(&merge_commit->object.oid), GIT_SHA1_HEXSZ,
+                     git_path_merge_head(the_repository), 0);
+       write_message("no-ff", 5, git_path_merge_mode(the_repository), 0);
+
        for (j = bases; j; j = j->next)
                commit_list_insert(j->item, &reversed);
        free_commit_list(bases);
index 1f08a336878c21f67586d647571cea2ea85c3a73..cc5646836fce1aaaa01556450a9b017c7a853088 100755 (executable)
@@ -396,7 +396,7 @@ test_expect_success 'with --autosquash and --exec' '
        grep "G: +G" actual
 '
 
-test_expect_failure '--continue after resolving conflicts after a merge' '
+test_expect_success '--continue after resolving conflicts after a merge' '
        git checkout -b already-has-g E &&
        git cherry-pick E..G &&
        test_commit H2 &&