Skip to content

Commit e5ee33e

Browse files
phillipwoodgitster
authored andcommitted
rebase --continue: remove .git/MERGE_MSG
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 <[email protected]> Signed-off-by: Phillip Wood <[email protected]> Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bed9b4e commit e5ee33e

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

sequencer.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4717,6 +4717,9 @@ static int commit_staged_changes(struct repository *r,
47174717
refs_delete_ref(get_main_ref_store(r), "",
47184718
"CHERRY_PICK_HEAD", NULL, 0))
47194719
return error(_("could not remove CHERRY_PICK_HEAD"));
4720+
if (unlink(git_path_merge_msg(r)) && errno != ENOENT)
4721+
return error_errno(_("could not remove '%s'"),
4722+
git_path_merge_msg(r));
47204723
if (!final_fixup)
47214724
return 0;
47224725
}

t/t3403-rebase-skip.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ test_expect_success setup '
2020
git add hello &&
2121
git commit -m "hello" &&
2222
git branch skip-reference &&
23+
git tag hello &&
2324
2425
echo world >> hello &&
2526
git commit -a -m "hello world" &&
@@ -96,6 +97,13 @@ test_expect_success 'moved back to branch correctly' '
9697

9798
test_debug 'gitk --all & sleep 1'
9899

100+
test_expect_success 'skipping final pick removes .git/MERGE_MSG' '
101+
test_must_fail git rebase --onto hello reverted-goodbye^ \
102+
reverted-goodbye &&
103+
git rebase --skip &&
104+
test_path_is_missing .git/MERGE_MSG
105+
'
106+
99107
test_expect_success 'correct advice upon picking empty commit' '
100108
test_when_finished "git rebase --abort" &&
101109
test_must_fail git rebase -i --onto goodbye \

t/t3418-rebase-continue.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ test_expect_success 'merge based rebase --continue with works with touched file'
3131
git rebase --continue
3232
'
3333

34+
test_expect_success 'merge based rebase --continue removes .git/MERGE_MSG' '
35+
git checkout -f --detach topic &&
36+
37+
test_must_fail git rebase --onto main HEAD^ &&
38+
git read-tree --reset -u HEAD &&
39+
test_path_is_file .git/MERGE_MSG &&
40+
git rebase --continue &&
41+
test_path_is_missing .git/MERGE_MSG
42+
'
43+
3444
test_expect_success 'apply based rebase --continue works with touched file' '
3545
rm -fr .git/rebase-* &&
3646
git reset --hard &&

0 commit comments

Comments
 (0)