rebase -i: respect commit.cleanup when picking fixups

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Phillip Wood committed Sep 18, 2025 at 10:00 UTC 5b44c3bd578ce6bd7071faa0dff5fcfc06a0b36a
2 files changed +22 -7
sequencer.c
-1
@@ -2434,7 +2434,6 @@ static int do_pick_commit(struct repository *r,
2434 if (!final_fixup)
2435 msg_file = rebase_path_squash_msg();
2436 else if (file_exists(rebase_path_fixup_msg())) {
2437 - flags |= VERBATIM_MSG;
2437 msg_file = rebase_path_fixup_msg();
2438 } else {
2439 const char *dest = git_path_squash_msg(r);
t/t3415-rebase-autosquash.sh
+22 -6
@@ -476,12 +476,28 @@ test_expect_success 'fixup a fixup' '
476 test XZWY = $(git show | tr -cd W-Z)
477 '
478
479 -test_expect_success 'fixup does not clean up commit message' '
480 - oneline="#818" &&
481 - git commit --allow-empty -m "$oneline" &&
482 - git commit --fixup HEAD --allow-empty &&
483 - git -c commit.cleanup=strip rebase -ki --autosquash HEAD~2 &&
484 - test "$oneline" = "$(git show -s --format=%s)"
479 +test_expect_success 'pick and fixup respect commit.cleanup' '
480 + git reset --hard base &&
481 + test_commit --no-tag "fixup! second commit" file1 fixup &&
482 + test_commit something &&
483 + write_script .git/hooks/prepare-commit-msg <<-\EOF &&
484 + printf "\n# Prepared\n" >> "$1"
485 + EOF
486 + git rebase -i --autosquash HEAD~3 &&
487 + test_commit_message HEAD~1 <<-\EOF &&
488 + second commit
489 +
490 + # Prepared
491 + EOF
492 + test_commit_message HEAD <<-\EOF &&
493 + something
494 +
495 + # Prepared
496 + EOF
497 + git reset --hard something &&
498 + git -c commit.cleanup=strip rebase -i --autosquash HEAD~3 &&
499 + test_commit_message HEAD~1 -m "second commit" &&
500 + test_commit_message HEAD -m "something"
501 '
502
503 test_done