{"thread":{"id":"42202","subject":"[PATCH] commit-tree: do not pay attention to commit.gpgsign","startedAt":"2016-05-02T21:58:45Z","lastAt":"2016-05-03T18:58:02Z","messageCount":4,"participants":["Junio C Hamano","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"285214","messageId":"xmqqlh3sqfze.fsf@gitster.mtv.corp.google.com","threadId":"42202","inReplyTo":null,"subject":"[PATCH] commit-tree: do not pay attention to commit.gpgsign","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-05-02T21:58:45Z","receivedAt":"2016-05-02T21:58:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"ba3c69a9 (commit: teach --gpg-sign option, 2011-10-05) introduced a\n\"signed commit\" by teaching --[no-gpg-sign option and commit.gpgsign\nconfiguration variable to various commands that create commits.\n\nTeaching these to \"git commit\" and \"git merge\", both of which are\nend-user facing Porcelain commands, was perfectly fine.  Allowing\nthe plumbing \"git commit-tree\" to suddenly change the behaviour to\nsurprise the scripts by paying attention to commit.gpgsign was not.\n\nAmong the in-tree scripts, filter-branch, quiltimport, rebase and\nstash are the commands that run \"commit-tree\".  If any of these\nwants to allow users to always sign every single commit, they should\noffer their own configuration (e.g. \"filterBranch..gpgsign\") with an\noption to disable (e.g. \"git filter-branch --no-gpgsign\").\n\nIgnoring commit.gpgsign option _obviously_ breaks the backward\ncompatibility, but I seriously doubt anybody sane is depending on\nthis misfeature that commit-tree blindly follows commit.gpgsign in\nany third-party script that calls it.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * This is an simpler alternative that forces commit-tree callers\n   that want to honor commit.gpgsign to do so themselves.\n\n builtin/commit-tree.c | 15 +--------------\n 1 file changed, 1 insertion(+), 14 deletions(-)\n\ndiff --git a/builtin/commit-tree.c b/builtin/commit-tree.c\nindex 3feeffe..e4ba0d8 100644\n--- a/builtin/commit-tree.c\n+++ b/builtin/commit-tree.c\n@@ -8,7 +8,6 @@\n #include \"tree.h\"\n #include \"builtin.h\"\n #include \"utf8.h\"\n-#include \"gpg-interface.h\"\n \n static const char commit_tree_usage[] = \"git commit-tree [(-p <sha1>)...] [-S[<keyid>]] [-m <message>] [-F <file>] <sha1>\";\n \n@@ -28,18 +27,6 @@ static void new_parent(struct commit *parent, struct commit_list **parents_p)\n \tcommit_list_insert(parent, parents_p);\n }\n \n-static int commit_tree_config(const char *var, const char *value, void *cb)\n-{\n-\tint status = git_gpg_config(var, value, NULL);\n-\tif (status)\n-\t\treturn status;\n-\tif (!strcmp(var, \"commit.gpgsign\")) {\n-\t\tsign_commit = git_config_bool(var, value) ? \"\" : NULL;\n-\t\treturn 0;\n-\t}\n-\treturn git_default_config(var, value, cb);\n-}\n-\n int cmd_commit_tree(int argc, const char **argv, const char *prefix)\n {\n \tint i, got_tree = 0;\n@@ -48,7 +35,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)\n \tunsigned char commit_sha1[20];\n \tstruct strbuf buffer = STRBUF_INIT;\n \n-\tgit_config(commit_tree_config, NULL);\n+\tgit_config(git_default_config, NULL);\n \n \tif (argc < 2 || !strcmp(argv[1], \"-h\"))\n \t\tusage(commit_tree_usage);\n"},{"id":"285240","messageId":"20160503041256.GA30529@sigill.intra.peff.net","threadId":"42202","inReplyTo":"xmqqlh3sqfze.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] commit-tree: do not pay attention to commit.gpgsign","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-05-03T04:12:57Z","receivedAt":"2016-05-03T04:12:57Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, May 02, 2016 at 02:58:45PM -0700, Junio C Hamano wrote:\n\n> ba3c69a9 (commit: teach --gpg-sign option, 2011-10-05) introduced a\n> \"signed commit\" by teaching --[no-gpg-sign option and commit.gpgsign\n> configuration variable to various commands that create commits.\n> \n> Teaching these to \"git commit\" and \"git merge\", both of which are\n> end-user facing Porcelain commands, was perfectly fine.  Allowing\n> the plumbing \"git commit-tree\" to suddenly change the behaviour to\n> surprise the scripts by paying attention to commit.gpgsign was not.\n> \n> Among the in-tree scripts, filter-branch, quiltimport, rebase and\n> stash are the commands that run \"commit-tree\".  If any of these\n> wants to allow users to always sign every single commit, they should\n> offer their own configuration (e.g. \"filterBranch..gpgsign\") with an\n> option to disable (e.g. \"git filter-branch --no-gpgsign\").\n> \n> Ignoring commit.gpgsign option _obviously_ breaks the backward\n> compatibility, but I seriously doubt anybody sane is depending on\n> this misfeature that commit-tree blindly follows commit.gpgsign in\n> any third-party script that calls it.\n> \n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n> \n>  * This is an simpler alternative that forces commit-tree callers\n>    that want to honor commit.gpgsign to do so themselves.\n\nI don't have any such scripts myself (aside from git-stash, whose\nsigning behavior is moderately annoying), but I think this simpler form\nis fine. There is already an escape hatch for scripts, and it is:\n\n  if test \"$(git config --bool commit.gpgsign)\" = \"true\"; then\n          sign=-S\n  else\n          sign=\n  fi\n\n  git commit-tree $sign ...\n\nThat is a few more lines than \"--use-commit-gpgsign-config\", but it's\nsimple enough to be acceptable, and matches the same technique that\nother config options need when used with plumbing.\n\nSo I think the motivation and premise are good, but...\n\n> -static int commit_tree_config(const char *var, const char *value, void *cb)\n> -{\n> -\tint status = git_gpg_config(var, value, NULL);\n> -\tif (status)\n> -\t\treturn status;\n> -\tif (!strcmp(var, \"commit.gpgsign\")) {\n> -\t\tsign_commit = git_config_bool(var, value) ? \"\" : NULL;\n> -\t\treturn 0;\n> -\t}\n> -\treturn git_default_config(var, value, cb);\n> -}\n> -\n\nI think this may be going too far. If I do \"git commit-tree -S\", I'd\nexpect it to use gpg.program, but here you are dropping the call to\ngit_gpg_config. Likewise for user.signingkey.\n\nSo I think you just want to drop the commit.gpgsign block here, and keep\nthe rest.\n\n-Peff\n"},{"id":"285348","messageId":"xmqqfutznhqw.fsf_-_@gitster.mtv.corp.google.com","threadId":"42202","inReplyTo":"20160503041256.GA30529@sigill.intra.peff.net","subject":"Re* [PATCH] commit-tree: do not pay attention to commit.gpgsign","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-05-03T18:01:11Z","receivedAt":"2016-05-03T18:01:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> So I think the motivation and premise are good, but...\n>\n>> -static int commit_tree_config(const char *var, const char *value, void *cb)\n>> -{\n>> -\tint status = git_gpg_config(var, value, NULL);\n>> -\tif (status)\n>> -\t\treturn status;\n>> -\tif (!strcmp(var, \"commit.gpgsign\")) {\n>> -\t\tsign_commit = git_config_bool(var, value) ? \"\" : NULL;\n>> -\t\treturn 0;\n>> -\t}\n>> -\treturn git_default_config(var, value, cb);\n>> -}\n>> -\n>\n> I think this may be going too far. If I do \"git commit-tree -S\", I'd\n> expect it to use gpg.program, but here you are dropping the call to\n> git_gpg_config. Likewise for user.signingkey.\n\nThanks (and thanks Eric for typospotting).\n\n-- >8 --\nba3c69a9 (commit: teach --gpg-sign option, 2011-10-05) introduced a\n\"signed commit\" by teaching the --[no]-gpg-sign option and the\ncommit.gpgsign configuration variable to various commands that\ncreate commits.\n\nTeaching these to \"git commit\" and \"git merge\", both of which are\nend-user facing Porcelain commands, was perfectly fine.  Allowing\nthe plumbing \"git commit-tree\" to suddenly change the behaviour to\nsurprise the scripts by paying attention to commit.gpgsign was not.\n\nAmong the in-tree scripts, filter-branch, quiltimport, rebase and\nstash are the commands that run \"commit-tree\".  If any of these\nwants to allow users to always sign every single commit, they should\noffer their own configuration (e.g. \"filterBranch.gpgsign\") with an\noption to disable signing (e.g. \"git filter-branch --no-gpgsign\").\n\nIgnoring commit.gpgsign option _obviously_ breaks the backward\ncompatibility, but it is easy to follow the standard pattern in\nscripts to honor whatever configuration variable they choose to\nfollow.  E.g.\n\n\tcase $(git config --bool commit.gpgsign) in\n\ttrue) sign=-S ;;\n\t*) sign= ;;\n\tesac &&\n\tgit commit-tree $sign ...whatever other args...\n\nDo so to make sure that \"git rebase\" keeps paying attention to the\nconfiguration variable, which unfortunately is a documented mistake.\n\nHelped-by: Jeff King <peff@peff.net>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Documentation/git-commit-tree.txt |  4 ++--\n builtin/commit-tree.c             |  4 ----\n git-rebase.sh                     |  5 ++++-\n t/t7510-signed-commit.sh          | 13 ++++++++++---\n 4 files changed, 16 insertions(+), 10 deletions(-)\n\ndiff --git a/Documentation/git-commit-tree.txt b/Documentation/git-commit-tree.txt\nindex f5f2a8d..eb273c3 100644\n--- a/Documentation/git-commit-tree.txt\n+++ b/Documentation/git-commit-tree.txt\n@@ -59,8 +59,8 @@ OPTIONS\n \tGPG-sign commit.\n \n --no-gpg-sign::\n-\tCountermand `commit.gpgSign` configuration variable that is\n-\tset to force each and every commit to be signed.\n+\tDo not GPG-sign commit, to countermand a `--gpg-sign` option\n+\tgiven earlier on the command line.\n \n \n Commit Information\ndiff --git a/builtin/commit-tree.c b/builtin/commit-tree.c\nindex 25aa2cd..15de7e8 100644\n--- a/builtin/commit-tree.c\n+++ b/builtin/commit-tree.c\n@@ -33,10 +33,6 @@ static int commit_tree_config(const char *var, const char *value, void *cb)\n \tint status = git_gpg_config(var, value, NULL);\n \tif (status)\n \t\treturn status;\n-\tif (!strcmp(var, \"commit.gpgsign\")) {\n-\t\tsign_commit = git_config_bool(var, value) ? \"\" : NULL;\n-\t\treturn 0;\n-\t}\n \treturn git_default_config(var, value, cb);\n }\n \ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 90854e3..4d46662 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -87,7 +87,10 @@ preserve_merges=\n autosquash=\n keep_empty=\n test \"$(git config --bool rebase.autosquash)\" = \"true\" && autosquash=t\n-gpg_sign_opt=\n+case \"$(git config --bool commit.gpgsign)\" in\n+true)\tgpg_sign_opt=-S ;;\n+*)\tgpg_sign_opt= ;;\n+esac\n \n read_basic_state () {\n \ttest -f \"$state_dir/head-name\" &&\ndiff --git a/t/t7510-signed-commit.sh b/t/t7510-signed-commit.sh\nindex 13331e5..7b365ee 100755\n--- a/t/t7510-signed-commit.sh\n+++ b/t/t7510-signed-commit.sh\n@@ -45,12 +45,18 @@ test_expect_success GPG 'create signed commits' '\n \tgit tag seventh-signed &&\n \n \techo 8 >file && test_tick && git commit -a -m eighth -SB7227189 &&\n-\tgit tag eighth-signed-alt\n+\tgit tag eighth-signed-alt &&\n+\n+\t# commit.gpgsign is still on but this must not be signed\n+\tgit tag ninth-unsigned $(echo 9 | git commit-tree HEAD^{tree}) &&\n+\t# explicit -S of course must sign.\n+\tgit tag tenth-signed $(echo 9 | git commit-tree -S HEAD^{tree})\n '\n \n test_expect_success GPG 'verify and show signatures' '\n \t(\n-\t\tfor commit in initial second merge fourth-signed fifth-signed sixth-signed seventh-signed\n+\t\tfor commit in initial second merge fourth-signed \\\n+\t\t\tfifth-signed sixth-signed seventh-signed tenth-signed\n \t\tdo\n \t\t\tgit verify-commit $commit &&\n \t\t\tgit show --pretty=short --show-signature $commit >actual &&\n@@ -60,7 +66,8 @@ test_expect_success GPG 'verify and show signatures' '\n \t\tdone\n \t) &&\n \t(\n-\t\tfor commit in merge^2 fourth-unsigned sixth-unsigned seventh-unsigned\n+\t\tfor commit in merge^2 fourth-unsigned sixth-unsigned \\\n+\t\t\tseventh-unsigned ninth-unsigned\n \t\tdo\n \t\t\ttest_must_fail git verify-commit $commit &&\n \t\t\tgit show --pretty=short --show-signature $commit >actual &&\n-- \n2.8.2-486-gecbb083\n"},{"id":"285358","messageId":"20160503185802.GB30530@sigill.intra.peff.net","threadId":"42202","inReplyTo":"xmqqfutznhqw.fsf_-_@gitster.mtv.corp.google.com","subject":"Re: Re* [PATCH] commit-tree: do not pay attention to commit.gpgsign","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-05-03T18:58:02Z","receivedAt":"2016-05-03T18:58:02Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, May 03, 2016 at 11:01:11AM -0700, Junio C Hamano wrote:\n\n> Ignoring commit.gpgsign option _obviously_ breaks the backward\n> compatibility, but it is easy to follow the standard pattern in\n> scripts to honor whatever configuration variable they choose to\n> follow.  E.g.\n> \n> \tcase $(git config --bool commit.gpgsign) in\n> \ttrue) sign=-S ;;\n> \t*) sign= ;;\n> \tesac &&\n> \tgit commit-tree $sign ...whatever other args...\n> \n> Do so to make sure that \"git rebase\" keeps paying attention to the\n> configuration variable, which unfortunately is a documented mistake.\n> \n> Helped-by: Jeff King <peff@peff.net>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n>  Documentation/git-commit-tree.txt |  4 ++--\n>  builtin/commit-tree.c             |  4 ----\n>  git-rebase.sh                     |  5 ++++-\n>  t/t7510-signed-commit.sh          | 13 ++++++++++---\n>  4 files changed, 16 insertions(+), 10 deletions(-)\n\nThanks, this looks good to me[1]. Especially thinking about the rebase\ncase you handle here makes me more convinced than ever that an option\nlike \"--respect-commit-gpgsign-config\" is the wrong path. Because the\nultimate fate for rebase may be something like:\n\n  case $(git config --bool rebase.gpgsign) in\n  true) sign=-S ;;\n  false) sign= ;;\n  *)\n\tcase $(git config --bool commit.gpgsign) in\n\ttrue) sign=-S ;;\n\t*) sign= ;;\n\tesac\n\t;;\n  esac\n\nYou _can_ implement that by falling back to --respect... in the \"*\"\ncase, but at that point it is not saving much code, and merely making\nthings unnecessarily confusing.\n\n-Peff\n\n[1] I will say that I am happy with rebase respecting commit.gpgsign\n    myself. The config I want is really \"sign all commits I create\", so\n    I'd end up setting rebase.gpgsign, too, if it existed. But maybe\n    other people have different workflows.\n"}]}