am: add am.signoff add config variable
PATCH v2 1/1 am: add am.signoff add config variable
git-am has options to enable --message-id and --3way by default, but no option to enable --signoff by default. Add a "am.signoff" config option.
---
Changes v1 -> v2:
* Added documentation to Documentation/git-am.txt and Documentation/config.txt
* Added test cases to t4150-am.sh
--- Documentation/config.txt | 5 +++++ Documentation/git-am.txt | 6 ++++-- builtin/am.c | 2 ++ t/t4150-am.sh | 24 ++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-)
Documentation/config.txt +5 -0
@@ -822,6 +822,11 @@ am.keepcr:: by giving `--no-keep-cr` from the command line. See linkgit:git-am[1], linkgit:git-mailsplit[1]. +am.signoff:: + If true, git-am will add a `Signed-off-by:` line to the commit + message. See the signoff option in linkgit:git-commit[1] for + more information. + am.threeWay:: By default, `git am` will fail if the patch does not apply cleanly. When set to true, this setting tells `git am` to fall back on 3-way merge if
Documentation/git-am.txt +4 -2
@@ -9,7 +9,7 @@ git-am - Apply a series of patches from a mailbox SYNOPSIS -------- [verse] -'git am' [--signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8] +'git am' [--[no-]signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8] [--[no-]3way] [--interactive] [--committer-date-is-author-date] [--ignore-date] [--ignore-space-change | --ignore-whitespace] [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
@@ -32,10 +32,12 @@ OPTIONS If you supply directories, they will be treated as Maildirs. -s:: ---signoff:: +--[no]-signoff:: Add a `Signed-off-by:` line to the commit message, using the committer identity of yourself. See the signoff option in linkgit:git-commit[1] for more information. + The `am.signoff` configuration variable can be used to specify the + default behaviour. `--no-signoff` is useful to override `am.signoff`. -k:: --keep::
builtin/am.c +2 -0
@@ -154,6 +154,8 @@ static void am_state_init(struct am_state *state, const char *dir)git_config_get_bool ("am.messageid" , &state->message_id); +git_config_get_bool ("am.signoff" , &state->signoff); + state->scissors =SCISSORS_UNSET ;argv_array_init (&state->git_apply_opts);
t/t4150-am.sh +24 -0
@@ -479,6 +479,30 @@ test_expect_success 'am --signoff adds Signed-off-by: line' ' test_cmp expected actual ' +test_expect_success '--no-signoff overrides am.signoff' ' + rm -fr .git/rebase-apply && + git reset --hard first && + test_config am.signoff true && + git am --no-signoff <patch2 && + printf "%s\n" "$signoff" >expected && + git cat-file commit HEAD^ | grep "Signed-off-by:" >actual && + test $(git cat-file commit HEAD | grep -c "Signed-off-by:") -eq 0 +' + +test_expect_success 'am.signoff adds Signed-off-by: line' ' + rm -fr .git/rebase-apply && + git reset --hard first && + test_config am.signoff true && + git am <patch2 && + printf "%s\n" "$signoff" >expected && + echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >>expected && + git cat-file commit HEAD^ | grep "Signed-off-by:" >actual && + test_cmp expected actual && + echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected && + git cat-file commit HEAD | grep "Signed-off-by:" >actual && + test_cmp expected actual +' + test_expect_success 'am stays in branch' ' echo refs/heads/master2 >expected && git symbolic-ref HEAD >actual &&
Signature · 1 line
2.11.0.259.g40922b1
Quoted 10 lines · Eduardo Habkost
git-am has options to enable --message-id and --3way by default, but no option to enable --signoff by default. Add a "am.signoff" config option.
Signed-off-by Eduardo Habkost <[email protected]>---
Changes v1 -> v2:
* Added documentation toDocumentation/git-am.txtandDocumentation/config.txt
* Added test cases tot4150-am.sh
Thanks!
Documentation and code looks good to me, for the test a small nit below.
t/t4150-am.sh test_expect_success 'am --signoff adds Signed-off-by: line' ' · line 487
Quoted 6 lines
t/t4150-am.sh +6
-0+test_expect_success '--no-signoff overrides am.signoff' ' + rm -fr .git/rebase-apply && + git reset --hard first && + test_config am.signoff true && + git am --no-signoff <patch2 && + printf "%s\n" "$signoff" >expected &&
"expected" is never read in this test, so we can omit this line?
Quoted 1 line
+ git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
So we check if the previous commit is not tampered with,
Quoted 1 line
+ test $(git cat-file commit HEAD | grep -c "Signed-off-by:") -eq 0
and then we check if the top most commit has zero occurrences for lines grepped for sign off. That certainly works, but took me a while to understand (TIL about -c in grep :).
Another way that to write this check, that Git regulars may be more used to is:
git cat-file commit HEAD | grep "Signed-off-by:" >actual test_must_be_empty actual
I would have suggested to grep for $signoff instead of "Signed-off-by:", but it turns out being fuzzy here is better and would also catch e.g. a broken sign off.
t/t4150-am.sh test_expect_success 'am --signoff adds Signed-off-by: line' ' · line 504
Quoted 13 lines
t/t4150-am.sh +13
-0+test_expect_success 'am.signoff adds Signed-off-by: line' ' + rm -fr .git/rebase-apply && + git reset --hard first && + test_config am.signoff true && + git am <patch2 && + printf "%s\n" "$signoff" >expected && + echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >>expected && + git cat-file commit HEAD^ | grep "Signed-off-by:" >actual && + test_cmp expected actual && + echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected && + git cat-file commit HEAD | grep "Signed-off-by:" >actual && + test_cmp expected actual +'
This test looks good to me,
Thanks,
Stefan
Quoted 15 lines · Stefan Beller
Quoted 10 lines · Eduardo Habkost
git-am has options to enable --message-id and --3way by default, but no option to enable --signoff by default. Add a "am.signoff" config option.
Signed-off-by Eduardo Habkost <[email protected]>---
Changes v1 -> v2:
* Added documentation toDocumentation/git-am.txtandDocumentation/config.txt
* Added test cases tot4150-am.shThanks!
Documentation and code looks good to me, for the test a small nit below.
Quoted 9 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+test_expect_success '--no-signoff overrides am.signoff' ' + rm -fr .git/rebase-apply && + git reset --hard first && + test_config am.signoff true && + git am --no-signoff <patch2 && + printf "%s\n" "$signoff" >expected &&"expected" is never read in this test, so we can omit this line?
Oops, I have deleted a "test_cmp expected actual" line by mistake.
Quoted 3 lines
Quoted 1 line
+ git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
So we check if the previous commit is not tampered with,
We do, but only if we have a "test_cmp expected actual" line here.
Fixed by:
t/t4150-am.sh +1 -0
@@ -486,6 +486,7 @@ test_expect_success '--no-signoff overrides am.signoff' ' git am --no-signoff <patch2 && printf "%s\n" "$signoff" >expected && git cat-file commit HEAD^ | grep "Signed-off-by:" >actual && + test_cmp expected actual && test $(git cat-file commit HEAD | grep -c "Signed-off-by:") -eq 0 '
Quoted 11 lines
Quoted 2 lines
+ test $(git cat-file commit HEAD | grep -c "Signed-off-by:") -eq 0
and then we check if the top most commit has zero occurrences for lines grepped for sign off. That certainly works, but took me a while to understand (TIL about -c in grep :).
Another way that to write this check, that Git regulars may be more used to is:
git cat-file commit HEAD | grep "Signed-off-by:" >actual
test_must_be_emptyactual
test_must_be_empty is what I was looking for. But if I do this:
test_expect_success '--no-signoff overrides am.signoff' '
rm -fr .git/rebase-apply && git reset --hard first && test_config am.signoff true && git am --no-signoff <patch2 && printf "%s\n" "$signoff" >expected && git cat-file commit HEAD^ | grep "Signed-off-by:" >actual && test_cmp expected actual && git cat-file commit HEAD | grep "Signed-off-by:" >actual && test_must_be_empty actual
'
The test fails because the second "grep" command returns a non-zero exit code. Any suggestions to avoid that problem in a more idiomatic way?
Quoted 4 lines
I would have suggested to grep for $signoff instead of "Signed-off-by:", but it turns out being fuzzy here is better and would also catch e.g. a broken sign off.
Yes, I want to ensure no extra Signed-off-by line is present except for $signof (that is already present in the original e-mail).
Quoted 19 lines
Quoted 4 lines
(quoted diff) +3
-0+test_expect_success 'am.signoff adds Signed-off-by: line' ' + rm -fr .git/rebase-apply && + git reset --hard first &&Review
Quoted 10 lines
(quoted diff) +10
-0+ test_config am.signoff true && + git am <patch2 && + printf "%s\n" "$signoff" >expected && + echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >>expected && + git cat-file commit HEAD^ | grep "Signed-off-by:" >actual && + test_cmp expected actual && + echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected && + git cat-file commit HEAD | grep "Signed-off-by:" >actual && + test_cmp expected actual +'This test looks good to me,
Thanks,
Stefan
Signature · 1 line
Eduardo
Quoted 2 lines · Eduardo Habkost
Quoted 1 line · Stefan Beller
On Wed, Dec 28, 2016 at 10:35 AM, Eduardo Habkost <[email protected]> wrote:
[...]
Quoted 23 lines
Quoted 10 lines
Quoted 1 line
+ test $(git cat-file commit HEAD | grep -c "Signed-off-by:") -eq 0
and then we check if the top most commit has zero occurrences for lines grepped for sign off. That certainly works, but took me a while to understand (TIL about -c in grep :).
Another way that to write this check, that Git regulars may be more used to is:
git cat-file commit HEAD | grep "Signed-off-by:" >actual
test_must_be_emptyactual
test_must_be_emptyis what I was looking for. But if I do this:
test_expect_success'--no-signoff overrides am.signoff' 'rm -fr .git/rebase-apply && git reset --hard first && test_config am.signoff true && git am --no-signoff <patch2 && printf "%s\n" "$signoff" >expected && git cat-file commit HEAD^ | grep "Signed-off-by:" >actual && test_cmp expected actual && git cat-file commit HEAD | grep "Signed-off-by:" >actual && test_must_be_empty actual
Quoted 5 lines
'
The test fails because the second "grep" command returns a non-zero exit code. Any suggestions to avoid that problem in a more idiomatic way?
I just found out that "test_must_fail grep ..." is a common idiom, so what about:
test_expect_success '--no-signoff overrides am.signoff' '
rm -fr .git/rebase-apply && git reset --hard first && test_config am.signoff true && git am --no-signoff <patch2 && printf "%s\n" "$signoff" >expected && git cat-file commit HEAD^ | grep "Signed-off-by:" >actual && test_cmp expected actual && git cat-file commit HEAD | test_must_fail grep -q "Signed-off-by:"
'
Signature · 1 line
Eduardo
Quoted 29 lines · Eduardo Habkost
Quoted 2 lines · Eduardo Habkost
Quoted 1 line · Stefan Beller
On Wed, Dec 28, 2016 at 10:35 AM, Eduardo Habkost <[email protected]> wrote:
[...]
Quoted 25 lines
Quoted 10 lines
Quoted 1 line
+ test $(git cat-file commit HEAD | grep -c "Signed-off-by:") -eq 0
and then we check if the top most commit has zero occurrences for lines grepped for sign off. That certainly works, but took me a while to understand (TIL about -c in grep :).
Another way that to write this check, that Git regulars may be more used to is:
git cat-file commit HEAD | grep "Signed-off-by:" >actual
test_must_be_emptyactual
test_must_be_emptyis what I was looking for. But if I do this:
test_expect_success'--no-signoff overrides am.signoff' 'rm -fr .git/rebase-apply && git reset --hard first && test_config am.signoff true && git am --no-signoff <patch2 && printf "%s\n" "$signoff" >expected && git cat-file commit HEAD^ | grep "Signed-off-by:" >actual && test_cmp expected actual && git cat-file commit HEAD | grep "Signed-off-by:" >actual && test_must_be_empty actual'
Quoted 6 lines
Quoted 3 lines
The test fails because the second "grep" command returns a non-zero exit code. Any suggestions to avoid that problem in a more idiomatic way?
I just found out that "
test_must_failgrep ..." is a common idiom, so what about:
Uh, no please.
test_must_fail is supposed to be used for commands to be tested, i.e. git commands as this is the git test suite. :) test_must_fail checks, e.g. that the failing command "properly" fails instead of bye-bye-segfault. And grep would never do this. (In this world we assume everything to be perfect except git itself)
For grep just use !
git cat-file commit HEAD >actual &&
! grep "Signed-off-by:" actual
$ git grep "test_must_fail grep" returns 20 occurrences, so in case you're that would be a good cleanup patch (if you're interested in such things).
Thanks,
Stefan
Hey Eduardo,
Quoted 12 lines · Eduardo Habkost
Quoted 12 lines
test_expect_success'--no-signoff overrides am.signoff' 'rm -fr .git/rebase-apply && git reset --hard first && test_config am.signoff true && git am --no-signoff <patch2 && printf "%s\n" "$signoff" >expected && git cat-file commit HEAD^ | grep "Signed-off-by:" >actual && test_cmp expected actual && git cat-file commit HEAD | grep "Signed-off-by:" >actual && test_must_be_empty actual'
Quoted 6 lines
Quoted 3 lines
The test fails because the second "grep" command returns a non-zero exit code. Any suggestions to avoid that problem in a more idiomatic way?
I just found out that "
test_must_failgrep ..." is a common idiom, so what about:
Is there any particular reason to use "grep" instead of "test_cmp"? To check for non-zero error code, you can always use "! test_cmp".
Regards,
Pranit Bauva
Quoted 19 lines · Pranit Bauva
Hey Eduardo,
Quoted 16 lines · Eduardo Habkost
Quoted 15 lines
test_expect_success'--no-signoff overrides am.signoff' 'rm -fr .git/rebase-apply && git reset --hard first && test_config am.signoff true && git am --no-signoff <patch2 && printf "%s\n" "$signoff" >expected && git cat-file commit HEAD^ | grep "Signed-off-by:" >actual && test_cmp expected actual && git cat-file commit HEAD | grep "Signed-off-by:" >actual && test_must_be_empty actual'
The test fails because the second "grep" command returns a non-zero exit code. Any suggestions to avoid that problem in a more idiomatic way?
Quoted 5 lines
Quoted 2 lines
I just found out that "
test_must_failgrep ..." is a common idiom, so what about:Is there any particular reason to use "grep" instead of "
test_cmp"? To check for non-zero error code, you can always use "!test_cmp".
The test code is checking only the "Signed-off-by" lines, not the whole commit message. "test_cmp" would require recovering the entire contents of the original commit message, which would add complexity to the test code.
Signature · 1 line
Eduardo
Quoted 14 lines · Eduardo Habkost
Documentation/git-am.txt +1
-1@@ -9,7 +9,7 @@ git-am - Apply a series of patches from a mailbox SYNOPSIS -------- [verse] -'git am' [--signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8] +'git am' [--[no-]signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8] [--[no-]3way] [--interactive] [--committer-date-is-author-date] [--ignore-date] [--ignore-space-change | --ignore-whitespace] [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
Documentation/git-am.txt OPTIONS · line 35
Quoted 5 lines
Documentation/git-am.txt +1
-1@@ -32,10 +32,12 @@ OPTIONS If you supply directories, they will be treated as Maildirs. -s:: ---signoff:: +--[no]-signoff::
That should be --[no-]signoff, as in the synopsis.
Andreas.
Signature · 3 lines
Andreas Schwab, [email protected] GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Quoted 18 lines · Andreas Schwab
Quoted 16 lines · Eduardo Habkost
Documentation/git-am.txt +1
-1@@ -9,7 +9,7 @@ git-am - Apply a series of patches from a mailbox SYNOPSIS -------- [verse] -'git am' [--signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8] +'git am' [--[no-]signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8] [--[no-]3way] [--interactive] [--committer-date-is-author-date] [--ignore-date] [--ignore-space-change | --ignore-whitespace] [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]@@ -32,10 +32,12 @@ OPTIONS If you supply directories, they will be treated as Maildirs.
Quoted 5 lines
Documentation/git-am.txt OPTIONS · line 35
Quoted 3 lines
Documentation/git-am.txt +1
-1-s:: ---signoff:: +--[no]-signoff::That should be --[no-]signoff, as in the synopsis.
Thanks for catching it. I will fix it in v3.
Signature · 1 line
Eduardo