git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/3] rebase --continue: remove .git/MERGE_MSG

From
PGPhillip Wood via GitGitGadget <gitgitgadget@gmail.com>
Date
Aug 10, 2021, 09:31 UTC
Message-ID
<6a63b657f1313ea6d4141c37a7c24bca691ce107.1628587917.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1013.git.1628587917.gitgitgadget@gmail.com>
From: Phillip Wood <phillip.wood@dunelm.org.uk>

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>
---
 sequencer.c                |  3 +++
 t/t3403-rebase-skip.sh     |  8 ++++++++
 t/t3418-rebase-continue.sh | 10 ++++++++++
 3 files changed, 21 insertions(+)
diff --git a/sequencer.c b/sequencer.c
index 7f07cd00f3f..52c7b461179 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -4716,6 +4716,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;
 	}
diff --git a/t/t3403-rebase-skip.sh b/t/t3403-rebase-skip.sh
index a44e68d0ffb..f6e48644978 100755
--- a/t/t3403-rebase-skip.sh
+++ b/t/t3403-rebase-skip.sh
@@ -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 \
diff --git a/t/t3418-rebase-continue.sh b/t/t3418-rebase-continue.sh
index e4cb8be0418..f23996c9be0 100755
--- a/t/t3418-rebase-continue.sh
+++ b/t/t3418-rebase-continue.sh
@@ -31,6 +31,16 @@ test_expect_success 'interactive rebase --continue works with touched file' '
 	git rebase --continue
 '
 
+test_expect_success '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 'non-interactive rebase --continue works with touched file' '
 	rm -fr .git/rebase-* &&
 	git reset --hard &&
-- 
gitgitgadget
Previous: Phillip WoodNext: Elijah Newren
Message 14 of 25 in “rebase --continue: remove .git/MERGE_MSG”
  1. 0/3 rebase --continue: remove .git/MERGE_MSGPhillip Wood via GitGitGadget, Aug 10, 2021
  2. 1/3 t3403: fix commit authorshipPhillip Wood via GitGitGadget, Aug 10, 2021
  3. Elijah NewrenAug 10, 2021
  4. Junio C HamanoAug 10, 2021
  5. Phillip WoodAug 12, 2021
  6. Johannes SchindelinAug 14, 2021
  7. Junio C HamanoAug 15, 2021
  8. Phillip WoodAug 15, 2021
  9. Junio C HamanoAug 16, 2021
  10. Phillip WoodAug 17, 2021
  11. 2/3 rebase --apply: restore some testsPhillip Wood via GitGitGadget, Aug 10, 2021
  12. Elijah NewrenAug 10, 2021
  13. Phillip WoodAug 12, 2021
  14. 3/3 rebase --continue: remove .git/MERGE_MSGPhillip Wood via GitGitGadget, Aug 10, 2021
  15. Elijah NewrenAug 10, 2021
  16. 0/3 rebase --continue: remove .git/MERGE_MSGPhillip Wood via GitGitGadget, Aug 12, 2021
  17. 1/3 t3403: fix commit authorshipPhillip Wood via GitGitGadget, Aug 12, 2021
  18. 2/3 rebase --apply: restore some testsPhillip Wood via GitGitGadget, Aug 12, 2021
  19. 3/3 rebase --continue: remove .git/MERGE_MSGPhillip Wood via GitGitGadget, Aug 12, 2021
  20. Junio C HamanoAug 13, 2021
  21. Phillip WoodAug 14, 2021
  22. Elijah NewrenAug 13, 2021
  23. Junio C HamanoAug 13, 2021
  24. Elijah NewrenAug 13, 2021
  25. Phillip WoodAug 14, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.