From 01dc801adad35d4e2f815dc1918dad057631bc0e Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Thu, 4 Apr 2019 11:25:13 -0700 Subject: tag: fix formatting Wrap usage line at ''. Also, wrap strings with '\n' at the end of string fragments instead of at the beginning of the next string fragment. Convert a space-indent into a tab-indent for style. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- builtin/tag.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/builtin/tag.c b/builtin/tag.c index 02f6bd1279..faae364e0f 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -22,10 +22,11 @@ #include "ref-filter.h" static const char * const git_tag_usage[] = { - N_("git tag [-a | -s | -u ] [-f] [-m | -F ] []"), + N_("git tag [-a | -s | -u ] [-f] [-m | -F ]\n" + "\t\t []"), N_("git tag -d ..."), - N_("git tag -l [-n[]] [--contains ] [--no-contains ] [--points-at ]" - "\n\t\t[--format=] [--[no-]merged []] [...]"), + N_("git tag -l [-n[]] [--contains ] [--no-contains ] [--points-at ]\n" + "\t\t[--format=] [--[no-]merged []] [...]"), N_("git tag -v [--format=] ..."), NULL }; @@ -215,7 +216,7 @@ static void create_tag(const struct object_id *object, const char *tag, type = oid_object_info(the_repository, object, NULL); if (type <= OBJ_NONE) - die(_("bad object type.")); + die(_("bad object type.")); strbuf_addf(&header, "object %s\n" -- cgit v1.2.3 From eea9c1e78ffd878cbaaf2c1e346e186a1e58a460 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Thu, 4 Apr 2019 11:25:15 -0700 Subject: tag: advise on nested tags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Robert Dailey reported confusion on the mailing list about a nested tag which was most likely created by mistake. Jeff King noted that this isn't a very common case and creating a tag-to-a-tag can be a user-error. Suggest that it may be a mistake with an advice message when creating such a tag. Those who do want to create a tag that point at another tag regularly can turn it off with the usual advice mechanism. Reported-by: Robert Dailey Helped-by: Jeff King Helped-by: Ævar Arnfjörð Bjarmason Signed-off-by: Denton Liu [jc: fixed test style and tweaked the log message] Signed-off-by: Junio C Hamano --- Documentation/config/advice.txt | 2 ++ advice.c | 2 ++ advice.h | 1 + builtin/tag.c | 14 ++++++++++++-- t/t7004-tag.sh | 11 +++++++++++ 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Documentation/config/advice.txt b/Documentation/config/advice.txt index 88620429ea..ec4f6ae658 100644 --- a/Documentation/config/advice.txt +++ b/Documentation/config/advice.txt @@ -90,4 +90,6 @@ advice.*:: waitingForEditor:: Print a message to the terminal whenever Git is waiting for editor input from the user. + nestedTag:: + Advice shown if a user attempts to recursively tag a tag object. -- diff --git a/advice.c b/advice.c index 567209aa79..ce5f374ecd 100644 --- a/advice.c +++ b/advice.c @@ -26,6 +26,7 @@ int advice_ignored_hook = 1; int advice_waiting_for_editor = 1; int advice_graft_file_deprecated = 1; int advice_checkout_ambiguous_remote_branch_name = 1; +int advice_nested_tag = 1; static int advice_use_color = -1; static char advice_colors[][COLOR_MAXLEN] = { @@ -81,6 +82,7 @@ static struct { { "waitingForEditor", &advice_waiting_for_editor }, { "graftFileDeprecated", &advice_graft_file_deprecated }, { "checkoutAmbiguousRemoteBranchName", &advice_checkout_ambiguous_remote_branch_name }, + { "nestedTag", &advice_nested_tag }, /* make this an alias for backward compatibility */ { "pushNonFastForward", &advice_push_update_rejected } diff --git a/advice.h b/advice.h index f875f8cd8d..cb5d361614 100644 --- a/advice.h +++ b/advice.h @@ -26,6 +26,7 @@ extern int advice_ignored_hook; extern int advice_waiting_for_editor; extern int advice_graft_file_deprecated; extern int advice_checkout_ambiguous_remote_branch_name; +extern int advice_nested_tag; int git_default_advice_config(const char *var, const char *value); __attribute__((format (printf, 1, 2))) diff --git a/builtin/tag.c b/builtin/tag.c index faae364e0f..32948fade0 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -206,7 +206,14 @@ struct create_tag_options { } cleanup_mode; }; -static void create_tag(const struct object_id *object, const char *tag, +static const char message_advice_nested_tag[] = + N_("You have created a nested tag. The object referred to by your new is\n" + "already a tag. If you meant to tag the object that it points to, use:\n" + "\n" + "\tgit tag -f %s %s^{}"); + +static void create_tag(const struct object_id *object, const char *object_ref, + const char *tag, struct strbuf *buf, struct create_tag_options *opt, struct object_id *prev, struct object_id *result) { @@ -218,6 +225,9 @@ static void create_tag(const struct object_id *object, const char *tag, if (type <= OBJ_NONE) die(_("bad object type.")); + if (type == OBJ_TAG && advice_nested_tag) + advise(_(message_advice_nested_tag), tag, object_ref); + strbuf_addf(&header, "object %s\n" "type %s\n" @@ -551,7 +561,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix) if (create_tag_object) { if (force_sign_annotate && !annotate) opt.sign = 1; - create_tag(&object, tag, &buf, &opt, &prev, &object); + create_tag(&object, object_ref, tag, &buf, &opt, &prev, &object); } transaction = ref_transaction_begin(&err); diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh index 0b01862c23..e285686662 100755 --- a/t/t7004-tag.sh +++ b/t/t7004-tag.sh @@ -1700,6 +1700,17 @@ test_expect_success '--points-at finds annotated tags of tags' ' test_cmp expect actual ' +test_expect_success 'recursive tagging should give advice' ' + sed -e "s/|$//" <<-EOF >expect && + hint: You have created a nested tag. The object referred to by your new is + hint: already a tag. If you meant to tag the object that it points to, use: + hint: | + hint: git tag -f nested annotated-v4.0^{} + EOF + git tag -m nested nested annotated-v4.0 2>actual && + test_i18ncmp expect actual +' + test_expect_success 'multiple --points-at are OR-ed together' ' cat >expect <<-\EOF && v2.0 -- cgit v1.2.3