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

[PATCH v2] commit: add commit.signoff config option

From
CFCaio Marcelo de Oliveira Filho <cmarcelo@gmail.com>
Date
Jun 25, 2015, 14:50 UTC
Message-ID
<1435243807-32112-1-git-send-email-cmarcelo@gmail.com>

In projects that use Signed-off-by, it's convenient to include that line in the commit message by default. The commit.signoff config option allows to add that line in all commits automatically.

Document that this config option can be overriden by using --no-signoff.

Signed-off-by: Caio Marcelo de Oliveira Filho <cmarcelo@gmail.com>
---
Differences from v1:
* Use test_config helper in the test
* Add bash completion for commit and config
 Documentation/config.txt               |  6 ++++++
 Documentation/git-commit.txt           |  5 +++++
 builtin/commit.c                       |  4 ++++
 contrib/completion/git-completion.bash |  4 +++-
 t/t7500-commit.sh                      | 20 ++++++++++++++++++++
 5 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 3e37b93..e019f62 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1089,6 +1089,12 @@ commit.gpgSign::
 	convenient to use an agent to avoid typing your GPG passphrase
 	several times.
 
+commit.signoff::
+
+	A boolean to enable/disable whether Signed-off-by line by the
+	committer should be added to all commits at the end of the
+	commit log messages.  Defaults to false.
+
 commit.status::
 	A boolean to enable/disable inclusion of status information in the
 	commit message template when using an editor to prepare the commit
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 904dafa..7546c7a 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -156,6 +156,11 @@ OPTIONS
 	Add Signed-off-by line by the committer at the end of the commit
 	log message.
 
+--no-signoff::
+	Countermand `commit.signoff` configuration, preventing a
+	Signed-off-by line to be added at the end of the commit log
+	message.
+
 -n::
 --no-verify::
 	This option bypasses the pre-commit and commit-msg hooks.
diff --git a/builtin/commit.c b/builtin/commit.c
index 254477f..5cfbe57 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1505,6 +1505,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;
+	}
 
 	status = git_gpg_config(k, v, NULL);
 	if (status)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index c97c648..7a79a89 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1123,7 +1123,8 @@ _git_commit ()
 		;;
 	--*)
 		__gitcomp "
-			--all --author= --signoff --verify --no-verify
+			--all --author=
+			--signoff --no-signoff --verify --no-verify
 			--edit --no-edit
 			--amend --include --only --interactive
 			--dry-run --reuse-message= --reedit-message=
@@ -2009,6 +2010,7 @@ _git_config ()
 		color.status.untracked
 		color.status.updated
 		color.ui
+		commit.signoff
 		commit.status
 		commit.template
 		core.abbrev
diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh
index 116885a..949272d 100755
--- a/t/t7500-commit.sh
+++ b/t/t7500-commit.sh
@@ -179,6 +179,26 @@ test_expect_success '--signoff' '
 	test_cmp expect output
 '
 
+test_expect_success 'commit.signoff config option' '
+	test_config commit.signoff true &&
+	echo "yet another content *narf*" >> foo &&
+	echo "zort" | git commit -F - foo &&
+	git cat-file commit HEAD | sed "1,/^\$/d" > output &&
+	test_cmp expect output
+'
+
+cat > expect <<EOF
+no signed off by here
+EOF
+
+test_expect_success '--no-signoff' '
+	test_config commit.signoff true &&
+	echo "yet another content *narf*" >> foo &&
+	echo "no signed off by here" | git commit --no-signoff -F - foo &&
+	git cat-file commit HEAD | sed "1,/^\$/d" > output &&
+	test_cmp expect output
+'
+
 test_expect_success 'commit message from file (1)' '
 	mkdir subdir &&
 	echo "Log in top directory" >log &&
-- 
2.4.4.489.g5bc41de
Next: Junio C Hamano
Message 1 of 7 in “commit: add commit.signoff config option”
  1. commit: add commit.signoff config optionCaio Marcelo de Oliveira Filho, Jun 25, 2015
  2. Junio C HamanoJun 25, 2015
  3. Johannes LöthbergJun 25, 2015
  4. Caio Marcelo de Oliveira FilhoJun 25, 2015
  5. Junio C HamanoJun 25, 2015
  6. Matthieu MoyJun 25, 2015
  7. Torsten BögershausenJun 25, 2015

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.