Skip to content

Commit c241371

Browse files
sgngitster
authored andcommitted
rebase.c: honour --no-gpg-sign
Signed-off-by: Đoàn Trần Công Danh <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 274b9cc commit c241371

File tree

3 files changed

+79
-4
lines changed

3 files changed

+79
-4
lines changed

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

builtin/rebase.c

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

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

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

1825-
if (gpg_sign) {
1826-
free(options.gpg_sign_opt);
1828+
if (gpg_sign)
18271829
options.gpg_sign_opt = xstrfmt("-S%s", gpg_sign);
1828-
}
18291830

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

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)