Skip to content

Commit fc3f6fd

Browse files
committed
Merge branch 'dd/no-gpg-sign'
"git rebase" learned the "--no-gpg-sign" option to countermand commit.gpgSign the user may have. * dd/no-gpg-sign: Documentation: document merge option --no-gpg-sign Documentation: merge commit-tree --[no-]gpg-sign Documentation: reword commit --no-gpg-sign Documentation: document am --no-gpg-sign cherry-pick/revert: honour --no-gpg-sign in all case rebase.c: honour --no-gpg-sign
2 parents 886fcb7 + 5c5bac1 commit fc3f6fd

11 files changed

+190
-18
lines changed

Documentation/git-am.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,12 @@ default. You can use `--no-utf8` to override this.
148148

149149
-S[<keyid>]::
150150
--gpg-sign[=<keyid>]::
151+
--no-gpg-sign::
151152
GPG-sign commits. The `keyid` argument is optional and
152153
defaults to the committer identity; if specified, it must be
153-
stuck to the option without a space.
154+
stuck to the option without a space. `--no-gpg-sign` is useful to
155+
countermand both `commit.gpgSign` configuration variable, and
156+
earlier `--gpg-sign`.
154157

155158
--continue::
156159
-r::

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-commit-tree.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,11 @@ OPTIONS
6161

6262
-S[<keyid>]::
6363
--gpg-sign[=<keyid>]::
64+
--no-gpg-sign::
6465
GPG-sign commits. The `keyid` argument is optional and
6566
defaults to the committer identity; if specified, it must be
66-
stuck to the option without a space.
67-
68-
--no-gpg-sign::
69-
Do not GPG-sign commit, to countermand a `--gpg-sign` option
70-
given earlier on the command line.
67+
stuck to the option without a space. `--no-gpg-sign` is useful to
68+
countermand a `--gpg-sign` option given earlier on the command line.
7169

7270
Commit Information
7371
------------------

Documentation/git-commit.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,12 @@ changes to tracked files.
348348

349349
-S[<keyid>]::
350350
--gpg-sign[=<keyid>]::
351+
--no-gpg-sign::
351352
GPG-sign commits. The `keyid` argument is optional and
352353
defaults to the committer identity; if specified, it must be
353-
stuck to the option without a space.
354-
355-
--no-gpg-sign::
356-
Countermand `commit.gpgSign` configuration variable that is
357-
set to force each and every commit to be signed.
354+
stuck to the option without a space. `--no-gpg-sign` is useful to
355+
countermand both `commit.gpgSign` configuration variable, and
356+
earlier `--gpg-sign`.
358357

359358
\--::
360359
Do not interpret any more arguments as options.

Documentation/git-rebase.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,12 @@ See also INCOMPATIBLE OPTIONS below.
354354

355355
-S[<keyid>]::
356356
--gpg-sign[=<keyid>]::
357+
--no-gpg-sign::
357358
GPG-sign commits. The `keyid` argument is optional and
358359
defaults to the committer identity; if specified, it must be
359-
stuck to the option without a space.
360+
stuck to the option without a space. `--no-gpg-sign` is useful to
361+
countermand both `commit.gpgSign` configuration variable, and
362+
earlier `--gpg-sign`.
360363

361364
-q::
362365
--quiet::

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::

Documentation/merge-options.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,12 @@ When not possible, refuse to merge and exit with a non-zero status.
6161

6262
-S[<keyid>]::
6363
--gpg-sign[=<keyid>]::
64+
--no-gpg-sign::
6465
GPG-sign the resulting merge commit. The `keyid` argument is
6566
optional and defaults to the committer identity; if specified,
66-
it must be stuck to the option without a space.
67+
it must be stuck to the option without a space. `--no-gpg-sign`
68+
is useful to countermand both `commit.gpgSign` configuration variable,
69+
and earlier `--gpg-sign`.
6770

6871
--log[=<n>]::
6972
--no-log::

builtin/rebase.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
15931593

15941594
options.allow_empty_message = 1;
15951595
git_config(rebase_config, &options);
1596+
/* options.gpg_sign_opt will be either "-S" or NULL */
1597+
gpg_sign = options.gpg_sign_opt ? "" : NULL;
1598+
FREE_AND_NULL(options.gpg_sign_opt);
15961599

15971600
if (options.use_legacy_rebase ||
15981601
!git_env_bool("GIT_TEST_REBASE_USE_BUILTIN", -1))
@@ -1823,10 +1826,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
18231826
if (options.empty != EMPTY_UNSPECIFIED)
18241827
imply_merge(&options, "--empty");
18251828

1826-
if (gpg_sign) {
1827-
free(options.gpg_sign_opt);
1829+
if (gpg_sign)
18281830
options.gpg_sign_opt = xstrfmt("-S%s", gpg_sign);
1829-
}
18301831

18311832
if (exec.nr) {
18321833
int i;

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/t3435-rebase-gpg-sign.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2020 Doan Tran Cong Danh
4+
#
5+
6+
test_description='test rebase --[no-]gpg-sign'
7+
8+
. ./test-lib.sh
9+
. "$TEST_DIRECTORY/lib-rebase.sh"
10+
. "$TEST_DIRECTORY/lib-gpg.sh"
11+
12+
if ! test_have_prereq GPG
13+
then
14+
skip_all='skip all test rebase --[no-]gpg-sign, gpg not available'
15+
test_done
16+
fi
17+
18+
test_rebase_gpg_sign () {
19+
local must_fail= will=will fake_editor=
20+
if test "x$1" = "x!"
21+
then
22+
must_fail=test_must_fail
23+
will="won't"
24+
shift
25+
fi
26+
conf=$1
27+
shift
28+
test_expect_success "rebase $* with commit.gpgsign=$conf $will sign commit" "
29+
git reset two &&
30+
git config commit.gpgsign $conf &&
31+
set_fake_editor &&
32+
FAKE_LINES='r 1 p 2' git rebase --force-rebase --root $* &&
33+
$must_fail git verify-commit HEAD^ &&
34+
$must_fail git verify-commit HEAD
35+
"
36+
}
37+
38+
test_expect_success 'setup' '
39+
test_commit one &&
40+
test_commit two &&
41+
test_must_fail git verify-commit HEAD &&
42+
test_must_fail git verify-commit HEAD^
43+
'
44+
45+
test_expect_success 'setup: merge commit' '
46+
test_commit fork-point &&
47+
git switch -c side &&
48+
test_commit three &&
49+
git switch master &&
50+
git merge --no-ff side &&
51+
git tag merged
52+
'
53+
54+
test_rebase_gpg_sign ! false
55+
test_rebase_gpg_sign true
56+
test_rebase_gpg_sign ! true --no-gpg-sign
57+
test_rebase_gpg_sign ! true --gpg-sign --no-gpg-sign
58+
test_rebase_gpg_sign false --no-gpg-sign --gpg-sign
59+
test_rebase_gpg_sign true -i
60+
test_rebase_gpg_sign ! true -i --no-gpg-sign
61+
test_rebase_gpg_sign ! true -i --gpg-sign --no-gpg-sign
62+
test_rebase_gpg_sign false -i --no-gpg-sign --gpg-sign
63+
64+
test_expect_failure 'rebase -p --no-gpg-sign override commit.gpgsign' '
65+
git reset --hard merged &&
66+
git config commit.gpgsign true &&
67+
git rebase -p --no-gpg-sign --onto=one fork-point master &&
68+
test_must_fail git verify-commit HEAD
69+
'
70+
71+
test_done

0 commit comments

Comments
 (0)