commit: add commit.signoff config option
PATCH 1/1 commit: add commit.signoff config option
From: Caio Marcelo de Oliveira Filho <[email protected]>
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.
--- Documentation/config.txt | 6 ++++++ Documentation/git-commit.txt | 5 +++++ builtin/commit.c | 4 ++++ t/t7500-commit.sh | 22 ++++++++++++++++++++++ 4 files changed, 37 insertions(+)
Documentation/config.txt +6 -0
@@ -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
Documentation/git-commit.txt +5 -0
@@ -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.
builtin/commit.c +4 -0
@@ -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)
t/t7500-commit.sh +22 -0
@@ -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 &&
Signature · 1 line
2.4.4.489.gc2a2b54.dirty
Quoted 9 lines · On 06/25, [email protected] wrote:
From: Caio Marcelo de Oliveira Filho <[email protected]>
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.
Quoted 12 lines · Caio Marcelo de Oliveira Filho
t/t7500-commit.sh +12
-0+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
t/t7500-commit.sh test_expect_success '--signoff' ' · line 203
Quoted 10 lines
t/t7500-commit.sh +10
-0+ +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
Quoted 4 lines
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.
Signature · 1 line
Caio Marcelo de Oliveira Filho