Skip to content

Commit 9e72a56

Browse files
committed
Merge branch 'ph/tag-force-no-warn-on-creation' into maint
"git tag -f <tag>" always said "Updated tag '<tag>'" even when creating a new tag (i.e. not overwriting nor updating). * ph/tag-force-no-warn-on-creation: tag: --force does not have to warn when creating tags
2 parents fa0a6a4 + 3ae851e commit 9e72a56

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

builtin/tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
582582
die(_("%s: cannot lock the ref"), ref.buf);
583583
if (write_ref_sha1(lock, object, NULL) < 0)
584584
die(_("%s: cannot update the ref"), ref.buf);
585-
if (force && hashcmp(prev, object))
585+
if (force && !is_null_sha1(prev) && hashcmp(prev, object))
586586
printf(_("Updated tag '%s' (was %s)\n"), tag, find_unique_abbrev(prev, DEFAULT_ABBREV));
587587

588588
strbuf_release(&buf);

t/t7004-tag.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ test_expect_success 'creating a tag using HEAD directly should succeed' '
104104
tag_exists myhead
105105
'
106106

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+
107119
# deleting tags:
108120

109121
test_expect_success 'trying to delete an unknown tag should fail' '

0 commit comments

Comments
 (0)