git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] commit: add commit.signoff config option
@ 2015-06-25  7:30 cmarcelo
  2015-06-25  8:21 ` Alexander Kuleshov
  0 siblings, 1 reply; 7+ messages in thread
From: cmarcelo @ 2015-06-25  7:30 UTC (permalink / raw)
  To: git; +Cc: Caio Marcelo de Oliveira Filho

From: Caio Marcelo de Oliveira Filho <cmarcelo@gmail.com>

In projects that use Signed-off-by, it's convenient to include that line
in the commit 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>
---
 Documentation/config.txt     |  6 ++++++
 Documentation/git-commit.txt |  5 +++++
 builtin/commit.c             |  4 ++++
 t/t7500-commit.sh            | 22 ++++++++++++++++++++++
 4 files changed, 37 insertions(+)

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/t/t7500-commit.sh b/t/t7500-commit.sh
index 116885a..fcb39b4 100755
--- a/t/t7500-commit.sh
+++ b/t/t7500-commit.sh
@@ -179,6 +179,28 @@ test_expect_success '--signoff' '
 	test_cmp expect output
 '
 
+test_expect_success 'commit.signoff config option' '
+	git 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 &&
+	git config --unset commit.signoff &&
+	test_cmp expect output
+'
+
+cat > expect <<EOF
+no signed off by here
+EOF
+
+test_expect_success '--no-signoff' '
+	git 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 &&
+	git config --unset commit.signoff &&
+	test_cmp expect output
+'
+
 test_expect_success 'commit message from file (1)' '
 	mkdir subdir &&
 	echo "Log in top directory" >log &&
-- 
2.4.4.489.gc2a2b54.dirty

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH] commit: add commit.signoff config option
@ 2015-06-25  7:32 Caio Marcelo de Oliveira Filho
  2015-06-25  8:43 ` Christian Couder
  0 siblings, 1 reply; 7+ messages in thread
From: Caio Marcelo de Oliveira Filho @ 2015-06-25  7:32 UTC (permalink / raw)
  To: git; +Cc: Caio Marcelo de Oliveira Filho

In projects that use Signed-off-by, it's convenient to include that line
in the commit 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>
---
 Documentation/config.txt     |  6 ++++++
 Documentation/git-commit.txt |  5 +++++
 builtin/commit.c             |  4 ++++
 t/t7500-commit.sh            | 22 ++++++++++++++++++++++
 4 files changed, 37 insertions(+)

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/t/t7500-commit.sh b/t/t7500-commit.sh
index 116885a..fcb39b4 100755
--- a/t/t7500-commit.sh
+++ b/t/t7500-commit.sh
@@ -179,6 +179,28 @@ test_expect_success '--signoff' '
 	test_cmp expect output
 '
 
+test_expect_success 'commit.signoff config option' '
+	git 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 &&
+	git config --unset commit.signoff &&
+	test_cmp expect output
+'
+
+cat > expect <<EOF
+no signed off by here
+EOF
+
+test_expect_success '--no-signoff' '
+	git 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 &&
+	git config --unset commit.signoff &&
+	test_cmp expect output
+'
+
 test_expect_success 'commit message from file (1)' '
 	mkdir subdir &&
 	echo "Log in top directory" >log &&
-- 
2.4.4.489.gc2a2b54.dirty

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] commit: add commit.signoff config option
  2015-06-25  7:30 cmarcelo
@ 2015-06-25  8:21 ` Alexander Kuleshov
  2015-06-25  8:32   ` Remi Galan Alfonso
  0 siblings, 1 reply; 7+ messages in thread
From: Alexander Kuleshov @ 2015-06-25  8:21 UTC (permalink / raw)
  To: cmarcelo; +Cc: git

On 06/25, cmarcelo@gmail.com wrote:
> From: Caio Marcelo de Oliveira Filho <cmarcelo@gmail.com>
> 
> In projects that use Signed-off-by, it's convenient to include that line
> in the commit 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.
> 

Hello, also would be great to have bash completion for the --no-signoff

Thank you.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] commit: add commit.signoff config option
  2015-06-25  8:21 ` Alexander Kuleshov
@ 2015-06-25  8:32   ` Remi Galan Alfonso
  2015-06-25 14:57     ` Caio Marcelo de Oliveira Filho
  0 siblings, 1 reply; 7+ messages in thread
From: Remi Galan Alfonso @ 2015-06-25  8:32 UTC (permalink / raw)
  To: cmarcelo; +Cc: git

Caio Marcelo de Oliveira Filho <cmarcelo@gmail.com> writes:
> +test_expect_success 'commit.signoff config option' '
> +        git 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 &&
> +        git config --unset commit.signoff &&
> +        test_cmp expect output
> +'
> +
> +cat > expect <<EOF
> +no signed off by here
> +EOF
> +
> +test_expect_success '--no-signoff' '
> +        git 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 &&
> +        git config --unset commit.signoff &&
> +        test_cmp expect output
> +'
> +

In both tests, you should probably use 'test_config' instead of 'git
config [...] git config --unset', it takes care of it for you (also
should prevent the case where the config is not unset when your test
fails in the middle).

For example, the first test would be:
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
'

Rémi

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] commit: add commit.signoff config option
  2015-06-25  7:32 [PATCH] commit: add commit.signoff config option Caio Marcelo de Oliveira Filho
@ 2015-06-25  8:43 ` Christian Couder
  2015-06-25 14:55   ` Caio Marcelo de Oliveira Filho
  0 siblings, 1 reply; 7+ messages in thread
From: Christian Couder @ 2015-06-25  8:43 UTC (permalink / raw)
  To: Caio Marcelo de Oliveira Filho; +Cc: git

On Thu, Jun 25, 2015 at 9:32 AM, Caio Marcelo de Oliveira Filho
<cmarcelo@gmail.com> wrote:
> In projects that use Signed-off-by, it's convenient to include that line
> in the commit by default. The commit.signoff config option allows to add
> that line in all commits automatically.

You can use a commit template.

Or you can use the "commit-msg" hook. For example with commands like:

grep "^Signed-off-by:" "$1" ||
echo "Signed-off-by: $(git config user.name) <$(git config user.email)>" >>"$1"

If you have more complex needs, there is also "git interpret-trailers"
(see the examples in the man page).

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] commit: add commit.signoff config option
  2015-06-25  8:43 ` Christian Couder
@ 2015-06-25 14:55   ` Caio Marcelo de Oliveira Filho
  0 siblings, 0 replies; 7+ messages in thread
From: Caio Marcelo de Oliveira Filho @ 2015-06-25 14:55 UTC (permalink / raw)
  To: Christian Couder; +Cc: git

On Thu, Jun 25, 2015 at 5:43 AM, Christian Couder
<christian.couder@gmail.com> wrote:
> You can use a commit template.
>
> Or you can use the "commit-msg" hook. For example with commands like:
>
> grep "^Signed-off-by:" "$1" ||
> echo "Signed-off-by: $(git config user.name) <$(git config user.email)>" >>"$1"
>
> If you have more complex needs, there is also "git interpret-trailers"
> (see the examples in the man page).

Thanks for the references. I was initially using a commit template to solve
the problem. But I've considered that since we already handle
"Signed-off-by" somewhat specially (e.g. "commit -s"), and how common this
case is, it was worth adding a config option.


-- 
Caio Marcelo de Oliveira Filho

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] commit: add commit.signoff config option
  2015-06-25  8:32   ` Remi Galan Alfonso
@ 2015-06-25 14:57     ` Caio Marcelo de Oliveira Filho
  0 siblings, 0 replies; 7+ messages in thread
From: Caio Marcelo de Oliveira Filho @ 2015-06-25 14:57 UTC (permalink / raw)
  To: Remi Galan Alfonso; +Cc: git

> In both tests, you should probably use 'test_config' instead of 'git
> config [...] git config --unset', it takes care of it for you (also
> should prevent the case where the config is not unset when your test
> fails in the middle).

Posted a v2 with this improvement and the bash completion.
Thanks for the review.


-- 
Caio Marcelo de Oliveira Filho

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-06-25 14:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-25  7:32 [PATCH] commit: add commit.signoff config option Caio Marcelo de Oliveira Filho
2015-06-25  8:43 ` Christian Couder
2015-06-25 14:55   ` Caio Marcelo de Oliveira Filho
  -- strict thread matches above, loose matches on Subject: below --
2015-06-25  7:30 cmarcelo
2015-06-25  8:21 ` Alexander Kuleshov
2015-06-25  8:32   ` Remi Galan Alfonso
2015-06-25 14:57     ` Caio Marcelo de Oliveira Filho

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).