Subject: [PATCH v4 29/29] sequencer: honor --trailer with fixup -C

From: Li Chen <[email-masked]>
Date: Tue, 14 Oct 2025 20:24:42 +0800

Add an interactive rebase test that exercises
todo lists containing fixup and fixup -C commands,
and teach append_squash_message() to append trailers
when replacing the commit message.

Signed-off-by: Li Chen <[email-masked]>
---
 sequencer.c               |  4 ++++
 t/t3440-rebase-trailer.sh | 27 +++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/sequencer.c b/sequencer.c
index c02364cfce..fbf35cb474 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2027,6 +2027,10 @@ static int append_squash_message(struct strbuf *buf, const char *body,
 		if (opts->signoff)
 			append_signoff(buf, 0, 0);
 
+		if (opts->trailer_args.nr &&
+			amend_strbuf_with_trailers(buf, &opts->trailer_args))
+			return error(_("unable to add trailers to commit message"));
+
 		if ((command == TODO_FIXUP) &&
 		    (flag & TODO_REPLACE_FIXUP_MSG) &&
 		    (file_exists(rebase_path_fixup_msg()) ||
diff --git a/t/t3440-rebase-trailer.sh b/t/t3440-rebase-trailer.sh
index ca0619655e..d0526ea0e9 100755
--- a/t/t3440-rebase-trailer.sh
+++ b/t/t3440-rebase-trailer.sh
@@ -97,6 +97,33 @@ test_expect_success 'rebase -m --trailer adds trailer after conflicts' '
 	expect_trailer_msg HEAD^ "third"
 '
 
+test_expect_success '--trailer handles fixup commands in todo list' '
+	git checkout -B fixup-trailer HEAD &&
+	test_commit fixup-base base &&
+	test_commit fixup-second second &&
+	first_short=$(git rev-parse --short fixup-base) &&
+	second_short=$(git rev-parse --short fixup-second) &&
+	cat >todo <<EOF &&
+pick $first_short fixup-base
+fixup $second_short fixup-second
+EOF
+	(
+		set_replace_editor todo &&
+		git rebase -i --trailer "$REVIEWED_BY_TRAILER" HEAD~2
+	) &&
+	expect_trailer_msg HEAD "fixup-base" &&
+	git reset --hard fixup-second &&
+	cat >todo <<EOF &&
+pick $first_short fixup-base
+fixup -C $second_short fixup-second
+EOF
+	(
+		set_replace_editor todo &&
+		git rebase -i --trailer "$REVIEWED_BY_TRAILER" HEAD~2
+	) &&
+	expect_trailer_msg HEAD "fixup-second"
+'
+
 test_expect_success 'rebase --root --trailer updates every commit' '
 	git checkout first &&
 	git -c trailer.review.key=Reviewed-by rebase --root \
-- 
2.51.0