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

[PATCH 1/2] rebase -i: respect commit.cleanup when picking fixups

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Sep 18, 2025, 09:00 UTC
Message-ID
<8fb1b4b4a5f4857a3d7d98d029b22904751ec144.1758186038.git.phillip.wood@dunelm.org.uk>
In-Reply-To
<cover.1758186038.git.phillip.wood@dunelm.org.uk>
From: Phillip Wood <phillip.wood@dunelm.org.uk>

If the user uses a prepare-commit-msg hook to add comments to the commit message template and sets commit.cleanup to remove them when the commit is created then the comments will not be removed when rebase commits the final command in a chain of "fixup" commands[1]. This happens because f7d42ceec52 (rebase -i: do leave commit message intact in fixup! chains, 2021-01-28) started passing the VERBATIM_MSG flag when committing the final command in a chain of "fixup" commands. That change was added in response to a bug report[2] where the commit message was being cleaned up when it should not be. The cause of that bug was that before f7d42ceec52 the sequencer passed CLEANUP_MSG when committing the final fixup. That commit should have simply removed the CLEANUP_MSG flag, not changed it to VERBATIM_MSG. Using VERBATIM_MSG ignores the user's commit.cleanup config when committing the final fixup which means it behaves differently to an ordinary "pick" command which respects commit.cleanup.

Fix this by not setting an explicit cleanup flag when committing the final fixup which matches the way "pick" commands behave. The test added in f7d42ceec52 is replaced with one that checks that "fixup" and "pick" commands do not clean up the message when commit.cleanup is not set and do clean up the message when it is set.

[1] https://lore.kernel.org/git/CA+itcS3DxbgpFy2aPRvHQvTAYE=dU0kfeDdidVwWLU=rBAWR4w@mail.gmail.com [2] https://lore.kernel.org/git/CANVGpwZGbzYLMeMze64e_OU9p3bjyEgzC5thmNBr6LttBt+YGw@mail.gmail.com

Reported-by: Simon Cheng <cyqsimon@gmail.com>
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 sequencer.c                  |  1 -
 t/t3415-rebase-autosquash.sh | 28 ++++++++++++++++++++++------
 2 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/sequencer.c b/sequencer.c
index 9ae40a91b24..47c57c2ea3c 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2436,7 +2436,6 @@ static int do_pick_commit(struct repository *r,
 		if (!final_fixup)
 			msg_file = rebase_path_squash_msg();
 		else if (file_exists(rebase_path_fixup_msg())) {
-			flags |= VERBATIM_MSG;
 			msg_file = rebase_path_fixup_msg();
 		} else {
 			const char *dest = git_path_squash_msg(r);
diff --git a/t/t3415-rebase-autosquash.sh b/t/t3415-rebase-autosquash.sh
index 5d093e3a7ab..5033411a431 100755
--- a/t/t3415-rebase-autosquash.sh
+++ b/t/t3415-rebase-autosquash.sh
@@ -486,12 +486,28 @@ test_expect_success 'fixup a fixup' '
 	test XZWY = $(git show | tr -cd W-Z)
 '
 
-test_expect_success 'fixup does not clean up commit message' '
-	oneline="#818" &&
-	git commit --allow-empty -m "$oneline" &&
-	git commit --fixup HEAD --allow-empty &&
-	git -c commit.cleanup=strip rebase -ki --autosquash HEAD~2 &&
-	test "$oneline" = "$(git show -s --format=%s)"
+test_expect_success 'pick and fixup respect commit.cleanup' '
+	git reset --hard base &&
+	test_commit --no-tag "fixup! second commit" file1 fixup &&
+	test_commit something &&
+	write_script .git/hooks/prepare-commit-msg <<-\EOF &&
+	printf "\n# Prepared\n" >> "$1"
+	EOF
+	git rebase -i --autosquash HEAD~3 &&
+	test_commit_message HEAD~1 <<-\EOF &&
+	second commit
+
+	# Prepared
+	EOF
+	test_commit_message HEAD <<-\EOF &&
+	something
+
+	# Prepared
+	EOF
+	git reset --hard something &&
+	git -c commit.cleanup=strip rebase -i --autosquash HEAD~3 &&
+	test_commit_message HEAD~1 -m "second commit" &&
+	test_commit_message HEAD -m "something"
 '
 
 test_done
-- 
2.51.0.595.g259a2096d9c
Previous: Phillip WoodNext: Junio C Hamano
Message 2 of 4 in “rebase -i: respect commit.cleanup when picking fixups”
  1. 0/2 rebase -i: respect commit.cleanup when picking fixupsPhillip Wood, Sep 18, 2025
  2. 1/2 rebase -i: respect commit.cleanup when picking fixupsPhillip Wood, Sep 18, 2025
  3. Junio C HamanoSep 18, 2025
  4. 2/2 sequencer: remove VERBATIM_MSG flagPhillip Wood, Sep 18, 2025

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.