Re: [PATCH 1/1] commit: make the sign-off trailer configurable
- From
Derrick Stolee <stolee@gmail.com>
- Date
- Jan 6, 2020, 13:38 UTC
- Message-ID
- <71a718a7-2be7-391c-dc8f-0626a0a21aac@gmail.com>
- In-Reply-To
- <20200105174127.9278-2-hji@dyntopia.com>
On 1/5/2020 12:41 PM, Hans Jerry Illikainen wrote:
Show 9 quoted lines
> The commit builtin did not previously have a configuration option to > enable the 'Signed-off-by' trailer by default. > > For some use-cases (namely, when the user doesn't always have the right > to contribute patches to a project) it makes sense to make it a > conscientious decision to add the signoff trailer. However, others' > might always have the right to ship patches -- in which case it makes > sense to have an option to add the trailer by default for projects that > require it.
My initial thought was that the sign-off was supposed to be a purposeful decision, but then I also realized that I never do anything in the Git codebase that I _can't_ put online under the GPL. (It may not make it upstream, but it will always be put online somewhere.)
> This patch introduces a commit.signOff configuration option that > determine whether the trailer should be added for commits. It can be > overridden with the --(no-)signoff command-line option.
With that in mind, I think this is a valuable feature.
> Signed-off-by: Hans Jerry Illikainen <hji@dyntopia.com>
Did you generate this with your config option? ;)
Show 8 quoted lines
> +commit.signOff:: > + A boolean to specify whether commits should enable the > + `-s/--signoff` option by default. *Note:* Adding the > + Signed-off-by: line to a commit message should be a conscious > + act and means that you certify you have the rights to submit the > + work under the same open source license. Please see the > + 'SubmittingPatches' document for further discussion. > +
I wonder about the language of "should be a conscious act" here. It's as if you are trying to convince someone to not use this feature. Perhaps switch it to "is a deliberate act" and add something such as "Enable this value only in repos where you are the only user and always have these rights."
The multi-user scenario may be worth clarifying explicitly here. If there is any chance that another user will join the machine and use that same repo, then they would have a different user.name and user.email in their global config (probably) but this as a local setting would provide their sign-off.
Show 12 quoted lines
> diff --git a/builtin/commit.c b/builtin/commit.c
> index c70ad01cc9..497e29c58c 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -1474,6 +1474,10 @@ static int git_commit_config(const char *k, const char *v, void *cb)
> sign_commit = git_config_bool(k, v) ? "" : NULL;
> return 0;
> }
> + if (!strcmp(k, "commit.signoff")) {
> + signoff = git_config_bool(k, v);
> + return 0;
> + }Since we are directly modifying the same global used by the --[no-]signoff option, I verified that the config options are checked before the arguments are parsed. Thus, --no-signoff will override commit.signOff=true...
Show 23 quoted lines
> +test_expect_success 'commit.signOff=true' ' > + test_config commit.signOff true && > + echo 1 >>positive && > + git add positive && > + git commit -m "thank you" && > + git cat-file commit HEAD >commit.msg && > + sed -ne "s/Signed-off-by: //p" commit.msg >actual && > + git var GIT_COMMITTER_IDENT >ident && > + sed -e "s/>.*/>/" ident >expected && > + test_cmp expected actual > +' > + > +test_expect_success 'commit.signOff=true and --no-signoff' ' > + test_config commit.signOff true && > + echo 2 >>positive && > + git add positive && > + git commit --no-signoff -m "thank you" && > + git cat-file commit HEAD >commit.msg && > + sed -ne "s/Signed-off-by: //p" commit.msg >actual && > + git var GIT_COMMITTER_IDENT >ident && > + sed -e "s/>.*/>/" ident >expected && > + ! test_cmp expected actual > +'
...which you test here, too. Excellent.
Show 5 quoted lines
> +test_expect_success 'commit.signOff=false and --signoff' ' > + test_config commit.signOff false && > + echo 1 >>positive && > + git add positive && > + git commit --signoff -m "thank you" &&
Perhaps it is worth adding an explicit "-c commit.signOff=false" here?
Show 7 quoted lines
> + git cat-file commit HEAD >commit.msg && > + sed -ne "s/Signed-off-by: //p" commit.msg >actual && > + git var GIT_COMMITTER_IDENT >ident && > + sed -e "s/>.*/>/" ident >expected && > + test_cmp expected actual > +' > +
I wonder if the boilerplate for these tests could be simplified or shared across the tests?
For example: could we not just use test_i18ngrep to see if commit.msg contains (or does not contain) the string "Signed-off-by"?
I believe this patch delivers the stated feature well. Hopefully others can add commentary on its usefulness or possible issues in using it.
Thanks, -Stolee