tag: --force does not have to warn when creating tags
"git tag --force" mentions what old tag object is being replaced when it is used to update an existing tag, but it shows the same message when creating a new one. Stop doing that, as it does not add any information. Add a test for this and also to ensure --force can replace tags at all. Signed-off-by: Phil Hord <hordp@cisco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Phil Hord committed
Mar 12, 2013 at 19:13 UTC
3ae851e6fbb4e99fa7281d18a5c6f95a3fb6d998
2 files changed
+13
-1
builtin/tag.c
+1
-1
@@ -584,7 +584,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
584
die(_("%s: cannot lock the ref"), ref.buf);
585
if (write_ref_sha1(lock, object, NULL) < 0)
586
die(_("%s: cannot update the ref"), ref.buf);
587
- if (force && hashcmp(prev, object))
587
+ if (force && !is_null_sha1(prev) && hashcmp(prev, object))
588
printf(_("Updated tag '%s' (was %s)\n"), tag, find_unique_abbrev(prev, DEFAULT_ABBREV));
589
590
strbuf_release(&buf);
t/t7004-tag.sh
+12
@@ -104,6 +104,18 @@ test_expect_success 'creating a tag using HEAD directly should succeed' '
104
tag_exists myhead
105
'
106
107
+test_expect_success '--force can create a tag with the name of one existing' '
108
+ tag_exists mytag &&
109
+ git tag --force mytag &&
110
+ tag_exists mytag'
111
+
112
+test_expect_success '--force is moot with a non-existing tag name' '
113
+ git tag newtag >expect &&
114
+ git tag --force forcetag >actual &&
115
+ test_cmp expect actual
116
+'
117
+git tag -d newtag forcetag
118
+
119
# deleting tags:
120
121
test_expect_success 'trying to delete an unknown tag should fail' '