git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] am: add am.signoff add config variable

From
EHEduardo Habkost <ehabkost@redhat.com>
Date
Dec 28, 2016, 18:35 UTC
Message-ID
<20161228183501.15068-1-ehabkost@redhat.com>

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 <ehabkost@redhat.com>
---
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(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 30cb94610..6b2990203 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -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
diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt
index 12879e402..f22f10d40 100644
--- a/Documentation/git-am.txt
+++ b/Documentation/git-am.txt
@@ -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::
diff --git a/builtin/am.c b/builtin/am.c
index 31fb60578..d2e02334f 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -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);
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index 89a5bacac..41b5481c9 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -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 &&
-- 
2.11.0.259.g40922b1
Next: Stefan Beller
Message 1 of 9 in “am: add am.signoff add config variable”
  1. am: add am.signoff add config variableEduardo Habkost, Dec 28, 2016
  2. Stefan BellerDec 28, 2016
  3. Eduardo HabkostDec 28, 2016
  4. Eduardo HabkostDec 28, 2016
  5. Stefan BellerDec 28, 2016
  6. Pranit BauvaDec 29, 2016
  7. Eduardo HabkostDec 29, 2016
  8. Andreas SchwabDec 28, 2016
  9. Eduardo HabkostDec 28, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.