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 <congdanhqx@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Đoàn Trần Công Danh committed
Apr 3, 2020 at 17:28 UTC
cf0ad4d199924073ef485ff60393c8a81edbdbb6
4 files changed
+96
-2
Documentation/git-cherry-pick.txt
+4
-1
@@ -109,9 +109,12 @@ effect to your index in a row.
109
110
-S[<keyid>]::
111
--gpg-sign[=<keyid>]::
112
+--no-gpg-sign::
113
GPG-sign commits. The `keyid` argument is optional and
114
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`.
118
119
--ff::
120
If the current HEAD is the same as the parent of the
Documentation/git-revert.txt
+4
-1
@@ -90,9 +90,12 @@ effect to your index in a row.
90
91
-S[<keyid>]::
92
--gpg-sign[=<keyid>]::
93
+--no-gpg-sign::
94
GPG-sign commits. The `keyid` argument is optional and
95
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`.
99
100
-s::
101
--signoff::
sequencer.c
+2
@@ -946,6 +946,8 @@ static int run_git_commit(struct repository *r,
946
argv_array_push(&cmd.args, "--amend");
947
if (opts->gpg_sign)
948
argv_array_pushf(&cmd.args, "-S%s", opts->gpg_sign);
949
+ else
950
+ argv_array_push(&cmd.args, "--no-gpg-sign");
951
if (defmsg)
952
argv_array_pushl(&cmd.args, "-F", defmsg, NULL);
953
else if (!(flags & EDIT_MSG))
t/t3514-cherry-pick-revert-gpg.sh
new
+86
@@ -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