]> git.ipfire.org Git - thirdparty/git.git/commitdiff
rebase --continue: remove .git/MERGE_MSG
authorPhillip Wood <phillip.wood@dunelm.org.uk>
Thu, 12 Aug 2021 13:42:09 +0000 (13:42 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 13 Aug 2021 18:36:22 +0000 (11:36 -0700)
If the user skips the final commit by removing all the changes from
the index and worktree with 'git restore' (or read-tree) and then runs
'git rebase --continue' .git/MERGE_MSG is left behind. This will seed
the commit message the next time the user commits which is not what we
want to happen.

Reported-by: Victor Gambier <vgambier@excilys.com>
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c
t/t3403-rebase-skip.sh
t/t3418-rebase-continue.sh

index 0bec01cf38e8173c930b84250a61e84eb0c6963b..cb3c93c272a2d0aea409a7d4f8a1eac7d70cc3f0 100644 (file)
@@ -4717,6 +4717,9 @@ static int commit_staged_changes(struct repository *r,
                    refs_delete_ref(get_main_ref_store(r), "",
                                    "CHERRY_PICK_HEAD", NULL, 0))
                        return error(_("could not remove CHERRY_PICK_HEAD"));
+               if (unlink(git_path_merge_msg(r)) && errno != ENOENT)
+                       return error_errno(_("could not remove '%s'"),
+                                          git_path_merge_msg(r));
                if (!final_fixup)
                        return 0;
        }
index a44e68d0ffbe2bf20f4c994c9f659d7246110a83..f6e48644978b63ab00ccf40cca379e0770aef0b9 100755 (executable)
@@ -20,6 +20,7 @@ test_expect_success setup '
        git add hello &&
        git commit -m "hello" &&
        git branch skip-reference &&
+       git tag hello &&
 
        echo world >> hello &&
        git commit -a -m "hello world" &&
@@ -96,6 +97,13 @@ test_expect_success 'moved back to branch correctly' '
 
 test_debug 'gitk --all & sleep 1'
 
+test_expect_success 'skipping final pick removes .git/MERGE_MSG' '
+       test_must_fail git rebase --onto hello reverted-goodbye^ \
+               reverted-goodbye &&
+       git rebase --skip &&
+       test_path_is_missing .git/MERGE_MSG
+'
+
 test_expect_success 'correct advice upon picking empty commit' '
        test_when_finished "git rebase --abort" &&
        test_must_fail git rebase -i --onto goodbye \
index bda5e5db802f3b547c41799f49d1f99157c2bb8e..738fbae9b291b38f7129ec6321819c70cdc5aeae 100755 (executable)
@@ -31,6 +31,16 @@ test_expect_success 'merge based rebase --continue with works with touched file'
        git rebase --continue
 '
 
+test_expect_success 'merge based rebase --continue removes .git/MERGE_MSG' '
+       git checkout -f --detach topic &&
+
+       test_must_fail git rebase --onto main HEAD^ &&
+       git read-tree --reset -u HEAD &&
+       test_path_is_file .git/MERGE_MSG &&
+       git rebase --continue &&
+       test_path_is_missing .git/MERGE_MSG
+'
+
 test_expect_success 'apply based rebase --continue works with touched file' '
        rm -fr .git/rebase-* &&
        git reset --hard &&