rebase: support --trailer
Subsystems (2)
v4 cover rebase: support --trailer
From: Li Chen <[email protected]>
This patch series teaches git rebase a new
--trailer <text> option and, as a prerequisite, moves all trailer handling out of the external interpret-trailers helper and into the builtin code path, as suggested by Phillip Wood.
Patch 0 switches trailer.c to an in-memory implementation (amend_strbuf_with_trailers()). It removes every fork/exec.
Patch 1~8 fix all reviewer comments from v3 for patch 0.
Patch 9 builds on that helper to implement
git rebase --trailer. When the option is given we:
force the merge backend (apply/am backend lacks a message filter), automatically enable --force-rebase so that fast-forwarded commits are rewritten, and append the requested trailer(s) to every rewritten commit.
State is stored in $state_dir/trailer so an interrupted rebase can resume safely. A dedicated test-suite (t3440) exercises plain, conflict, --root, invalid-input scenarios and etc.
The rest patches address all reviewer comments from v3 for patch 9.
All t/*.sh testcases have run successfully.
v4: fix all reviewer comments in v3. [2]
v3: merges the remaining trailer paths into one in-process helper, dropping the
duplicate code, as pointed by Junio and Phillip [1]
v2: fix issues pointed by Phillip
RFC link: https://lore.kernel.org/git/[email protected]/
Comments welcome!
[1]: https://lore.kernel.org/git/[email protected]/
[2]: https://lore.kernel.org/git/[email protected]/
Li Chen (29):
trailer: append trailers in-process and drop the fork to
interpret-trailers
trailer: restore interpret_trailers helper
trailer: drop --trailer prefix handling in amend helper
trailer: move config_head and arg_head to if storage
trailer: use bool for had_trailer_before
interpret-trailers: buffer stdout output
trailer: mirror interpret-trailers output flow
trailer: handle trailer append failures gently
rebase: support --trailer
rebase: inline trailer state paths
rebase: reuse buffer for trailer args
rebase: drop redundant strbuf_release call
rebase: skip stripping of --trailer option prefix
rebase: die on invalid trailer args
rebase: validate trailers with configured separators
sequencer: add trailers to message before writing file
tests: t3440: create expect files at point of use
tests: t3440: check apply backend error includes option
tests: t3440: use test_commit_message for trailer checks
tests: t3440: drop redundant resets and pass branch to rebase where
needed
tests: t3440: assert trailer on HEAD after conflict rebase
rebase: persist --trailer options across restarts
tests: t3440: remove redundant --keep-empty
tests: t3440: use helper for trailer checks
tests: t3440: test --trailer without values
tests: t3440: convert ex.com to example.com
tests: t3440: ensure trailers persist after rebase continue
tests: t3440: exercise trailer config mapping
sequencer: honor --trailer with fixup -C
Documentation/git-rebase.adoc | 7 ++ builtin/commit.c | 2 +- builtin/interpret-trailers.c | 94 +++++------------------- builtin/rebase.c | 50 +++++++++++++ builtin/tag.c | 3 +- sequencer.c | 34 +++++++++ sequencer.h | 4 +- t/meson.build | 1 + t/t3440-rebase-trailer.sh | 134 ++++++++++++++++++++++++++++++++++ trailer.c | 130 ++++++++++++++++++++++++++++++--- trailer.h | 23 +++++- wrapper.c | 16 ++++ wrapper.h | 6 ++ 13 files changed, 411 insertions(+), 93 deletions(-) create mode 100755 t/t3440-rebase-trailer.sh
Signature · 1 line
2.51.0
PATCH v4 1/29 trailer: append trailers in-process and drop the fork to `interpret-trailers`
From: Li Chen <[email protected]>
Route all trailer insertion through trailer_process() and make builtin/interpret-trailers just do file I/O before calling into it. amend_file_with_trailers() now shares the same code path.
This removes the fork/exec and tempfile juggling, cutting overhead and simplifying error handling. No functional change is intended. It also centralizes logic to prepare for follow-up rebase --trailer patch.
--- builtin/interpret-trailers.c | 116 ++++++++------------------------ trailer.c | 125 ++++++++++++++++++++++++++++++++--- trailer.h | 18 ++++- 3 files changed, 157 insertions(+), 102 deletions(-)
builtin/interpret-trailers.c +26 -90
@@ -10,7 +10,6 @@#include "gettext.h" #include "parse-options.h" #include "string-list.h" -#include "tempfile.h" #include "trailer.h" #include "config.h"
@@ -93,37 +92,6 @@ static int parse_opt_parse(const struct option *opt, const char *arg,return 0 ; } -static struct tempfile *trailers_tempfile; - -static FILE *create_in_place_tempfile (const char *file) -{ -struct stat st; -struct strbuf filename_template =STRBUF_INIT ; -const char *tail; -FILE *outfile; - -if (stat (file, &st)) -die_errno (_ ("could not stat %s" ), file); -if (!S_ISREG (st.st_mode)) -die (_ ("file %s is not a regular file" ), file); -if (!(st.st_mode &S_IWUSR )) -die (_ ("file %s is not writable by user" ), file); - -/* Create temporary file in the same directory as the original */ - tail =strrchr (file,'/' ); -if (tail) -strbuf_add (&filename_template, file, tail - file +1 ); -strbuf_addstr (&filename_template,"git-interpret-trailers-XXXXXX" ); - - trailers_tempfile =xmks_tempfile_m (filename_template.buf, st.st_mode); -strbuf_release (&filename_template); - outfile =fdopen_tempfile (trailers_tempfile,"w" ); -if (!outfile) -die_errno (_ ("could not open temporary file" )); - -return outfile; -} -static void read_input_file (struct strbuf *sb,const char *file) {if (file) {
@@ -136,61 +104,6 @@ static void read_input_file(struct strbuf *sb, const char *file)strbuf_complete_line (sb); } -static void interpret_trailers (const struct process_trailer_options *opts, -struct list_head *new_trailer_head, -const char *file) -{ -LIST_HEAD (head); -struct strbuf sb =STRBUF_INIT ; -struct strbuf trailer_block_sb =STRBUF_INIT ; -struct trailer_block *trailer_block; -FILE *outfile = stdout; - -trailer_config_init (); - -read_input_file (&sb, file); - -if (opts->in_place) - outfile =create_in_place_tempfile (file); - - trailer_block =parse_trailers (opts, sb.buf, &head); - -/* Print the lines before the trailer block */ -if (!opts->only_trailers) -fwrite (sb.buf,1 ,trailer_block_start (trailer_block), outfile); - -if (!opts->only_trailers && !blank_line_before_trailer_block (trailer_block)) -fprintf (outfile,"\n" ); - - -if (!opts->only_input) { -LIST_HEAD (config_head); -LIST_HEAD (arg_head); -parse_trailers_from_config (&config_head); -parse_trailers_from_command_line_args (&arg_head, new_trailer_head); -list_splice (&config_head, &arg_head); -process_trailers_lists (&head, &arg_head); - } - -/* Print trailer block. */ -format_trailers (opts, &head, &trailer_block_sb); -free_trailers (&head); -fwrite (trailer_block_sb.buf,1 , trailer_block_sb.len, outfile); -strbuf_release (&trailer_block_sb); - -/* Print the lines after the trailer block as is. */ -if (!opts->only_trailers) -fwrite (sb.buf +trailer_block_end (trailer_block),1 , - sb.len -trailer_block_end (trailer_block), outfile); -trailer_block_release (trailer_block); - -if (opts->in_place) -if (rename_tempfile (&trailers_tempfile, file)) -die_errno (_ ("could not rename temporary file to %s" ), file); - -strbuf_release (&sb); -} - int cmd_interpret_trailers(int argc, const char **argv, const char *prefix,
@@ -232,14 +145,37 @@ int cmd_interpret_trailers(int argc, git_interpret_trailers_usage, options); +trailer_config_init (); +if (argc) {int i; -for (i =0 ; i < argc; i++) -interpret_trailers (&opts, &trailers, argv[i]); +for (i =0 ; i < argc; i++) { +struct strbuf in_buf =STRBUF_INIT ; +struct strbuf out_buf =STRBUF_INIT ; + +read_input_file (&in_buf, argv[i]); +if (trailer_process (&opts, in_buf.buf, &trailers, &out_buf) <0 ) +die (_ ("failed to process trailers for %s" ), argv[i]); +if (opts.in_place) +write_file_buf (argv[i], out_buf.buf, out_buf.len); +else +fwrite (out_buf.buf,1 , out_buf.len, stdout); +strbuf_release (&in_buf); +strbuf_release (&out_buf); + } }else { +struct strbuf in_buf =STRBUF_INIT ; +struct strbuf out_buf =STRBUF_INIT ; +if (opts.in_place)die (_ ("no input file given for in-place editing" )); -interpret_trailers (&opts, &trailers,NULL ); + +read_input_file (&in_buf,NULL ); +if (trailer_process (&opts, in_buf.buf, &trailers, &out_buf) <0 ) +die (_ ("failed to process trailers" )); +fwrite (out_buf.buf,1 , out_buf.len, stdout); +strbuf_release (&in_buf); +strbuf_release (&out_buf); }new_trailers_clear (&trailers);
trailer.c +116 -9
130 lines not on this page · raw message
trailer.h +15 -3
@@ -196,10 +196,22 @@ int trailer_iterator_advance(struct trailer_iterator *iter);void trailer_iterator_release (struct trailer_iterator *iter);/* -* Augment a file to add trailers to it by running git-interpret-trailers. -* This calls run_command() and its return value is the same (i.e. 0 for -* success, various non-zero for other errors). See run-command.h. +* Augment a file to add trailers to it (similar to 'git interpret-trailers'). +* Returns 0 on success or a non-zero error code on failure. */ int amend_file_with_trailers (const char *path,const struct strvec *trailer_args); +/* +* Process trailer lines for a commit message in-memory. +* @opts: trailer processing options (e.g. from parse-options) +* @msg: the input message string +* @new_trailer_head: list of new trailers to add (struct new_trailer_item) +* @out: strbuf to store the resulting message (must be initialized) +* +* Returns 0 on success, <0 on error. +*/ +int trailer_process (const struct process_trailer_options *opts, +const char *msg, +struct list_head *new_trailer_head, +struct strbuf *out);#endif /* TRAILER_H */
Signature · 1 line
2.51.0
Re: [PATCH v4 01/29] trailer: append trailers in-process and drop the fork to `interpret-trailers`
Quoted 8 lines · Li Chen
From: Li Chen <[email protected]>
Route all trailer insertion through
trailer_process()and make builtin/interpret-trailers just do file I/O before calling into it.amend_file_with_trailers()now shares the same code path.This removes the fork/exec and tempfile juggling, cutting overhead and simplifying error handling. No functional change is intended. It also
Why “is intended” instead of “No functional change.”?
Quoted 15 lines
centralizes logic to prepare for follow-up rebase --trailer patch.
Signed-off-by Li Chen <[email protected]>--- builtin/interpret-trailers.c | 116 ++++++++------------------------ trailer.c | 125 ++++++++++++++++++++++++++++++++--- trailer.h | 18 ++++- 3 files changed, 157 insertions(+), 102 deletions(-)[...]
builtin/interpret-trailers.c +0
-0new_trailers_clear (&trailers);trailer.c +0
-0
trailer.c void trailer_iterator_release(struct · line 1230
Quoted 8 lines
trailer.c +2
-1@@ -1224,14 +1224,121 @@ void trailer_iterator_release(struct trailer_iterator *iter) strbuf_release(&iter->key); } -int amend_file_with_trailers (const char *path,const struct strvec *trailer_args) +static int amend_strbuf_with_trailers (struct strbuf *buf, +const struct strvec *trailer_args)
This needs Clang formatting.
Quoted 3 lines
trailer.c +0
-1{ -struct child_process run_trailer =CHILD_PROCESS_INIT ;
Re: [PATCH v4 01/29] trailer: append trailers in-process and drop the fork to `interpret-trailers`
Hi Kristoffer
---- On Wed, 15 Oct 2025 04:43:09 +0800 Kristoffer Haugsbakk <[email protected]> wrote ---
Quoted 31 lines · Li Chen
Quoted 8 lines
From: Li Chen <[email protected]>
Route all trailer insertion through
trailer_process()and make builtin/interpret-trailers just do file I/O before calling into it.amend_file_with_trailers()now shares the same code path.This removes the fork/exec and tempfile juggling, cutting overhead and simplifying error handling. No functional change is intended. It also
Why “is intended” instead of “No functional change.”?
Quoted 19 lines
centralizes logic to prepare for follow-up rebase --trailer patch.
Signed-off-by Li Chen <[email protected]>--- builtin/interpret-trailers.c | 116 ++++++++------------------------ trailer.c | 125 ++++++++++++++++++++++++++++++++--- trailer.h | 18 ++++- 3 files changed, 157 insertions(+), 102 deletions(-) [...] new_trailers_clear(&trailers);trailer.c +0
-0@@ -1224,14 +1224,121 @@ void trailer_iterator_release(struct trailer_iterator *iter) strbuf_release(&iter->key); }
Quoted 6 lines
trailer.c void trailer_iterator_release(struct trailer_iterator *iter) · line 1228
Quoted 4 lines
trailer.c +2
-1-int amend_file_with_trailers (const char *path,const struct strvec *trailer_args) +static int amend_strbuf_with_trailers (struct strbuf *buf, +const struct strvec *trailer_args)This needs Clang formatting.
I apologize for the 4-space indentation in my previous codes due to my editor settings, which is not align with this project(treat tab as 8 space) I will use clang-format in the next version.
Regards,
Li
PATCH v4 2/29 trailer: restore interpret_trailers helper
In reply to Li ChenThe change factors the duplicated read/process/write logic into a single interpret_trailers() helper(which was removed in previous commit) while preserving the original error handling and output paths for both in-place edits and stdout output.
cmd_interpret_trailers() now reuses the helper for each filename and for the stdin path, keeping the option parsing and safety checks intact.
--- builtin/interpret-trailers.c | 50 +++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 23 deletions(-)
builtin/interpret-trailers.c +27 -23
@@ -104,6 +104,30 @@ static void read_input_file(struct strbuf *sb, const char *file)strbuf_complete_line (sb); } +static void interpret_trailers (const struct process_trailer_options *opts, +struct list_head *new_trailer_head, +const char *file) +{ +struct strbuf in_buf =STRBUF_INIT ; +struct strbuf out_buf =STRBUF_INIT ; + +read_input_file (&in_buf, file); +if (trailer_process (opts, in_buf.buf, new_trailer_head, &out_buf) <0 ) { +if (file) +die (_ ("failed to process trailers for %s" ), file); +else +die (_ ("failed to process trailers" )); + } + +if (opts->in_place) +write_file_buf (file, out_buf.buf, out_buf.len); +else +fwrite (out_buf.buf,1 , out_buf.len, stdout); + +strbuf_release (&in_buf); +strbuf_release (&out_buf); +} + int cmd_interpret_trailers(int argc, const char **argv, const char *prefix,
@@ -149,33 +173,13 @@ int cmd_interpret_trailers(int argc,if (argc) {int i; -for (i =0 ; i < argc; i++) { -struct strbuf in_buf =STRBUF_INIT ; -struct strbuf out_buf =STRBUF_INIT ; - -read_input_file (&in_buf, argv[i]); -if (trailer_process (&opts, in_buf.buf, &trailers, &out_buf) <0 ) -die (_ ("failed to process trailers for %s" ), argv[i]); -if (opts.in_place) -write_file_buf (argv[i], out_buf.buf, out_buf.len); -else -fwrite (out_buf.buf,1 , out_buf.len, stdout); -strbuf_release (&in_buf); -strbuf_release (&out_buf); - } +for (i =0 ; i < argc; i++) +interpret_trailers (&opts, &trailers, argv[i]); }else { -struct strbuf in_buf =STRBUF_INIT ; -struct strbuf out_buf =STRBUF_INIT ; -if (opts.in_place)die (_ ("no input file given for in-place editing" )); -read_input_file (&in_buf,NULL ); -if (trailer_process (&opts, in_buf.buf, &trailers, &out_buf) <0 ) -die (_ ("failed to process trailers" )); -fwrite (out_buf.buf,1 , out_buf.len, stdout); -strbuf_release (&in_buf); -strbuf_release (&out_buf); +interpret_trailers (&opts, &trailers,NULL ); }new_trailers_clear (&trailers);
Signature · 1 line
2.51.0
PATCH v4 3/29 trailer: drop --trailer prefix handling in amend helper
In reply to Li ChenMake callers pass plain trailer text instead of recreating the option prefix before invoking interpret-trailers.
--- builtin/commit.c | 2 +- builtin/tag.c | 3 +-- trailer.c | 5 +---- 3 files changed, 3 insertions(+), 7 deletions(-)
builtin/commit.c +1 -1
@@ -1719,7 +1719,7 @@ int cmd_commit(int argc,OPT_STRING (0 ,"fixup" , &fixup_message,N_ ("[(amend|reword):]commit" ),N_ ("use autosquash formatted message to fixup or amend/reword specified commit" )),OPT_STRING (0 ,"squash" , &squash_message,N_ ("commit" ),N_ ("use autosquash formatted message to squash specified commit" )),OPT_BOOL (0 ,"reset-author" , &renew_authorship,N_ ("the commit is authored by me now (used with -C/-c/--amend)" )), -OPT_PASSTHRU_ARGV (0 ,"trailer" , &trailer_args,N_ ("trailer" ),N_ ("add custom trailer(s)" ),PARSE_OPT_NONEG ), +OPT_CALLBACK_F (0 ,"trailer" , &trailer_args,N_ ("trailer" ),N_ ("add custom trailer(s)" ),PARSE_OPT_NONEG , parse_opt_strvec),OPT_BOOL ('s' ,"signoff" , &signoff,N_ ("add a Signed-off-by trailer" )),OPT_FILENAME ('t' ,"template" , &template_file,N_ ("use specified template file" )), OPT_BOOL('e', "edit", &edit_flag, N_("force edit of commit")),
builtin/tag.c +1 -2
@@ -499,8 +499,7 @@ int cmd_tag(int argc,OPT_CALLBACK_F ('m' ,"message" , &msg,N_ ("message" ),N_ ("tag message" ),PARSE_OPT_NONEG , parse_msg_arg),OPT_FILENAME ('F' ,"file" , &msgfile,N_ ("read message from file" )), -OPT_PASSTHRU_ARGV (0 ,"trailer" , &trailer_args,N_ ("trailer" ), -N_ ("add custom trailer(s)" ),PARSE_OPT_NONEG ), +OPT_CALLBACK_F (0 ,"trailer" , &trailer_args,N_ ("trailer" ),N_ ("add custom trailer(s)" ),PARSE_OPT_NONEG , parse_opt_strvec),OPT_BOOL ('e' ,"edit" , &edit_flag,N_ ("force edit of tag message" )),OPT_BOOL ('s' ,"sign" , &opt.sign,N_ ("annotated and GPG-signed tag" )), OPT_CLEANUP(&cleanup_arg),
trailer.c +1 -4
@@ -1235,12 +1235,9 @@ static int amend_strbuf_with_trailers(struct strbuf *buf, opts.no_divider =1 ;for (i =0 ; i < trailer_args->nr; i++) { -const char *arg = trailer_args->v[i]; -const char *text; +const char *text = trailer_args->v[i];struct new_trailer_item *item; -if (!skip_prefix (arg,"--trailer=" , &text)) - text = arg;if (!*text)continue ; item =xcalloc (1 ,sizeof (*item));
Signature · 1 line
2.51.0
PATCH v4 4/29 trailer: move config_head and arg_head to if storage
In reply to Li ChenFrom: Li Chen <[email protected]>
Move LIST_HEAD(config_head) and LIST_HEAD(arg_head) into the non-only_input branch so they are created only when needed. No functional change.
--- trailer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
trailer.c +3 -2
@@ -1265,14 +1265,15 @@ int trailer_process(const struct process_trailer_options *opts, {struct trailer_block *blk;LIST_HEAD (orig_head); -LIST_HEAD (config_head); -LIST_HEAD (arg_head);struct strbuf trailers_sb =STRBUF_INIT ;int had_trailer_before; blk =parse_trailers (opts, msg, &orig_head); had_trailer_before = !list_empty (&orig_head);if (!opts->only_input) { +LIST_HEAD (config_head); +LIST_HEAD (arg_head); +parse_trailers_from_config (&config_head);parse_trailers_from_command_line_args (&arg_head, new_trailer_head);list_splice (&config_head, &arg_head);
Signature · 1 line
2.51.0
PATCH v4 5/29 trailer: use bool for had_trailer_before
In reply to Li ChenFrom: Li Chen <[email protected]>
Switch had_trailer_before from int to bool
to match its logical use. No functional change.
--- trailer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
trailer.c +1 -1
@@ -1266,7 +1266,7 @@ int trailer_process(const struct process_trailer_options *opts,struct trailer_block *blk;LIST_HEAD (orig_head);struct strbuf trailers_sb =STRBUF_INIT ; -int had_trailer_before; +bool had_trailer_before; blk =parse_trailers (opts, msg, &orig_head); had_trailer_before = !list_empty (&orig_head);
Signature · 1 line
2.51.0
PATCH v4 6/29 interpret-trailers: buffer stdout output
In reply to Li ChenSimplified the non-in-place path in interpret_trailers by writing the existing output strbuf directly to stdout without creating a redundant temporary buffer.
--- builtin/interpret-trailers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/interpret-trailers.c +1 -1
@@ -122,7 +122,7 @@ static void interpret_trailers(const struct process_trailer_options *opts,if (opts->in_place)write_file_buf (file, out_buf.buf, out_buf.len);else -fwrite (out_buf.buf,1 , out_buf.len, stdout); +strbuf_write (&out_buf, stdout);strbuf_release (&in_buf);strbuf_release (&out_buf);
Signature · 1 line
2.51.0
PATCH v4 7/29 trailer: mirror interpret-trailers output flow
In reply to Li ChenDrop the early-return branch that mirrored the special case. Let trailer_process() always follow the same path as interpret-trailers. Ensure trailer lists and buffers are freed along the unified exit path.
--- trailer.c | 38 +++++++------------------------------- 1 file changed, 7 insertions(+), 31 deletions(-)
trailer.c +7 -31
@@ -1266,10 +1266,8 @@ int trailer_process(const struct process_trailer_options *opts,struct trailer_block *blk;LIST_HEAD (orig_head);struct strbuf trailers_sb =STRBUF_INIT ; -bool had_trailer_before; blk =parse_trailers (opts, msg, &orig_head); - had_trailer_before = !list_empty (&orig_head);if (!opts->only_input) {LIST_HEAD (config_head);LIST_HEAD (arg_head);
@@ -1280,40 +1278,18 @@ int trailer_process(const struct process_trailer_options *opts,process_trailers_lists (&orig_head, &arg_head); }format_trailers (opts, &orig_head, &trailers_sb); -if (!opts->only_trailers && !opts->only_input && !opts->unfold && - !opts->trim_empty &&list_empty (&orig_head) && - (list_empty (new_trailer_head) || opts->only_input)) { -size_t split =trailer_block_start (blk);/* end-of-log-msg */ -if (!blank_line_before_trailer_block (blk)) { -strbuf_add (out, msg, split); -strbuf_addch (out,'\n' ); -strbuf_addstr (out, msg + split); - }else -strbuf_addstr (out, msg); - -strbuf_release (&trailers_sb); -trailer_block_release (blk); -return 0 ; - }if (opts->only_trailers) {strbuf_addbuf (out, &trailers_sb); - }else if (had_trailer_before) { -strbuf_add (out, msg,trailer_block_start (blk)); -if (!blank_line_before_trailer_block (blk)) -strbuf_addch (out,'\n' ); -strbuf_addbuf (out, &trailers_sb); -strbuf_add (out, msg +trailer_block_end (blk), -strlen (msg) -trailer_block_end (blk)); }else { -size_t cpos =trailer_block_start (blk); -strbuf_add (out, msg, cpos); -if (cpos ==0 )/* empty body → just one \n */ -strbuf_addch (out,'\n' ); -else if (!blank_line_before_trailer_block (blk)) -strbuf_addch (out,'\n' );/* body without trailing blank */ +size_t block_start =trailer_block_start (blk); +size_t block_end =trailer_block_end (blk); +bool need_blank_line = !blank_line_before_trailer_block (blk); +strbuf_add (out, msg, block_start); +if (need_blank_line) +strbuf_addch (out,'\n' );strbuf_addbuf (out, &trailers_sb); -strbuf_add (out, msg + cpos,strlen (msg) - cpos); +strbuf_add (out, msg + block_end,strlen (msg) - block_end); }strbuf_release (&trailers_sb);free_trailers (&orig_head);
Signature · 1 line
2.51.0
PATCH v4 8/29 trailer: handle trailer append failures gently
In reply to Li ChenAdded write_file_buf_gently so callers can rewrite files while surfacing errors instead of aborting.
Updated amend_file_with_trailers to release buffers and propagate trailer and write failures back to the caller, because amend_file_with_trailers shuold not die.
--- trailer.c | 14 ++++++++++---- wrapper.c | 16 ++++++++++++++++ wrapper.h | 6 ++++++ 3 files changed, 32 insertions(+), 4 deletions(-)
trailer.c +10 -4
@@ -9,6 +9,7 @@#include "commit.h" #include "trailer.h" #include "list.h" +#include "wrapper.h" /* * Copyright (c) 2013, 2014 Christian Couder <[email protected]> */
@@ -1308,11 +1309,16 @@ int amend_file_with_trailers(const char *path,if (strbuf_read_file (&buf, path,0 ) <0 )return error_errno ("could not read '%s'" , path); -if (amend_strbuf_with_trailers (&buf, trailer_args)) -die ("failed to append trailers" ); +if (amend_strbuf_with_trailers (&buf, trailer_args)) { +strbuf_release (&buf); +return error ("failed to append trailers" ); + } + +if (write_file_buf_gently (path, buf.buf, buf.len)) { +strbuf_release (&buf); +return -1 ; + } -/* `write_file_buf()` aborts on error internally */ -write_file_buf (path, buf.buf, buf.len);strbuf_release (&buf);return 0 ; }
wrapper.c +16 -0
@@ -688,6 +688,22 @@ void write_file_buf(const char *path, const char *buf, size_t len)die_errno (_ ("could not close '%s'" ), path); } +int write_file_buf_gently (const char *path,const char *buf,size_t len) +{ +int fd =open (path,O_WRONLY |O_CREAT |O_TRUNC ,0666 ); + +if (fd <0 ) +return error_errno (_ ("could not open '%s'" ), path); +if (write_in_full (fd, buf, len) <0 ) { +int ret =error_errno (_ ("could not write to '%s'" ), path); +close (fd); +return ret; + } +if (close (fd)) +return error_errno (_ ("could not close '%s'" ), path); +return 0 ; +} +void write_file (const char *path,const char *fmt, ...) {va_list params;
wrapper.h +6 -0
@@ -56,6 +56,12 @@ static inline ssize_t write_str_in_full(int fd, const char *str)*/ void write_file_buf (const char *path,const char *buf,size_t len); +/** +* Like write_file_buf(), but report errors instead of exiting. Returns 0 on +* success or a negative value on error after emitting a message. +*/ +int write_file_buf_gently (const char *path,const char *buf,size_t len); +/** * Like write_file_buf(), but format the contents into a buffer first. * Additionally, write_file() will append a newline if one is not already
Signature · 1 line
2.51.0
PATCH v4 9/29 rebase: support --trailer
In reply to Li ChenFrom: Li Chen <[email protected]>
Implement a new --trailer <text> option for git rebase (support merge backend only now), which appends arbitrary trailer lines to each rebased commit message.
Reject it if the user passes an option that requires the apply backend (git am) since it lacks message‑filter/trailer hook. otherwise we can just use the merge backend.
Automatically set REBASE_FORCE when any trailer is supplied.
And reject invalid input before user edit the interactive file.
--- Documentation/git-rebase.adoc | 7 +++ builtin/rebase.c | 89 +++++++++++++++++++++++++++++++++ sequencer.c | 13 +++++ sequencer.h | 4 +- t/meson.build | 1 + t/t3440-rebase-trailer.sh | 94 +++++++++++++++++++++++++++++++++++ 6 files changed, 207 insertions(+), 1 deletion(-) create mode 100755 t/t3440-rebase-trailer.sh
Documentation/git-rebase.adoc +7 -0
@@ -488,6 +488,13 @@ See also INCOMPATIBLE OPTIONS below. that if `--interactive` is given then only commits marked to be picked, edited or reworded will have the trailer added. + +--trailer <trailer>:: + Append the given trailer line(s) to every rebased commit + message, processed via linkgit:git-interpret-trailers[1]. + When this option is present *rebase automatically implies* + `--force-rebase` so that fast‑forwarded commits are also + rewritten. + See also INCOMPATIBLE OPTIONS below. -i::
builtin/rebase.c +89 -0
166 lines not on this page · raw message
sequencer.c +13 -0
@@ -420,6 +420,7 @@ void replay_opts_release(struct replay_opts *opts)if (opts->revs)release_revisions (opts->revs);free (opts->revs); +strvec_clear (&opts->trailer_args);replay_ctx_release (ctx);free (opts->ctx); }
@@ -2517,6 +2518,18 @@ static int do_pick_commit(struct repository *r,_ ("dropping %s %s -- patch contents already upstream\n" ), oid_to_hex(&commit->object.oid), msg.subject); }/* else allow == 0 and there's nothing special to do */ + +if (!res && opts->trailer_args.nr && !drop_commit) { +const char *trailer_file = + msg_file ? msg_file :git_path_merge_msg (r); + +if (amend_file_with_trailers (trailer_file, + &opts->trailer_args)) { + res =error (_ ("unable to add trailers to commit message" )); + goto leave; + } + } +if (!opts->no_commit && !drop_commit) {if (author || command ==TODO_REVERT || (flags &AMEND_MSG )) res = do_commit(r, msg_file, author, reflog_action,
sequencer.h +3 -1
@@ -44,6 +44,7 @@ struct replay_opts {int record_origin;int no_commit;int signoff; +struct strvec trailer_args;int allow_ff;int allow_rerere_auto;int allow_empty;
@@ -82,8 +83,9 @@ struct replay_opts {struct replay_ctx *ctx; };#define REPLAY_OPTS_INIT { \ - .edit = -1, \ .action = -1, \ + .edit = -1, \ + .trailer_args = STRVEC_INIT, \ .xopts = STRVEC_INIT, \ .ctx = replay_ctx_new(), \ }
t/meson.build +1 -0
@@ -383,6 +383,7 @@ integration_tests = [ 't3436-rebase-more-options.sh', 't3437-rebase-fixup-options.sh', 't3438-rebase-broken-files.sh', + 't3440-rebase-trailer.sh', 't3500-cherry.sh', 't3501-revert-cherry-pick.sh', 't3502-cherry-pick-merge.sh',
t/t3440-rebase-trailer.sh new file +94 -0
94 lines not on this page · raw message
Signature · 1 line
2.51.0
Quoted 6 lines · Li Chen
From: Li Chen <[email protected]>
Implement a new
--trailer <text>option forgit rebase(support merge backend only now), which appends arbitrary trailer lines to each rebased commit message.
Quoted 7 lines
Reject it if the user passes an option that requires the apply backend (git am) since it lacks message‑filter/trailer hook. otherwise we can just use the merge backend.
Automatically set
REBASE_FORCEwhen any trailer is supplied.And reject invalid input before user edit the interactive file.
s/edit/edits/
Quoted 17 lines
Signed-off-by Li Chen <[email protected]>--- Documentation/git-rebase.adoc | 7 +++ builtin/rebase.c | 89 +++++++++++++++++++++++++++++++++ sequencer.c | 13 +++++ sequencer.h | 4 +- t/meson.build | 1 + t/t3440-rebase-trailer.sh | 94 +++++++++++++++++++++++++++++++++++ 6 files changed, 207 insertions(+), 1 deletion(-) create mode 100755 t/t3440-rebase-trailer.shDocumentation/git-rebase.adoc +0
-0
Documentation/git-rebase.adoc See also INCOMPATIBLE OPTIONS below. · line 497
Quoted 10 lines
Documentation/git-rebase.adoc +7
-0@@ -488,6 +488,13 @@ See also INCOMPATIBLE OPTIONS below. that if `--interactive` is given then only commits marked to be picked, edited or reworded will have the trailer added. + +--trailer <trailer>:: + Append the given trailer line(s) to every rebased commit + message, processed via linkgit:git-interpret-trailers[1]. + When this option is present *rebase automatically implies* + `--force-rebase` so that fast‑forwarded commits are also + rewritten. +
You’ve cut off the second paragraph of --signoff. This should be added after See also below.
Probably also with an =:
--trailer=<trailer>::
Quoted 4 lines
Documentation/git-rebase.adoc +1
-0See also INCOMPATIBLE OPTIONS below. +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Documentation/git-rebase.adoc See also INCOMPATIBLE OPTIONS below.
Quoted 10 lines
Documentation/git-rebase.adoc +10
-0+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-rebase.sh # test_commit_message, helpers + +create_expect() { + cat >"$1" <<-EOF + $2 + + Reviewed-by: Dev <[email protected]>
One level of indentation seems enough?
Documentation/git-rebase.adoc
Quoted 3 lines
Documentation/git-rebase.adoc +2
-0+ EOF +}
Long line.
Quoted 4 lines
Documentation/git-rebase.adoc +3
-0+ git cat-file commit HEAD | grep "^Bug: 456" && + git cat-file commit HEAD | grep -v "^Bug: 123" +'
Hi Kristoffer
---- On Wed, 15 Oct 2025 04:43:33 +0800 Kristoffer Haugsbakk <[email protected]> wrote ---
Quoted 39 lines · Li Chen
Quoted 6 lines
From: Li Chen <[email protected]>
Implement a new
--trailer <text>option forgit rebase(support merge backend only now), which appends arbitrary trailer lines to each rebased commit message.Quoted 7 lines
Reject it if the user passes an option that requires the apply backend (git am) since it lacks message‑filter/trailer hook. otherwise we can just use the merge backend.
Automatically set
REBASE_FORCEwhen any trailer is supplied.And reject invalid input before user edit the interactive file.
s/edit/edits/
Quoted 22 lines
Signed-off-by Li Chen <[email protected]>--- Documentation/git-rebase.adoc | 7 +++ builtin/rebase.c | 89 +++++++++++++++++++++++++++++++++ sequencer.c | 13 +++++ sequencer.h | 4 +- t/meson.build | 1 + t/t3440-rebase-trailer.sh | 94 +++++++++++++++++++++++++++++++++++ 6 files changed, 207 insertions(+), 1 deletion(-) create mode 100755 t/t3440-rebase-trailer.shDocumentation/git-rebase.adoc +2
-0@@ -488,6 +488,13 @@ See also INCOMPATIBLE OPTIONS below. that if `--interactive` is given then only commits marked to be picked, edited or reworded will have the trailer added. + +--trailer <trailer>:: + Append the given trailer line(s) to every rebased commit
Quoted 8 lines
Documentation/git-rebase.adoc See also INCOMPATIBLE OPTIONS below. · line 497
Quoted 5 lines
Documentation/git-rebase.adoc +5
-0+ message, processed via linkgit:git-interpret-trailers[1]. + When this option is present *rebase automatically implies* + `--force-rebase` so that fast‑forwarded commits are also + rewritten. +You’ve cut off the second paragraph of
--signoff. This should be added afterSee alsobelow.
Thanks for catching this.
Quoted 4 lines
Probably also with an
=:--trailer=<trailer>::
It would be added in v6; but both = and should work.
Regards,
Li
PATCH v4 10/29 rebase: inline trailer state paths
In reply to Li ChenSimplified read_basic_state() by dropping the
temporary trailer path variables and callingstate_dir_path("trailer", opts) directly when
loading trailer arguments.
--- builtin/rebase.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
builtin/rebase.c +2 -6
@@ -442,8 +442,6 @@ static int read_basic_state(struct rebase_options *opts)struct strbuf head_name =STRBUF_INIT ;struct strbuf buf =STRBUF_INIT ;struct object_id oid; -const char trailer_state_name[] ="trailer" ; -const char *path =state_dir_path (trailer_state_name, opts); if (!read_oneliner(&head_name, state_dir_path("head-name", opts), READ_ONELINER_WARN_MISSING) ||
@@ -512,7 +510,7 @@ static int read_basic_state(struct rebase_options *opts)strbuf_release (&buf); -if (strbuf_read_file (&buf, path,0 ) >=0 ) { +if (strbuf_read_file (&buf,state_dir_path ("trailer" , opts),0 ) >=0 ) {const char *p = buf.buf, *end = buf.buf + buf.len;while (p < end) {
@@ -535,8 +533,6 @@ static int read_basic_state(struct rebase_options *opts)static int rebase_write_basic_state (struct rebase_options *opts) { -const char trailer_state_name[] ="trailer" ; -write_file (state_dir_path ("head-name" , opts),"%s" , opts->head_name ? opts->head_name :"detached HEAD" ); write_file(state_dir_path("onto", opts), "%s",
@@ -568,7 +564,7 @@ static int rebase_write_basic_state(struct rebase_options *opts)strbuf_addstr (&buf, opts->trailer_args.v[i]);strbuf_addch (&buf,'\n' ); } -write_file (state_dir_path (trailer_state_name, opts), +write_file (state_dir_path ("trailer" , opts),"%s" , buf.buf);strbuf_release (&buf); }
Signature · 1 line
2.51.0
PATCH v4 11/29 rebase: reuse buffer for trailer args
In reply to Li ChenReset the reusable buffer before reading trailer
arguments in read_basic_state() so the existing
allocation can be reused.
--- builtin/rebase.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/rebase.c +1 -1
@@ -508,7 +508,7 @@ static int read_basic_state(struct rebase_options *opts) opts->gpg_sign_opt =xstrdup (buf.buf); } -strbuf_release (&buf); +strbuf_reset (&buf);if (strbuf_read_file (&buf,state_dir_path ("trailer" , opts),0 ) >=0 ) {const char *p = buf.buf, *end = buf.buf + buf.len;
Signature · 1 line
2.51.0
PATCH v4 12/29 rebase: drop redundant strbuf_release call
In reply to Li ChenRemoved the redundant strbuf_release() call inread_basic_state() so the buffer is released once
even if strbuf_read_file() fails.
--- builtin/rebase.c | 1 - 1 file changed, 1 deletion(-)
builtin/rebase.c +0 -1
@@ -524,7 +524,6 @@ static int read_basic_state(struct rebase_options *opts) p = nl +1 ; } -strbuf_release (&buf); }strbuf_release (&buf);
Signature · 1 line
2.51.0
PATCH v4 13/29 rebase: skip stripping of --trailer option prefix
In reply to Li ChenRemoved redundant --trailer= prefix stripping in validate_trailer_args_after_config() since OPT_STRVEC already stores only the argument text.
--- builtin/rebase.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
builtin/rebase.c +1 -5
@@ -1128,13 +1128,9 @@ static int validate_trailer_args_after_config(const struct strvec *cli_args, struct strbuf *err) {for (size_t i =0 ; i < cli_args->nr; i++) { -const char *raw = cli_args->v[i]; -const char *txt;// Key[:=]Val +const char *txt = cli_args->v[i];// Key[:=]Val const char *sep; -if (!skip_prefix (raw,"--trailer=" , &txt)) - txt = raw; -if (!*txt) {strbuf_addstr (err,_ ("empty --trailer argument" ));return -1 ;
Signature · 1 line
2.51.0
PATCH v4 14/29 rebase: die on invalid trailer args
In reply to Li ChenThis can simplify the error handle invalidate_trailer_args_after_config and
its caller.
--- builtin/rebase.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-)
builtin/rebase.c +7 -19
@@ -1124,29 +1124,22 @@ static int check_exec_cmd(const char *cmd)return 0 ; } -static int validate_trailer_args_after_config (const struct strvec *cli_args, -struct strbuf *err) +static void validate_trailer_args_after_config (const struct strvec *cli_args) {for (size_t i =0 ; i < cli_args->nr; i++) {const char *txt = cli_args->v[i];// Key[:=]Val const char *sep; -if (!*txt) { -strbuf_addstr (err,_ ("empty --trailer argument" )); -return -1 ; - } +if (!*txt) +die (_ ("empty --trailer argument" )); sep =strpbrk (txt,":=" );/* there must be key bfore seperator */ -if (sep && sep == txt) { -strbuf_addf (err, -_ ("invalid trailer '%s': missing key before separator" ), - txt); -return -1 ; - } +if (sep && sep == txt) +die (_ ("invalid trailer '%s': missing key before separator" ), + txt); } -return 0 ; } int cmd_rebase(int argc,
@@ -1353,13 +1346,8 @@ int cmd_rebase(int argc, builtin_rebase_usage, 0);if (options.trailer_args.nr) { -struct strbuf err =STRBUF_INIT ; - -if (validate_trailer_args_after_config (&options.trailer_args, &err)) -die ("%s" , err.buf); - +validate_trailer_args_after_config (&options.trailer_args); options.flags |=REBASE_FORCE ; -strbuf_release (&err); }if (preserve_merges_selected)
Signature · 1 line
2.51.0
PATCH v4 15/29 rebase: validate trailers with configured separators
In reply to Li ChenMoved validate_trailer_args_after_config() into trailer.c so trailer argument validation reuses find_separator() and respects configured separators.
--- builtin/rebase.c | 18 ------------------ trailer.c | 25 +++++++++++++++++++++++++ trailer.h | 2 ++ 3 files changed, 27 insertions(+), 18 deletions(-)
builtin/rebase.c +0 -18
@@ -1124,24 +1124,6 @@ static int check_exec_cmd(const char *cmd)return 0 ; } -static void validate_trailer_args_after_config (const struct strvec *cli_args) -{ -for (size_t i =0 ; i < cli_args->nr; i++) { -const char *txt = cli_args->v[i];// Key[:=]Val -const char *sep; - -if (!*txt) -die (_ ("empty --trailer argument" )); - - sep =strpbrk (txt,":=" ); - -/* there must be key bfore seperator */ -if (sep && sep == txt) -die (_ ("invalid trailer '%s': missing key before separator" ), - txt); - } -} - int cmd_rebase(int argc, const char **argv, const char *prefix,
trailer.c +25 -0
@@ -7,6 +7,7 @@#include "string-list.h" #include "run-command.h" #include "commit.h" +#include "strvec.h" #include "trailer.h" #include "list.h" #include "wrapper.h"
@@ -773,6 +774,30 @@ void parse_trailers_from_command_line_args(struct list_head *arg_head,free (cl_separators); } +void validate_trailer_args_after_config (const struct strvec *cli_args) +{ +char *cl_separators; + +trailer_config_init (); + + cl_separators =xstrfmt ("=%s" , separators); + +for (size_t i =0 ; i < cli_args->nr; i++) { +const char *txt = cli_args->v[i]; +ssize_t separator_pos; + +if (!*txt) +die (_ ("empty --trailer argument" )); + + separator_pos =find_separator (txt, cl_separators); +if (separator_pos ==0 ) +die (_ ("invalid trailer '%s': missing key before separator" ), + txt); + } + +free (cl_separators); +} +static const char *next_line (const char *str) {const char *nl =strchrnul (str,'\n' );
trailer.h +2 -0
@@ -68,6 +68,8 @@ void parse_trailers_from_config(struct list_head *config_head);void parse_trailers_from_command_line_args (struct list_head *arg_head,struct list_head *new_trailer_head); +void validate_trailer_args_after_config (const struct strvec *cli_args); +void process_trailers_lists (struct list_head *head,struct list_head *arg_head);
Signature · 1 line
2.51.0
PATCH v4 16/29 sequencer: add trailers to message before writing file
In reply to Li ChenAdded trailer processing to the in-memory commit message within do_pick_commit, ensuring fixup/squash commands remain untouched before the message is written.
--- sequencer.c | 19 ++++++++----------- trailer.c | 4 ++-- trailer.h | 3 +++ 3 files changed, 13 insertions(+), 13 deletions(-)
sequencer.c +8 -11
@@ -2444,6 +2444,14 @@ static int do_pick_commit(struct repository *r,if (opts->signoff && !is_fixup (command))append_signoff (&ctx->message,0 ,0 ); +if (opts->trailer_args.nr && !is_fixup (command)) { +if (amend_strbuf_with_trailers (&ctx->message, + &opts->trailer_args)) { + res =error (_ ("unable to add trailers to commit message" )); + goto leave; + } + } +if (is_rebase_i (opts) &&write_author_script (msg.message) <0 ) res =-1 ; else if (!opts->strategy ||
@@ -2519,17 +2527,6 @@ static int do_pick_commit(struct repository *r, oid_to_hex(&commit->object.oid), msg.subject); }/* else allow == 0 and there's nothing special to do */ -if (!res && opts->trailer_args.nr && !drop_commit) { -const char *trailer_file = - msg_file ? msg_file :git_path_merge_msg (r); - -if (amend_file_with_trailers (trailer_file, - &opts->trailer_args)) { - res =error (_ ("unable to add trailers to commit message" )); - goto leave; - } - } -if (!opts->no_commit && !drop_commit) {if (author || command ==TODO_REVERT || (flags &AMEND_MSG )) res = do_commit(r, msg_file, author, reflog_action,
trailer.c +2 -2
@@ -1250,8 +1250,8 @@ void trailer_iterator_release(struct trailer_iterator *iter)strbuf_release (&iter->key); } -static int amend_strbuf_with_trailers (struct strbuf *buf, -const struct strvec *trailer_args) +int amend_strbuf_with_trailers (struct strbuf *buf, +const struct strvec *trailer_args) {struct process_trailer_options opts =PROCESS_TRAILER_OPTIONS_INIT ;LIST_HEAD (new_trailer_head);
trailer.h +3 -0
@@ -197,6 +197,9 @@ int trailer_iterator_advance(struct trailer_iterator *iter);*/ void trailer_iterator_release (struct trailer_iterator *iter); +int amend_strbuf_with_trailers (struct strbuf *buf, +const struct strvec *trailer_args); +/* * Augment a file to add trailers to it (similar to 'git interpret-trailers'). * Returns 0 on success or a non-zero error code on failure.
Signature · 1 line
2.51.0
Re: [PATCH v4 16/29] sequencer: add trailers to message before writing file
Quoted 15 lines · Li Chen
Added trailer processing to the in-memory commit message within
do_pick_commit, ensuring fixup/squash commands remain untouched before the message is written.Signed-off-by Li Chen <[email protected]>--- sequencer.c | 19 ++++++++----------- trailer.c | 4 ++-- trailer.h | 3 +++ 3 files changed, 13 insertions(+), 13 deletions(-)sequencer.c +0
-0
sequencer.c
Quoted 3 lines
sequencer.c +0
-2-static int amend_strbuf_with_trailers (struct strbuf *buf, -const struct strvec *trailer_args)
Weird indentation. This looks like it needs clang-format.
Quoted 4 lines
sequencer.c +2
-0+int amend_strbuf_with_trailers (struct strbuf *buf, +const struct strvec *trailer_args) {
PATCH v4 17/29 tests: t3440: create expect files at point of use
In reply to Li ChenCreated the expected trailer files within
the individual rebase tests that use them,
simplifying the shared history setup and
avoiding unused fixtures.
--- t/t3440-rebase-trailer.sh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
t/t3440-rebase-trailer.sh +4 -8
@@ -26,14 +26,7 @@ test_expect_success 'setup repo with a small history' ' git checkout -b conflict-branch first && test_commit file-2 file-2 && test_commit conflict file && - test_commit third file && - ident="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" && - create_expect initial-signed "Initial empty commit" && - create_expect first-signed "first" && - create_expect second-signed "second" && - create_expect file2-signed "file-2" && - create_expect third-signed "third" && - create_expect conflict-signed "conflict" + test_commit third file ' test_expect_success 'apply backend is rejected with --trailer' '
@@ -74,6 +67,7 @@ test_expect_success 'multiple Signed-off-by trailers all preserved' ' ' test_expect_success 'rebase -m --trailer adds trailer after conflicts' ' + create_expect file2-signed "file-2" && git reset --hard third && test_must_fail git rebase -m \ --trailer "Reviewed-by: Dev <[email protected]>" \
@@ -85,6 +79,8 @@ test_expect_success 'rebase -m --trailer adds trailer after conflicts' ' ' test_expect_success 'rebase --root --trailer updates every commit' ' + create_expect initial-signed "Initial empty commit" && + create_expect first-signed "first" && git checkout first && git rebase --root --keep-empty \ --trailer "Reviewed-by: Dev <[email protected]>" &&
Signature · 1 line
2.51.0
Re: [PATCH v4 17/29] tests: t3440: create expect files at point of use
Now you start to change the test suite/file that you created for this series. There shouldn’t be a need to do a test file-only patch/commit for a fresh series.
I saw in one of your patches that you removed --keep-empty from a test because “that is the default”. I also saw Phillip’s comment somewhere that said the same thing.
The goal with maturing series is not to add patches on top in each round (if that’s what you are doing). It is to recreate them as if the series was perfectly written to begin with; if one patch introduces --trailers and a test file, then there should be no need with follow-up patches that improve the test file style, refactors it, and so on.
Quoted 1 line
[PATCH v4 17/29] tests: t3440: create expect files at point of use
t3440 is enough.
Quoted 4 lines · Li Chen
Created the expected trailer files within
the individual rebase tests that use them,
simplifying the shared history setup and
avoiding unused fixtures.
The max line length (for prose) is 72 and I don’t know of a minimum (41 here).
Quoted 6 lines
Signed-off-by Li Chen <[email protected]>--- t/t3440-rebase-trailer.sh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)[snip]
Re: [PATCH v4 17/29] tests: t3440: create expect files at point of use
Hi Kristoffer,
Thanks for the review suggestions! I'll address them in the next version.
---- On Wed, 15 Oct 2025 04:41:33 +0800 Kristoffer Haugsbakk <[email protected]> wrote ---
Quoted 8 lines
Now you start to change the test suite/file that you created for this series. There shouldn’t be a need to do a test file-only patch/commit for a fresh series.
I saw in one of your patches that you removed
--keep-emptyfrom a test because “that is the default”. I also saw Phillip’s comment somewhere that said the same thing.
Quoted 6 lines
The goal with maturing series is not to add patches on top in each round (if that’s what you are doing). It is to recreate them as if the series was perfectly written to begin with; if one patch introduces
--trailersand a test file, then there should be no need with follow-up patches that improve the test file style, refactors it, and so on.
Thanks for the tip. I split the changes into separate commits to ease review,
as Phillip suggested in https://lore.kernel.org/git/[email protected]/.
It seems I may have overdone it? If so, I'll try for a better balance in the next version.
Li
Re: [PATCH v4 17/29] tests: t3440: create expect files at point of use
Quoted 8 lines · Li Chen
[snip]
Quoted 1 line
(if that’s what you are doing). It is to recreate them as if the
series
Quoted 4 lines
was perfectly written to begin with; if one patch introduces
--trailersand a test file, then there should be no need with follow-up patches that improve the test file style, refactors it, and so on.
Quoted 7 lines
Thanks for the tip. I split the changes into separate commits to ease review,
as Phillip suggested in
https://lore.kernel.org/git/[email protected]/.It seems I may have overdone it? If so, I'll try for a better balance in the next version.
Thank you. It seems like I should have skimmed the previous rounds more carefully. :)
Cheers
Re: [PATCH v4 17/29] tests: t3440: create expect files at point of use
In reply to Li ChenQuoted 20 lines · Li Chen
Hi Kristoffer,
Thanks for the review suggestions! I'll address them in the next version.
---- On Wed, 15 Oct 2025 04:41:33 +0800 Kristoffer Haugsbakk <[email protected]> wrote ---
Quoted 8 lines
Now you start to change the test suite/file that you created for this series. There shouldn’t be a need to do a test file-only patch/commit for a fresh series.
I saw in one of your patches that you removed
--keep-emptyfrom a test because “that is the default”. I also saw Phillip’s comment somewhere that said the same thing.Quoted 6 lines
The goal with maturing series is not to add patches on top in each round (if that’s what you are doing). It is to recreate them as if the series was perfectly written to begin with; if one patch introduces
--trailersand a test file, then there should be no need with follow-up patches that improve the test file style, refactors it, and so on.
Quoted 4 lines
Thanks for the tip. I split the changes into separate commits to ease review,
as Phillip suggested in https://lore.kernel.org/git/[email protected]/.It seems I may have overdone it? If so, I'll try for a better balance in the next version.
I asked that you did not refactor code at the same time as you moved it. I was expecting a handful of patches, not twenty-nine. The point that Kristoffer makes about this patch is perfectly valid - you add a new test and then correct it in a later patch. Instead you should correct the test where it is introduced as Kirstoffer suggested. Looking at the first patch in this series there seems to have been some miscommunication because it has exactly the same problem as V3. The code that is moved from builtin/interpret-trailers.c to trailer.c is heavily refactored at the same time. Variable names are changed and the code is rearranged so that "git diff --color-moved --color-moved-ws=ignore-indentation-change" detects barely any moved lines. I'll try and leave some more detailed feedback on the first few patches of V5 in the next few days.
Thanks
Phillip
Re: [PATCH v4 17/29] tests: t3440: create expect files at point of use
Hi Phillip,
---- On Thu, 23 Oct 2025 17:04:34 +0800 Phillip Wood <[email protected]> wrote ---
Quoted 25 lines · Li Chen
Quoted 20 lines
Hi Kristoffer,
Thanks for the review suggestions! I'll address them in the next version.
---- On Wed, 15 Oct 2025 04:41:33 +0800 Kristoffer Haugsbakk <[email protected]> wrote ---
Quoted 8 lines
Now you start to change the test suite/file that you created for this series. There shouldn’t be a need to do a test file-only patch/commit for a fresh series.
I saw in one of your patches that you removed
--keep-emptyfrom a test because “that is the default”. I also saw Phillip’s comment somewhere that said the same thing.Quoted 6 lines
The goal with maturing series is not to add patches on top in each round (if that’s what you are doing). It is to recreate them as if the series was perfectly written to begin with; if one patch introduces
--trailersand a test file, then there should be no need with follow-up patches that improve the test file style, refactors it, and so on.Quoted 4 lines
Thanks for the tip. I split the changes into separate commits to ease review,
as Phillip suggested in https://lore.kernel.org/git/[email protected]/.It seems I may have overdone it? If so, I'll try for a better balance in the next version.
Quoted 13 lines
I asked that you did not refactor code at the same time as you moved it. I was expecting a handful of patches, not twenty-nine. The point that Kristoffer makes about this patch is perfectly valid - you add a new test and then correct it in a later patch. Instead you should correct the test where it is introduced as Kirstoffer suggested. Looking at the first patch in this series there seems to have been some miscommunication because it has exactly the same problem as V3. The code that is moved from
builtin/interpret-trailers.ctotrailer.cis heavily refactored at the same time. Variable names are changed and the code is rearranged so that "git diff --color-moved --color-moved-ws=ignore-indentation-change" detects barely any moved lines. I'll try and leave some more detailed feedback on the first few patches of V5 in the next few days.
I mistakenly misunderstood that you meant changes between each patchset version should be reflected by adding new patches. Now I understand that you mean refactoring the original code needs to be reflected in new patches for review. Thank you very Thank you for telling me about --color-moved, and I found that git log also has this parameter. This option is very amazing.
I will do as you requested in the next version.
I sincerely apologize for the misunderstanding and wasted time.
Regards,
Li
Re: [PATCH v4 17/29] tests: t3440: create expect files at point of use
Hi Li
Quoted 7 lines · Li Chen
I mistakenly misunderstood that you meant changes between each patchset version should be reflected by adding new patches. Now I understand that you mean refactoring the original code needs to be reflected in new patches for review. Thank you very Thank you for telling me about --color-moved, and I found that git log also has this parameter. This option is very amazing.
I will do as you requested in the next version.I sincerely apologize for the misunderstanding and wasted time.
Don't worry, I left some more detailled comments on v5 at https://lore.kernel.org/git/[email protected] please do feel free to let me know if you have any questions.
Thanks
Phillip
PATCH v4 18/29 tests: t3440: check apply backend error includes option
In reply to Li ChenFrom: Li Chen <[email protected]>
Updated the rebase trailer test to assert that
the apply-backend error explicitly includes the
--trailer option in its message while retaining
the existing backend check.
--- t/t3440-rebase-trailer.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/t3440-rebase-trailer.sh +1 -1
@@ -34,7 +34,7 @@ test_expect_success 'apply backend is rejected with --trailer' ' test_expect_code 128 \ git rebase --apply --trailer "Reviewed-by: Dev <[email protected]>" \ HEAD^ 2>err && - test_grep "requires the merge backend" err && + test_grep "fatal: --trailer requires the merge backend" err && test_cmp_rev HEAD $head_before '
Signature · 1 line
2.51.0
PATCH v4 19/29 tests: t3440: use test_commit_message for trailer checks
In reply to Li ChenReplaced the pipeline-based trailer assertions with explicit expectations verified by test_commit_message, ensuring the rebase trailer tests catch git command failures reliably.
--- t/t3440-rebase-trailer.sh | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
t/t3440-rebase-trailer.sh +17 -7
@@ -52,18 +52,28 @@ test_expect_success 'reject trailer with missing key before separator' ' test_expect_success 'CLI trailer duplicates allowed; replace policy keeps last' ' git reset --hard third && - git -c trailer.Bug.ifexists=replace -c trailer.Bug.ifmissing=add rebase -m --trailer "Bug: 123" --trailer "Bug: 456" HEAD~1 && - git cat-file commit HEAD | grep "^Bug: 456" && - git cat-file commit HEAD | grep -v "^Bug: 123" + git -c trailer.Bug.ifexists=replace -c trailer.Bug.ifmissing=add \ + rebase -m --trailer "Bug: 123" --trailer "Bug: 456" HEAD~1 && + cat >expect <<-\EOF && + third + + Bug: 456 + EOF + test_commit_message HEAD expect ' test_expect_success 'multiple Signed-off-by trailers all preserved' ' git reset --hard third && git rebase -m \ - --trailer "Signed-off-by: Dev A <[email protected]>" \ - --trailer "Signed-off-by: Dev B <[email protected]>" HEAD~1 && - git cat-file commit HEAD | grep -c "^Signed-off-by:" >count && - test "$(cat count)" = 2 # two new commits + --trailer "Signed-off-by: Dev A <[email protected]>" \ + --trailer "Signed-off-by: Dev B <[email protected]>" HEAD~1 && + cat >expect <<-\EOF && + third + + Signed-off-by: Dev A <[email protected]> + Signed-off-by: Dev B <[email protected]> + EOF + test_commit_message HEAD expect ' test_expect_success 'rebase -m --trailer adds trailer after conflicts' '
Signature · 1 line
2.51.0
PATCH v4 20/29 tests: t3440: drop redundant resets and pass branch to rebase where needed
In reply to Li ChenFrom: Li Chen <[email protected]>
Stop hard-resetting to third in these tests. Where the branch matters, invoke git rebase -m ... HEAD~1 third to make the target explicit and preserve the original semantics.
--- t/t3440-rebase-trailer.sh | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
t/t3440-rebase-trailer.sh +2 -7
@@ -39,21 +39,18 @@ test_expect_success 'apply backend is rejected with --trailer' ' ' test_expect_success 'reject empty --trailer argument' ' - git reset --hard third && test_expect_code 128 git rebase -m --trailer "" HEAD^ 2>err && test_grep "empty --trailer" err ' test_expect_success 'reject trailer with missing key before separator' ' - git reset --hard third && test_expect_code 128 git rebase -m --trailer ": no-key" HEAD^ 2>err && test_grep "missing key before separator" err ' test_expect_success 'CLI trailer duplicates allowed; replace policy keeps last' ' - git reset --hard third && git -c trailer.Bug.ifexists=replace -c trailer.Bug.ifmissing=add \ - rebase -m --trailer "Bug: 123" --trailer "Bug: 456" HEAD~1 && + rebase -m --trailer "Bug: 123" --trailer "Bug: 456" HEAD~1 third && cat >expect <<-\EOF && third
@@ -63,10 +60,9 @@ test_expect_success 'CLI trailer duplicates allowed; replace policy keeps last' ' test_expect_success 'multiple Signed-off-by trailers all preserved' ' - git reset --hard third && git rebase -m \ --trailer "Signed-off-by: Dev A <[email protected]>" \ - --trailer "Signed-off-by: Dev B <[email protected]>" HEAD~1 && + --trailer "Signed-off-by: Dev B <[email protected]>" HEAD~1 third && cat >expect <<-\EOF && third
@@ -78,7 +74,6 @@ test_expect_success 'multiple Signed-off-by trailers all preserved' ' test_expect_success 'rebase -m --trailer adds trailer after conflicts' ' create_expect file2-signed "file-2" && - git reset --hard third && test_must_fail git rebase -m \ --trailer "Reviewed-by: Dev <[email protected]>" \ second third &&
Signature · 1 line
2.51.0
PATCH v4 21/29 tests: t3440: assert trailer on HEAD after conflict rebase
In reply to Li ChenFrom: Li Chen <[email protected]>
Switch the test to check the trailer on HEAD (not HEAD~2) and build the expected message for "third", matching the rebased tip after conflicts.
--- t/t3440-rebase-trailer.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
t/t3440-rebase-trailer.sh +2 -2
@@ -73,14 +73,14 @@ test_expect_success 'multiple Signed-off-by trailers all preserved' ' ' test_expect_success 'rebase -m --trailer adds trailer after conflicts' ' - create_expect file2-signed "file-2" && + create_expect third-signed "third" && test_must_fail git rebase -m \ --trailer "Reviewed-by: Dev <[email protected]>" \ second third && git checkout --theirs file && git add file && git rebase --continue && - test_commit_message HEAD~2 file2-signed + test_commit_message HEAD third-signed ' test_expect_success 'rebase --root --trailer updates every commit' '
Signature · 1 line
2.51.0
PATCH v4 22/29 rebase: persist --trailer options across restarts
In reply to Li Chent3440 showed rebase -m loses trailers after conflicts. Each --continue spawns a fresh replay_opts without trailer_args. Serialize them into rebase-merge/trailer so new runs reload them. This keeps the user requested trailers intact when resuming.
--- sequencer.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
sequencer.c +20 -0
@@ -209,6 +209,7 @@ static GIT_PATH_FUNC(rebase_path_reschedule_failed_exec, "rebase-merge/reschedul static GIT_PATH_FUNC(rebase_path_no_reschedule_failed_exec, "rebase-merge/no-reschedule-failed-exec") static GIT_PATH_FUNC(rebase_path_drop_redundant_commits, "rebase-merge/drop_redundant_commits") static GIT_PATH_FUNC(rebase_path_keep_redundant_commits, "rebase-merge/keep_redundant_commits") +staticGIT_PATH_FUNC (rebase_path_trailer,"rebase-merge/trailer" )/* * A 'struct replay_ctx' represents the private state of the sequencer.
@@ -3244,6 +3245,17 @@ static int read_populate_opts(struct replay_opts *opts)read_strategy_opts (opts, &buf);strbuf_reset (&buf); +if (strbuf_read_file (&buf,rebase_path_trailer (),0 ) >=0 ) { +char *p = buf.buf, *nl; + +while ((nl =strchr (p,'\n' ))) { + *nl ='\0' ; +if (*p) +strvec_push (&opts->trailer_args, p); + p = nl +1 ; + } +strbuf_reset (&buf); + } if (read_oneliner(&ctx->current_fixups, rebase_path_current_fixups(),
@@ -3338,6 +3350,14 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,write_file (rebase_path_reschedule_failed_exec (),"%s" ,"" ); else write_file(rebase_path_no_reschedule_failed_exec(), "%s", ""); +if (opts->trailer_args.nr) { +struct strbuf buf =STRBUF_INIT ; + +for (size_t i =0 ; i < opts->trailer_args.nr; i++) +strbuf_addf (&buf,"%s\n" , opts->trailer_args.v[i]); +write_file (rebase_path_trailer (),"%s" , buf.buf); +strbuf_release (&buf); + }return 0 ; }
Signature · 1 line
2.51.0
PATCH v4 23/29 tests: t3440: remove redundant --keep-empty
In reply to Li ChenFrom: Li Chen <[email protected]>
--keep-empty is the default these days so
we can drop that.
--- t/t3440-rebase-trailer.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/t3440-rebase-trailer.sh +1 -1
@@ -87,7 +87,7 @@ test_expect_success 'rebase --root --trailer updates every commit' ' create_expect initial-signed "Initial empty commit" && create_expect first-signed "first" && git checkout first && - git rebase --root --keep-empty \ + git rebase --root \ --trailer "Reviewed-by: Dev <[email protected]>" && test_commit_message HEAD first-signed && test_commit_message HEAD^ initial-signed
Signature · 1 line
2.51.0
PATCH v4 24/29 tests: t3440: use helper for trailer checks
In reply to Li ChenIntroduce expect_trailer_msg() to wrap test_commit_message and dedupe the trailer via REVIEWED_BY_TRAILER. Drop create_expect and temp files. In the conflict case, assert on HEAD (rebased "third") instead of HEAD~2. Update --apply rejection and --root tests to use the helper.
--- t/t3440-rebase-trailer.sh | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
t/t3440-rebase-trailer.sh +11 -12
@@ -11,11 +11,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh . "$TEST_DIRECTORY"/lib-rebase.sh # test_commit_message, helpers -create_expect() { - cat >"$1" <<-EOF +REVIEWED_BY_TRAILER="Reviewed-by: Dev <[email protected]>" + +expect_trailer_msg() { + test_commit_message "$1" <<-EOF $2 - Reviewed-by: Dev <[email protected]> + ${3:-$REVIEWED_BY_TRAILER} EOF }
@@ -32,7 +34,7 @@ test_expect_success 'setup repo with a small history' ' test_expect_success 'apply backend is rejected with --trailer' ' head_before=$(git rev-parse HEAD) && test_expect_code 128 \ - git rebase --apply --trailer "Reviewed-by: Dev <[email protected]>" \ + git rebase --apply --trailer "$REVIEWED_BY_TRAILER" \ HEAD^ 2>err && test_grep "fatal: --trailer requires the merge backend" err && test_cmp_rev HEAD $head_before
@@ -73,23 +75,20 @@ test_expect_success 'multiple Signed-off-by trailers all preserved' ' ' test_expect_success 'rebase -m --trailer adds trailer after conflicts' ' - create_expect third-signed "third" && test_must_fail git rebase -m \ - --trailer "Reviewed-by: Dev <[email protected]>" \ + --trailer "$REVIEWED_BY_TRAILER" \ second third && git checkout --theirs file && git add file && git rebase --continue && - test_commit_message HEAD third-signed + expect_trailer_msg HEAD "third" ' test_expect_success 'rebase --root --trailer updates every commit' ' - create_expect initial-signed "Initial empty commit" && - create_expect first-signed "first" && git checkout first && git rebase --root \ - --trailer "Reviewed-by: Dev <[email protected]>" && - test_commit_message HEAD first-signed && - test_commit_message HEAD^ initial-signed + --trailer "$REVIEWED_BY_TRAILER" && + expect_trailer_msg HEAD "first" && + expect_trailer_msg HEAD^ "Initial empty commit" ' test_done
Signature · 1 line
2.51.0
PATCH v4 25/29 tests: t3440: test --trailer without values
In reply to Li ChenAdded a regression test to ensure git rebase --trailer accepts trailers without values while preserving the separator’s trailing space in the recorded message.
--- t/t3440-rebase-trailer.sh | 10 ++++++++++ 1 file changed, 10 insertions(+)
t/t3440-rebase-trailer.sh +10 -0
@@ -50,6 +50,16 @@ test_expect_success 'reject trailer with missing key before separator' ' test_grep "missing key before separator" err ' +test_expect_success 'allow trailer with missing value after separator' ' + git rebase -m --trailer "Acked-by:" HEAD~1 third && + cat >expect <<-\EOF && + third + + Acked-by: + EOF + test_commit_message HEAD expect +' + test_expect_success 'CLI trailer duplicates allowed; replace policy keeps last' ' git -c trailer.Bug.ifexists=replace -c trailer.Bug.ifmissing=add \ rebase -m --trailer "Bug: 123" --trailer "Bug: 456" HEAD~1 third &&
Signature · 1 line
2.51.0
Re: [PATCH v4 25/29] tests: t3440: test --trailer without values
Quoted 4 lines · Li Chen
Added a regression test to ensure git rebase --trailer accepts trailers without values while preserving the separator’s trailing space in the recorded message.
See “imperative-mood” in Documentation/SubmittingPatches. Something like:
Add a regression test to ensure
Quoted 17 lines
Signed-off-by Li Chen <[email protected]>--- t/t3440-rebase-trailer.sh | 10 ++++++++++ 1 file changed, 10 insertions(+)t/t3440-rebase-trailer.sh +0
-0@@ -50,6 +50,16 @@ test_expect_success 'reject trailer with missing keybefore separator' '
t/t3440-rebase-trailer.sh +1
-0test_grep "missing key before separator" err ' +test_expect_success 'allow trailer with missing value after separator''
t/t3440-rebase-trailer.sh test_expect_success 'reject trailer with missing key before separator' ' · line 58
Quoted 5 lines
t/t3440-rebase-trailer.sh +5
-0+ git rebase -m --trailer "Acked-by:" HEAD~1 third && + cat >expect <<-\EOF && + third + + Acked-by:
This adds a trailing space to the source which will make ci/check-whitespace.sh fail. I think you are supposed to do something similar to what is done in t/t4124-apply-ws-rule.sh. Namely to use some placeholder character like _:
Acked-by:_
Together with:
sed -e "s/_/ /g"
I could also imagine that a variable like ${SP} might have worked together with -EOF similar to single quote:
t/test-lib.sh:SQ=\'
But t/test-lib.sh does not seem to have that. (Although it does have LF (line feed)).
Quoted 2 lines
t/t3440-rebase-trailer.sh +1
-0+ EOF
PATCH v4 26/29 tests: t3440: convert ex.com to example.com
In reply to Li ChenFrom: Li Chen <[email protected]>
Lets use example.com here rather than some
random domain that might actually exist.
--- t/t3440-rebase-trailer.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
t/t3440-rebase-trailer.sh +4 -4
@@ -73,13 +73,13 @@ test_expect_success 'CLI trailer duplicates allowed; replace policy keeps last' test_expect_success 'multiple Signed-off-by trailers all preserved' ' git rebase -m \ - --trailer "Signed-off-by: Dev A <[email protected]>" \ - --trailer "Signed-off-by: Dev B <[email protected]>" HEAD~1 third && + --trailer "Signed-off-by: Dev A <[email protected]>" \ + --trailer "Signed-off-by: Dev B <[email protected]>" HEAD~1 third && cat >expect <<-\EOF && third - Signed-off-by: Dev A <[email protected]> - Signed-off-by: Dev B <[email protected]> + Signed-off-by: Dev A <[email protected]> + Signed-off-by: Dev B <[email protected]> EOF test_commit_message HEAD expect '
Signature · 1 line
2.51.0
PATCH v4 27/29 tests: t3440: ensure trailers persist after rebase continue
In reply to Li ChenRebuilt the conflict test branch, added a fourth commit, and asserted that both the conflicted and subsequent commits receive the --trailer data in t/t3440-rebase-trailer.sh.
--- t/t3440-rebase-trailer.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
t/t3440-rebase-trailer.sh +6 -3
@@ -85,13 +85,16 @@ test_expect_success 'multiple Signed-off-by trailers all preserved' ' ' test_expect_success 'rebase -m --trailer adds trailer after conflicts' ' + git checkout -B conflict-branch third && + test_commit fourth file && test_must_fail git rebase -m \ - --trailer "$REVIEWED_BY_TRAILER" \ - second third && + --trailer "$REVIEWED_BY_TRAILER" \ + second && git checkout --theirs file && git add file && git rebase --continue && - expect_trailer_msg HEAD "third" + expect_trailer_msg HEAD "fourth" && + expect_trailer_msg HEAD^ "third" ' test_expect_success 'rebase --root --trailer updates every commit' '
Signature · 1 line
2.51.0
PATCH v4 28/29 tests: t3440: exercise trailer config mapping
In reply to Li ChenUpdated the rebase --root --trailer test to exercise trailer.review.key configuration and the --trailer= CLI form that uses an equals separator, ensuring we still add the expected Reviewed-by trailer.
--- t/t3440-rebase-trailer.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
t/t3440-rebase-trailer.sh +2 -2
@@ -99,8 +99,8 @@ test_expect_success 'rebase -m --trailer adds trailer after conflicts' ' test_expect_success 'rebase --root --trailer updates every commit' ' git checkout first && - git rebase --root \ - --trailer "$REVIEWED_BY_TRAILER" && + git -c trailer.review.key=Reviewed-by rebase --root \ + --trailer=review="Dev <[email protected]>" && expect_trailer_msg HEAD "first" && expect_trailer_msg HEAD^ "Initial empty commit" '
Signature · 1 line
2.51.0
PATCH v4 29/29 sequencer: honor --trailer with fixup -C
In reply to Li ChenAdd 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.
--- sequencer.c | 4 ++++ t/t3440-rebase-trailer.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+)
sequencer.c +4 -0
@@ -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()) ||
t/t3440-rebase-trailer.sh +27 -0
@@ -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 \
Signature · 1 line
2.51.0
Hi Phillip & Junio,
I apologize for the delay in sending out v4. I will respond to and update the code in the following patchset (if needed)
as soon as possible.
My apologies!
---- On Tue, 14 Oct 2025 20:24:13 +0800 Li Chen <[email protected]> wrote ---
Quoted 70 lines
From: Li Chen <[email protected]>
This patch series teaches git rebase a new
--trailer <text> option and, as a prerequisite, moves all trailer handling out of the external interpret-trailers helper and into the builtin code path, as suggested by Phillip Wood.Patch 0 switches
trailer.cto an in-memory implementation (amend_strbuf_with_trailers()). It removes every fork/exec.Patch 1~8 fix all reviewer comments from v3 for patch 0.
Patch 9 builds on that helper to implement
git rebase --trailer. When the option is given we:
force the merge backend (apply/am backend lacks a message filter), automatically enable --force-rebase so that fast-forwarded commits are rewritten, and append the requested trailer(s) to every rewritten commit.
State is stored in $state_dir/trailer so an interrupted rebase can resume safely. A dedicated test-suite (t3440) exercises plain, conflict, --root, invalid-input scenarios and etc.The rest patches address all reviewer comments from v3 for patch 9.
All t/*.sh testcases have run successfully.
v4: fix all reviewer comments in v3. [2]
v3: merges the remaining trailer paths into one in-process helper, dropping the
duplicate code, as pointed by Junio and Phillip [1]
v2: fix issues pointed by Phillip
RFC link: https://lore.kernel.org/git/[email protected]/Comments welcome!
[1]: https://lore.kernel.org/git/[email protected]/
[2]: https://lore.kernel.org/git/[email protected]/Li Chen (29):
trailer: append trailers in-process and drop the fork to
interpret-trailers
trailer: restoreinterpret_trailershelper
trailer: drop --trailer prefix handling in amend helper
trailer: moveconfig_headandarg_headto if storage
trailer: use bool forhad_trailer_before
interpret-trailers: buffer stdout output
trailer: mirror interpret-trailers output flow
trailer: handle trailer append failures gently
rebase: support --trailer
rebase: inline trailer state paths
rebase: reuse buffer for trailer args
rebase: drop redundantstrbuf_releasecall
rebase: skip stripping of --trailer option prefix
rebase: die on invalid trailer args
rebase: validate trailers with configured separators
sequencer: add trailers to message before writing file
tests: t3440: create expect files at point of use
tests: t3440: check apply backend error includes option
tests: t3440: usetest_commit_messagefor trailer checks
tests: t3440: drop redundant resets and pass branch to rebase where
needed
tests: t3440: assert trailer on HEAD after conflict rebase
rebase: persist --trailer options across restarts
tests: t3440: remove redundant --keep-empty
tests: t3440: use helper for trailer checks
tests: t3440: test --trailer without values
tests: t3440: convert ex.com to example.com
tests: t3440: ensure trailers persist after rebase continue
tests: t3440: exercise trailer config mapping
sequencer: honor --trailer with fixup -C
Quoted 20 lines
Documentation/git-rebase.adoc | 7 ++ builtin/commit.c | 2 +- builtin/interpret-trailers.c | 94 +++++------------------- builtin/rebase.c | 50 +++++++++++++ builtin/tag.c | 3 +- sequencer.c | 34 +++++++++ sequencer.h | 4 +- t/meson.build | 1 + t/t3440-rebase-trailer.sh | 134 ++++++++++++++++++++++++++++++++++ trailer.c | 130 ++++++++++++++++++++++++++++++--- trailer.h | 23 +++++- wrapper.c | 16 ++++ wrapper.h | 6 ++ 13 files changed, 411 insertions(+), 93 deletions(-) create mode 100755 t/t3440-rebase-trailer.shSignature · 1 line
2.51.0
Regards,
Li