]> git.ipfire.org Git - thirdparty/git.git/commitdiff
cherry-pick/revert: honour --no-gpg-sign in all case
authorĐoàn Trần Công Danh <congdanhqx@gmail.com>
Fri, 3 Apr 2020 10:28:03 +0000 (17:28 +0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 3 Apr 2020 18:37:22 +0000 (11:37 -0700)
{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>
Documentation/git-cherry-pick.txt
Documentation/git-revert.txt
sequencer.c
t/t3514-cherry-pick-revert-gpg.sh [new file with mode: 0755]

index 83ce51aedfea54fd5150ef142aca24f8c1df95c9..75feeef08a0e64ac3f6bfc35290e92984c1a1580 100644 (file)
@@ -109,9 +109,12 @@ effect to your index in a row.
 
 -S[<keyid>]::
 --gpg-sign[=<keyid>]::
+--no-gpg-sign::
        GPG-sign commits. The `keyid` argument is optional and
        defaults to the committer identity; if specified, it must be
-       stuck to the option without a space.
+       stuck to the option without a space. `--no-gpg-sign` is useful to
+       countermand both `commit.gpgSign` configuration variable, and
+       earlier `--gpg-sign`.
 
 --ff::
        If the current HEAD is the same as the parent of the
index 9d22270757c9b5d402f680a3f5933989678cb6f0..044276e9da62af44af9a8d897df0dd536556610b 100644 (file)
@@ -90,9 +90,12 @@ effect to your index in a row.
 
 -S[<keyid>]::
 --gpg-sign[=<keyid>]::
+--no-gpg-sign::
        GPG-sign commits. The `keyid` argument is optional and
        defaults to the committer identity; if specified, it must be
-       stuck to the option without a space.
+       stuck to the option without a space. `--no-gpg-sign` is useful to
+       countermand both `commit.gpgSign` configuration variable, and
+       earlier `--gpg-sign`.
 
 -s::
 --signoff::
index e528225e787f4e26de604807efc798e8b967010e..6e6e98a0f8a69199d2b2972c69206dc7f218a9c1 100644 (file)
@@ -946,6 +946,8 @@ static int run_git_commit(struct repository *r,
                argv_array_push(&cmd.args, "--amend");
        if (opts->gpg_sign)
                argv_array_pushf(&cmd.args, "-S%s", opts->gpg_sign);
+       else
+               argv_array_push(&cmd.args, "--no-gpg-sign");
        if (defmsg)
                argv_array_pushl(&cmd.args, "-F", defmsg, NULL);
        else if (!(flags & EDIT_MSG))
diff --git a/t/t3514-cherry-pick-revert-gpg.sh b/t/t3514-cherry-pick-revert-gpg.sh
new file mode 100755 (executable)
index 0000000..5b2e250
--- /dev/null
@@ -0,0 +1,86 @@
+#!/bin/sh
+#
+# Copyright (c) 2020 Doan Tran Cong Danh
+#
+
+test_description='test {cherry-pick,revert} --[no-]gpg-sign'
+
+. ./test-lib.sh
+. "$TEST_DIRECTORY/lib-gpg.sh"
+
+if ! test_have_prereq GPG
+then
+       skip_all='skip all test {cherry-pick,revert} --[no-]gpg-sign, gpg not available'
+       test_done
+fi
+
+test_gpg_sign () {
+       local must_fail= will=will fake_editor=
+       if test "x$1" = "x!"
+       then
+               must_fail=test_must_fail
+               will="won't"
+               shift
+       fi
+       conf=$1
+       cmd=$2
+       cmit=$3
+       shift 3
+       test_expect_success "$cmd $* $cmit with commit.gpgsign=$conf $will sign commit" "
+               git reset --hard tip &&
+               git config commit.gpgsign $conf &&
+               git $cmd $* $cmit &&
+               git rev-list tip.. >rev-list &&
+               $must_fail git verify-commit \$(cat rev-list)
+       "
+}
+
+test_expect_success 'setup' '
+       test_commit one &&
+       git switch -c side &&
+       test_commit side1 &&
+       test_commit side2 &&
+       git switch - &&
+       test_commit two &&
+       test_commit three &&
+       test_commit tip
+'
+
+test_gpg_sign ! false cherry-pick   side
+test_gpg_sign ! false cherry-pick ..side
+test_gpg_sign   true  cherry-pick   side
+test_gpg_sign   true  cherry-pick ..side
+test_gpg_sign ! true  cherry-pick   side --no-gpg-sign
+test_gpg_sign ! true  cherry-pick ..side --no-gpg-sign
+test_gpg_sign ! true  cherry-pick   side --gpg-sign --no-gpg-sign
+test_gpg_sign ! true  cherry-pick ..side --gpg-sign --no-gpg-sign
+test_gpg_sign   false cherry-pick   side --no-gpg-sign --gpg-sign
+test_gpg_sign   false cherry-pick ..side --no-gpg-sign --gpg-sign
+test_gpg_sign   true  cherry-pick   side --edit
+test_gpg_sign   true  cherry-pick ..side --edit
+test_gpg_sign ! true  cherry-pick   side --edit --no-gpg-sign
+test_gpg_sign ! true  cherry-pick ..side --edit --no-gpg-sign
+test_gpg_sign ! true  cherry-pick   side --edit --gpg-sign --no-gpg-sign
+test_gpg_sign ! true  cherry-pick ..side --edit --gpg-sign --no-gpg-sign
+test_gpg_sign   false cherry-pick   side --edit --no-gpg-sign --gpg-sign
+test_gpg_sign   false cherry-pick ..side --edit --no-gpg-sign --gpg-sign
+
+test_gpg_sign ! false revert HEAD  --edit
+test_gpg_sign ! false revert two.. --edit
+test_gpg_sign   true  revert HEAD  --edit
+test_gpg_sign   true  revert two.. --edit
+test_gpg_sign ! true  revert HEAD  --edit --no-gpg-sign
+test_gpg_sign ! true  revert two.. --edit --no-gpg-sign
+test_gpg_sign ! true  revert HEAD  --edit --gpg-sign --no-gpg-sign
+test_gpg_sign ! true  revert two.. --edit --gpg-sign --no-gpg-sign
+test_gpg_sign   false revert HEAD  --edit --no-gpg-sign --gpg-sign
+test_gpg_sign   false revert two.. --edit --no-gpg-sign --gpg-sign
+test_gpg_sign   true  revert HEAD  --no-edit
+test_gpg_sign   true  revert two.. --no-edit
+test_gpg_sign ! true  revert HEAD  --no-edit --no-gpg-sign
+test_gpg_sign ! true  revert two.. --no-edit --no-gpg-sign
+test_gpg_sign ! true  revert HEAD  --no-edit --gpg-sign --no-gpg-sign
+test_gpg_sign ! true  revert two.. --no-edit --gpg-sign --no-gpg-sign
+test_gpg_sign   false revert HEAD  --no-edit --no-gpg-sign --gpg-sign
+
+test_done