Skip to content

Commit cf0ad4d

Browse files
sgngitster
authored andcommitted
cherry-pick/revert: honour --no-gpg-sign in all case
{cherry-pick,revert} --edit hasn't honoured --no-gpg-sign yet. Pass this option down to git-commit to honour it. Signed-off-by: Đoàn Trần Công Danh <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c241371 commit cf0ad4d

File tree

4 files changed

+96
-2
lines changed

4 files changed

+96
-2
lines changed

Documentation/git-cherry-pick.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,12 @@ effect to your index in a row.
109109

110110
-S[<keyid>]::
111111
--gpg-sign[=<keyid>]::
112+
--no-gpg-sign::
112113
GPG-sign commits. The `keyid` argument is optional and
113114
defaults to the committer identity; if specified, it must be
114-
stuck to the option without a space.
115+
stuck to the option without a space. `--no-gpg-sign` is useful to
116+
countermand both `commit.gpgSign` configuration variable, and
117+
earlier `--gpg-sign`.
115118

116119
--ff::
117120
If the current HEAD is the same as the parent of the

Documentation/git-revert.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,12 @@ effect to your index in a row.
9090

9191
-S[<keyid>]::
9292
--gpg-sign[=<keyid>]::
93+
--no-gpg-sign::
9394
GPG-sign commits. The `keyid` argument is optional and
9495
defaults to the committer identity; if specified, it must be
95-
stuck to the option without a space.
96+
stuck to the option without a space. `--no-gpg-sign` is useful to
97+
countermand both `commit.gpgSign` configuration variable, and
98+
earlier `--gpg-sign`.
9699

97100
-s::
98101
--signoff::

sequencer.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,8 @@ static int run_git_commit(struct repository *r,
946946
argv_array_push(&cmd.args, "--amend");
947947
if (opts->gpg_sign)
948948
argv_array_pushf(&cmd.args, "-S%s", opts->gpg_sign);
949+
else
950+
argv_array_push(&cmd.args, "--no-gpg-sign");
949951
if (defmsg)
950952
argv_array_pushl(&cmd.args, "-F", defmsg, NULL);
951953
else if (!(flags & EDIT_MSG))

t/t3514-cherry-pick-revert-gpg.sh

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2020 Doan Tran Cong Danh
4+
#
5+
6+
test_description='test {cherry-pick,revert} --[no-]gpg-sign'
7+
8+
. ./test-lib.sh
9+
. "$TEST_DIRECTORY/lib-gpg.sh"
10+
11+
if ! test_have_prereq GPG
12+
then
13+
skip_all='skip all test {cherry-pick,revert} --[no-]gpg-sign, gpg not available'
14+
test_done
15+
fi
16+
17+
test_gpg_sign () {
18+
local must_fail= will=will fake_editor=
19+
if test "x$1" = "x!"
20+
then
21+
must_fail=test_must_fail
22+
will="won't"
23+
shift
24+
fi
25+
conf=$1
26+
cmd=$2
27+
cmit=$3
28+
shift 3
29+
test_expect_success "$cmd $* $cmit with commit.gpgsign=$conf $will sign commit" "
30+
git reset --hard tip &&
31+
git config commit.gpgsign $conf &&
32+
git $cmd $* $cmit &&
33+
git rev-list tip.. >rev-list &&
34+
$must_fail git verify-commit \$(cat rev-list)
35+
"
36+
}
37+
38+
test_expect_success 'setup' '
39+
test_commit one &&
40+
git switch -c side &&
41+
test_commit side1 &&
42+
test_commit side2 &&
43+
git switch - &&
44+
test_commit two &&
45+
test_commit three &&
46+
test_commit tip
47+
'
48+
49+
test_gpg_sign ! false cherry-pick side
50+
test_gpg_sign ! false cherry-pick ..side
51+
test_gpg_sign true cherry-pick side
52+
test_gpg_sign true cherry-pick ..side
53+
test_gpg_sign ! true cherry-pick side --no-gpg-sign
54+
test_gpg_sign ! true cherry-pick ..side --no-gpg-sign
55+
test_gpg_sign ! true cherry-pick side --gpg-sign --no-gpg-sign
56+
test_gpg_sign ! true cherry-pick ..side --gpg-sign --no-gpg-sign
57+
test_gpg_sign false cherry-pick side --no-gpg-sign --gpg-sign
58+
test_gpg_sign false cherry-pick ..side --no-gpg-sign --gpg-sign
59+
test_gpg_sign true cherry-pick side --edit
60+
test_gpg_sign true cherry-pick ..side --edit
61+
test_gpg_sign ! true cherry-pick side --edit --no-gpg-sign
62+
test_gpg_sign ! true cherry-pick ..side --edit --no-gpg-sign
63+
test_gpg_sign ! true cherry-pick side --edit --gpg-sign --no-gpg-sign
64+
test_gpg_sign ! true cherry-pick ..side --edit --gpg-sign --no-gpg-sign
65+
test_gpg_sign false cherry-pick side --edit --no-gpg-sign --gpg-sign
66+
test_gpg_sign false cherry-pick ..side --edit --no-gpg-sign --gpg-sign
67+
68+
test_gpg_sign ! false revert HEAD --edit
69+
test_gpg_sign ! false revert two.. --edit
70+
test_gpg_sign true revert HEAD --edit
71+
test_gpg_sign true revert two.. --edit
72+
test_gpg_sign ! true revert HEAD --edit --no-gpg-sign
73+
test_gpg_sign ! true revert two.. --edit --no-gpg-sign
74+
test_gpg_sign ! true revert HEAD --edit --gpg-sign --no-gpg-sign
75+
test_gpg_sign ! true revert two.. --edit --gpg-sign --no-gpg-sign
76+
test_gpg_sign false revert HEAD --edit --no-gpg-sign --gpg-sign
77+
test_gpg_sign false revert two.. --edit --no-gpg-sign --gpg-sign
78+
test_gpg_sign true revert HEAD --no-edit
79+
test_gpg_sign true revert two.. --no-edit
80+
test_gpg_sign ! true revert HEAD --no-edit --no-gpg-sign
81+
test_gpg_sign ! true revert two.. --no-edit --no-gpg-sign
82+
test_gpg_sign ! true revert HEAD --no-edit --gpg-sign --no-gpg-sign
83+
test_gpg_sign ! true revert two.. --no-edit --gpg-sign --no-gpg-sign
84+
test_gpg_sign false revert HEAD --no-edit --no-gpg-sign --gpg-sign
85+
86+
test_done

0 commit comments

Comments
 (0)