Skip to content

Commit ff2febc

Browse files
committed
rebase -i: respect commit.cleanup when picking fixups
Since f7d42ce (rebase -i: do leave commit message intact in fixup! chains, 2021-01-28) the sequencer has passed the VERBATIM_MSG flag when committing the final fixup in a chain. This was added in response to a bug report[1] where the commit message was being cleaned up when it should not be. The cause of that bug was that before f7d42ce 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 that respects commit.cleanup. Fix this by not setting any explicit cleanup flag when committing the final fixup which matches the way "pick" commands behave. The test added in f7d42ce 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/CANVGpwZGbzYLMeMze64e_OU9p3bjyEgzC5thmNBr6LttBt+YGw@mail.gmail.com/ Signed-off-by: Phillip Wood <[email protected]>
1 parent 92c87bd commit ff2febc

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

sequencer.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2436,7 +2436,6 @@ static int do_pick_commit(struct repository *r,
24362436
if (!final_fixup)
24372437
msg_file = rebase_path_squash_msg();
24382438
else if (file_exists(rebase_path_fixup_msg())) {
2439-
flags |= VERBATIM_MSG;
24402439
msg_file = rebase_path_fixup_msg();
24412440
} else {
24422441
const char *dest = git_path_squash_msg(r);

t/t3415-rebase-autosquash.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,28 @@ test_expect_success 'fixup a fixup' '
486486
test XZWY = $(git show | tr -cd W-Z)
487487
'
488488

489-
test_expect_success 'fixup does not clean up commit message' '
490-
oneline="#818" &&
491-
git commit --allow-empty -m "$oneline" &&
492-
git commit --fixup HEAD --allow-empty &&
493-
git -c commit.cleanup=strip rebase -ki --autosquash HEAD~2 &&
494-
test "$oneline" = "$(git show -s --format=%s)"
489+
test_expect_success 'pick and fixup respect commit.cleanup' '
490+
git reset --hard base &&
491+
test_commit --no-tag "fixup! second commit" file1 fixup &&
492+
test_commit something &&
493+
write_script .git/hooks/prepare-commit-msg <<-\EOF &&
494+
printf "\n# Prepared\n" >> "$1"
495+
EOF
496+
git rebase -i --autosquash HEAD~3 &&
497+
test_commit_message HEAD~1 <<-\EOF &&
498+
second commit
499+
500+
# Prepared
501+
EOF
502+
test_commit_message HEAD <<-\EOF &&
503+
something
504+
505+
# Prepared
506+
EOF
507+
git reset --hard something &&
508+
git -c commit.cleanup=strip rebase -i --autosquash HEAD~3 &&
509+
test_commit_message HEAD~1 -m "second commit" &&
510+
test_commit_message HEAD -m "something"
495511
'
496512

497513
test_done

0 commit comments

Comments
 (0)