From: David Aguilar <davvid@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH] tag: add a config option for setting --annotate by default
Date: Fri, 3 Feb 2017 18:14:02 -0800 [thread overview]
Message-ID: <20170204021402.15927-1-davvid@gmail.com> (raw)
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 <davvid@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
next reply other threads:[~2017-02-04 2:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-04 2:14 David Aguilar [this message]
2017-02-04 5:02 ` [PATCH] tag: add a config option for setting --annotate by default Junio C Hamano
2017-02-05 4:10 ` David Aguilar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170204021402.15927-1-davvid@gmail.com \
--to=davvid@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).