Re: [PATCH v13] [GSOC] commit: add --trailer option
- From
Christian Couder <christian.couder@gmail.com>
- Date
- Mar 22, 2021, 21:34 UTC
- Message-ID
- <CAP8UFD3fYTc8=y+kru-mN5KmTsnqc6X8mf14VtyWf1Nj9CJ1EQ@mail.gmail.com>
- In-Reply-To
- <CAOLTT8Ty5kabU6ivX946=FDWJ4SEXBzPinq2aG5t7Rp9jCCEPA@mail.gmail.com>
On Mon, Mar 22, 2021 at 11:23 AM ZheNing Hu <adlternative@gmail.com> wrote:
> > Christian Couder <christian.couder@gmail.com> 于2021年3月22日周一 下午3:43写道:
Show 24 quoted lines
> > 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 <email>" 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.<token>.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<<EOF EOF
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> ------
or like:
------ $ git interpret-trailers --trim-empty<<EOF
> EOF
------