From: Christian Couder Date: Mon, 22 Mar 2021 21:34:21 GMT Subject: Re: [PATCH v13] [GSOC] commit: add --trailer option Message-ID: In-Reply-To: On Mon, Mar 22, 2021 at 11:23 AM ZheNing Hu wrote: > > Christian Couder 于2021年3月22日周一 下午3:43写道: > > Nice that you have added such a test! > > Thanks. > > But at the same time I have two little doubt. > > 1. > If we have your config: > > $ git config trailer.sign.key "Signed-off-by: " > $ git config trailer.sign.ifexists replace > $ git config trailer.sign.command "git log --author='\$ARG' -1 > --format='format:%aN <%aE>'" > > Then I touch a test.c and use: > > $ git interpret-trailers --in-place test.c > > without `--trailer`, See what is happen: > > It seem like your local repo last commit "name " pair > have been record in `test.c`. > > Could this be considered a bug? First it seems strange to use `git interpret-trailers` on a "test.c" file. It's supposed to be used on commit messages. Then, as the doc says, every command specified by any "trailer..command" config option is run at least once when `git interpret-trailers` is run. This is because users might want to automatically add some trailers all the time. If you want nothing to happen when $ARG isn't set, you can change the config option to something like: $ git config trailer.sign.command "NAME='\$ARG'; test -n \"\$NAME\" && git log --author=\"\$NAME\" -1 --format='format:%aN <%aE>' || true" (This is because it looks like $ARG is replaced only once with the actual value, which is perhaps a bug. Otherwise something like the following might work: git config trailer.sign.command "test -n '\$ARG' && git log --author='\$ARG' -1 --format='format:%aN <%aE>' || true") Then you can run `git interpret-trailers` with the --trim-empty option like this: ------ $ git interpret-trailers --trim-empty --trailer sign=Linus< ------ or like: ------ $ git interpret-trailers --trim-empty< EOF ------