Make it easier for users to remember to annotate their tags.
Allow setting the default value for "--annotate" via the "tag.annotate"
configuration variable.

Signed-off-by: David Aguilar <dav...@gmail.com>
---
 Documentation/config.txt |  5 +++++
 builtin/tag.c            | 15 ++++++++++++---
 t/t7004-tag.sh           | 23 +++++++++++++++++++++++
 3 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index af2ae4cc02..0d562b97e9 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2945,6 +2945,11 @@ submodule.alternateErrorStrategy
        as computed via `submodule.alternateLocation`. Possible values are
        `ignore`, `info`, `die`. Default is `die`.
 
+tag.annotate::
+       A boolean to specify whether annotated tags should be created by
+       default.  If `--no-annotate` is specified on the command line,
+       it takes precedence over this option.
+
 tag.forceSignAnnotated::
        A boolean to specify whether annotated tags created should be GPG 
signed.
        If `--annotate` is specified on the command line, it takes
diff --git a/builtin/tag.c b/builtin/tag.c
index 73df728114..1cf9bb73ad 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -29,6 +29,7 @@ static const char * const git_tag_usage[] = {
 };
 
 static unsigned int colopts;
+static int force_annotate;
 static int force_sign_annotate;
 
 static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, 
const char *format)
@@ -161,6 +162,10 @@ static int git_tag_config(const char *var, const char 
*value, void *cb)
        status = git_gpg_config(var, value, cb);
        if (status)
                return status;
+       if (!strcmp(var, "tag.annotate")) {
+               force_annotate = git_config_bool(var, value);
+               return 0;
+       }
        if (!strcmp(var, "tag.forcesignannotated")) {
                force_sign_annotate = git_config_bool(var, value);
                return 0;
@@ -326,7 +331,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
        struct create_tag_options opt;
        char *cleanup_arg = NULL;
        int create_reflog = 0;
-       int annotate = 0, force = 0;
+       int annotate = -1, force = 0;
        int cmdmode = 0, create_tag_object = 0;
        const char *msgfile = NULL, *keyid = NULL;
        struct msg_arg msg = { 0, STRBUF_INIT };
@@ -387,11 +392,15 @@ int cmd_tag(int argc, const char **argv, const char 
*prefix)
                opt.sign = 1;
                set_signing_key(keyid);
        }
-       create_tag_object = (opt.sign || annotate || msg.given || msgfile);
 
        if (argc == 0 && !cmdmode)
                cmdmode = 'l';
 
+       if (force_annotate && !cmdmode && annotate == -1)
+               annotate = 1;
+
+       create_tag_object = (opt.sign || annotate > 0 || msg.given || msgfile);
+
        if ((create_tag_object || force) && (cmdmode != 0))
                usage_with_options(git_tag_usage, options);
 
@@ -478,7 +487,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
                die(_("Invalid cleanup mode %s"), cleanup_arg);
 
        if (create_tag_object) {
-               if (force_sign_annotate && !annotate)
+               if (force_sign_annotate && annotate == -1)
                        opt.sign = 1;
                create_tag(object, tag, &buf, &opt, prev, object);
        }
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index 1cfa8a21d2..5ba52b57dd 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -754,6 +754,29 @@ echo from a fake editor.
 EOF
 chmod +x fakeeditor
 
+get_tag_header config-annotate $commit commit $time >expect
+./fakeeditor >>expect
+test_expect_success 'tag.annotate creates annotated tags' '
+       test_config tag.annotate true &&
+       GIT_EDITOR=./fakeeditor git tag config-annotate &&
+       get_tag_msg config-annotate >actual &&
+       test_cmp expect actual
+'
+test_expect_success 'tag --no-annotate overrides tag.annotate=true config' '
+       test_config tag.annotate true &&
+       GIT_EDITOR=false git tag --no-annotate cli-override-tag-annotate &&
+       tag_exists cli-override-tag-annotate
+'
+
+get_tag_header config-no-annotate $commit commit $time >expect
+./fakeeditor >>expect
+test_expect_success 'tag --annotate overrides tag.annotate=false config' '
+       test_config tag.annotate false &&
+       GIT_EDITOR=./fakeeditor git tag --annotate config-no-annotate &&
+       get_tag_msg config-no-annotate >actual &&
+       test_cmp expect actual
+'
+
 get_tag_header implied-sign $commit commit $time >expect
 ./fakeeditor >>expect
 echo '-----BEGIN PGP SIGNATURE-----' >>expect
-- 
2.11.0.486.gcc949b6e67.dirty

Reply via email to