{"thread":{"id":"45042","subject":"[PATCH] tag: add a config option for setting --annotate by default","startedAt":"2017-02-04T02:14:13Z","lastAt":"2017-02-05T04:11:09Z","messageCount":3,"participants":["David Aguilar","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"310828","messageId":"20170204021402.15927-1-davvid@gmail.com","threadId":"45042","inReplyTo":null,"subject":"[PATCH] tag: add a config option for setting --annotate by default","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2017-02-04T02:14:02Z","receivedAt":"2017-02-04T02:14:13Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"Make it easier for users to remember to annotate their tags.\nAllow setting the default value for \"--annotate\" via the \"tag.annotate\"\nconfiguration variable.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n Documentation/config.txt |  5 +++++\n builtin/tag.c            | 15 ++++++++++++---\n t/t7004-tag.sh           | 23 +++++++++++++++++++++++\n 3 files changed, 40 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex af2ae4cc02..0d562b97e9 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -2945,6 +2945,11 @@ submodule.alternateErrorStrategy\n \tas computed via `submodule.alternateLocation`. Possible values are\n \t`ignore`, `info`, `die`. Default is `die`.\n \n+tag.annotate::\n+\tA boolean to specify whether annotated tags should be created by\n+\tdefault.  If `--no-annotate` is specified on the command line,\n+\tit takes precedence over this option.\n+\n tag.forceSignAnnotated::\n \tA boolean to specify whether annotated tags created should be GPG signed.\n \tIf `--annotate` is specified on the command line, it takes\ndiff --git a/builtin/tag.c b/builtin/tag.c\nindex 73df728114..1cf9bb73ad 100644\n--- a/builtin/tag.c\n+++ b/builtin/tag.c\n@@ -29,6 +29,7 @@ static const char * const git_tag_usage[] = {\n };\n \n static unsigned int colopts;\n+static int force_annotate;\n static int force_sign_annotate;\n \n static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, const char *format)\n@@ -161,6 +162,10 @@ static int git_tag_config(const char *var, const char *value, void *cb)\n \tstatus = git_gpg_config(var, value, cb);\n \tif (status)\n \t\treturn status;\n+\tif (!strcmp(var, \"tag.annotate\")) {\n+\t\tforce_annotate = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \tif (!strcmp(var, \"tag.forcesignannotated\")) {\n \t\tforce_sign_annotate = git_config_bool(var, value);\n \t\treturn 0;\n@@ -326,7 +331,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \tstruct create_tag_options opt;\n \tchar *cleanup_arg = NULL;\n \tint create_reflog = 0;\n-\tint annotate = 0, force = 0;\n+\tint annotate = -1, force = 0;\n \tint cmdmode = 0, create_tag_object = 0;\n \tconst char *msgfile = NULL, *keyid = NULL;\n \tstruct msg_arg msg = { 0, STRBUF_INIT };\n@@ -387,11 +392,15 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \t\topt.sign = 1;\n \t\tset_signing_key(keyid);\n \t}\n-\tcreate_tag_object = (opt.sign || annotate || msg.given || msgfile);\n \n \tif (argc == 0 && !cmdmode)\n \t\tcmdmode = 'l';\n \n+\tif (force_annotate && !cmdmode && annotate == -1)\n+\t\tannotate = 1;\n+\n+\tcreate_tag_object = (opt.sign || annotate > 0 || msg.given || msgfile);\n+\n \tif ((create_tag_object || force) && (cmdmode != 0))\n \t\tusage_with_options(git_tag_usage, options);\n \n@@ -478,7 +487,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \t\tdie(_(\"Invalid cleanup mode %s\"), cleanup_arg);\n \n \tif (create_tag_object) {\n-\t\tif (force_sign_annotate && !annotate)\n+\t\tif (force_sign_annotate && annotate == -1)\n \t\t\topt.sign = 1;\n \t\tcreate_tag(object, tag, &buf, &opt, prev, object);\n \t}\ndiff --git a/t/t7004-tag.sh b/t/t7004-tag.sh\nindex 1cfa8a21d2..5ba52b57dd 100755\n--- a/t/t7004-tag.sh\n+++ b/t/t7004-tag.sh\n@@ -754,6 +754,29 @@ echo from a fake editor.\n EOF\n chmod +x fakeeditor\n \n+get_tag_header config-annotate $commit commit $time >expect\n+./fakeeditor >>expect\n+test_expect_success 'tag.annotate creates annotated tags' '\n+\ttest_config tag.annotate true &&\n+\tGIT_EDITOR=./fakeeditor git tag config-annotate &&\n+\tget_tag_msg config-annotate >actual &&\n+\ttest_cmp expect actual\n+'\n+test_expect_success 'tag --no-annotate overrides tag.annotate=true config' '\n+\ttest_config tag.annotate true &&\n+\tGIT_EDITOR=false git tag --no-annotate cli-override-tag-annotate &&\n+\ttag_exists cli-override-tag-annotate\n+'\n+\n+get_tag_header config-no-annotate $commit commit $time >expect\n+./fakeeditor >>expect\n+test_expect_success 'tag --annotate overrides tag.annotate=false config' '\n+\ttest_config tag.annotate false &&\n+\tGIT_EDITOR=./fakeeditor git tag --annotate config-no-annotate &&\n+\tget_tag_msg config-no-annotate >actual &&\n+\ttest_cmp expect actual\n+'\n+\n get_tag_header implied-sign $commit commit $time >expect\n ./fakeeditor >>expect\n echo '-----BEGIN PGP SIGNATURE-----' >>expect\n-- \n2.11.0.486.gcc949b6e67.dirty\n\n"},{"id":"310831","messageId":"xmqqlgtm8s5k.fsf@gitster.mtv.corp.google.com","threadId":"45042","inReplyTo":"20170204021402.15927-1-davvid@gmail.com","subject":"Re: [PATCH] tag: add a config option for setting --annotate by default","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-02-04T05:02:47Z","receivedAt":"2017-02-04T05:02:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Aguilar <davvid@gmail.com> writes:\n\n> Make it easier for users to remember to annotate their tags.\n> Allow setting the default value for \"--annotate\" via the \"tag.annotate\"\n> configuration variable.\n>\n> Signed-off-by: David Aguilar <davvid@gmail.com>\n> ---\n\nI do not care too strongly about this, but I need to point out that\nthis will have fallout to tools and scripts.  E.g. if you have this\nconfigured and try to create a new tag in gitk, wouldn't this part\n\n\tif {$msg != {}} {\n\t    exec git tag -a -m $msg $tag $id\n\t} else {\n\t    exec git tag $tag $id\n\t}\n\ntry to open an editor somehow to get the message even when $msg is\nan empty string?  I think the same problem already exists for the\ntag.forceSignAnnotated variable we already have added, though.\n\n> diff --git a/Documentation/config.txt b/Documentation/config.txt\n> index af2ae4cc02..0d562b97e9 100644\n> --- a/Documentation/config.txt\n> +++ b/Documentation/config.txt\n> @@ -2945,6 +2945,11 @@ submodule.alternateErrorStrategy\n>  \tas computed via `submodule.alternateLocation`. Possible values are\n>  \t`ignore`, `info`, `die`. Default is `die`.\n>  \n> +tag.annotate::\n> +\tA boolean to specify whether annotated tags should be created by\n> +\tdefault.  If `--no-annotate` is specified on the command line,\n> +\tit takes precedence over this option.\n> +\n>  tag.forceSignAnnotated::\n>  \tA boolean to specify whether annotated tags created should be GPG signed.\n>  \tIf `--annotate` is specified on the command line, it takes\n"},{"id":"310866","messageId":"20170205041059.k6amkuynvv5o4iyi@gmail.com","threadId":"45042","inReplyTo":"xmqqlgtm8s5k.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] tag: add a config option for setting --annotate by default","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2017-02-05T04:10:59Z","receivedAt":"2017-02-05T04:11:09Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"On Fri, Feb 03, 2017 at 09:02:47PM -0800, Junio C Hamano wrote:\n> David Aguilar <davvid@gmail.com> writes:\n> \n> > Make it easier for users to remember to annotate their tags.\n> > Allow setting the default value for \"--annotate\" via the \"tag.annotate\"\n> > configuration variable.\n> >\n> > Signed-off-by: David Aguilar <davvid@gmail.com>\n> > ---\n> \n> I do not care too strongly about this, but I need to point out that\n> this will have fallout to tools and scripts.  E.g. if you have this\n> configured and try to create a new tag in gitk, wouldn't this part\n> \n> \tif {$msg != {}} {\n> \t    exec git tag -a -m $msg $tag $id\n> \t} else {\n> \t    exec git tag $tag $id\n> \t}\n> \n> try to open an editor somehow to get the message even when $msg is\n> an empty string?  I think the same problem already exists for the\n> tag.forceSignAnnotated variable we already have added, though.\n\nThat's true.  I should have put \"RFC\" in the subject line.\nLet's drop this patch unless there's others that find it useful.\n\nHow do you feel about a patch to add \"git merge --signoff\", for\nconsistency with \"git commit\"?\n\nThe rationale is that there might be situations (evil merges, or\neven regular merges depending on the project) where someone\nmight want to signoff on their merges.\n-- \nDavid\n"}]}