commit-tree: do not pay attention to commit.gpgsign
authorJunio C Hamano <gitster@pobox.com>
Mon, 2 May 2016 21:58:45 +0000 (14:58 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 3 May 2016 17:59:25 +0000 (10:59 -0700)
ba3c69a9 (commit: teach --gpg-sign option, 2011-10-05) introduced a
"signed commit" by teaching the --[no]-gpg-sign option and the
commit.gpgsign configuration variable to various commands that
create commits.

Teaching these to "git commit" and "git merge", both of which are
end-user facing Porcelain commands, was perfectly fine. Allowing
the plumbing "git commit-tree" to suddenly change the behaviour to
surprise the scripts by paying attention to commit.gpgsign was not.

Among the in-tree scripts, filter-branch, quiltimport, rebase and
stash are the commands that run "commit-tree". If any of these
wants to allow users to always sign every single commit, they should
offer their own configuration (e.g. "filterBranch.gpgsign") with an
option to disable signing (e.g. "git filter-branch --no-gpgsign").

Ignoring commit.gpgsign option _obviously_ breaks the backward
compatibility, but it is easy to follow the standard pattern in
scripts to honor whatever configuration variable they choose to
follow. E.g.

case $(git config --bool commit.gpgsign) in
true) sign=-S ;;
*) sign= ;;
esac &&
git commit-tree $sign ...whatever other args...

Do so to make sure that "git rebase" keeps paying attention to the
configuration variable, which unfortunately is a documented mistake.

Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-commit-tree.txt
builtin/commit-tree.c
git-rebase.sh
t/t7510-signed-commit.sh
index f5f2a8d326502714299cf85d9819bb065d5af390..eb273c3d8a0972fb32cdb9c61949e2b3f0e0953c 100644 (file)
@@ -59,8 +59,8 @@ OPTIONS
        GPG-sign commit.
 
 --no-gpg-sign::
-       Countermand `commit.gpgSign` configuration variable that is
-       set to force each and every commit to be signed.
+       Do not GPG-sign commit, to countermand a `--gpg-sign` option
+       given earlier on the command line.
 
 
 Commit Information
index 25aa2cdef3557c67a9482492a4d0294bc7b89b04..15de7e8f2203f884d88ec8497f123ca1c713b844 100644 (file)
@@ -33,10 +33,6 @@ static int commit_tree_config(const char *var, const char *value, void *cb)
        int status = git_gpg_config(var, value, NULL);
        if (status)
                return status;
-       if (!strcmp(var, "commit.gpgsign")) {
-               sign_commit = git_config_bool(var, value) ? "" : NULL;
-               return 0;
-       }
        return git_default_config(var, value, cb);
 }
 
index 90854e38cb9ceb6985a5d7bd9faae722ed92361f..4d466622a6c39141572d80d8e307687a3e659371 100755 (executable)
@@ -87,7 +87,10 @@ preserve_merges=
 autosquash=
 keep_empty=
 test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
-gpg_sign_opt=
+case "$(git config --bool commit.gpgsign)" in
+true)  gpg_sign_opt=-S ;;
+*)     gpg_sign_opt= ;;
+esac
 
 read_basic_state () {
        test -f "$state_dir/head-name" &&
index 13331e533bf520b6f268df16f8a143b8661a1c72..7b365ee115432322d2da9eeea31788c6f8d3c9b6 100755 (executable)
@@ -45,12 +45,18 @@ test_expect_success GPG 'create signed commits' '
        git tag seventh-signed &&
 
        echo 8 >file && test_tick && git commit -a -m eighth -SB7227189 &&
-       git tag eighth-signed-alt
+       git tag eighth-signed-alt &&
+
+       # commit.gpgsign is still on but this must not be signed
+       git tag ninth-unsigned $(echo 9 | git commit-tree HEAD^{tree}) &&
+       # explicit -S of course must sign.
+       git tag tenth-signed $(echo 9 | git commit-tree -S HEAD^{tree})
 '
 
 test_expect_success GPG 'verify and show signatures' '
        (
-               for commit in initial second merge fourth-signed fifth-signed sixth-signed seventh-signed
+               for commit in initial second merge fourth-signed \
+                       fifth-signed sixth-signed seventh-signed tenth-signed
                do
                        git verify-commit $commit &&
                        git show --pretty=short --show-signature $commit >actual &&
@@ -60,7 +66,8 @@ test_expect_success GPG 'verify and show signatures' '
                done
        ) &&
        (
-               for commit in merge^2 fourth-unsigned sixth-unsigned seventh-unsigned
+               for commit in merge^2 fourth-unsigned sixth-unsigned \
+                       seventh-unsigned ninth-unsigned
                do
                        test_must_fail git verify-commit $commit &&
                        git show --pretty=short --show-signature $commit >actual &&