Skip to content

Commit 3ae851e

Browse files
phordgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 03a0fb0 commit 3ae851e

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
@@ -584,7 +584,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
584584
die(_("%s: cannot lock the ref"), ref.buf);
585585
if (write_ref_sha1(lock, object, NULL) < 0)
586586
die(_("%s: cannot update the ref"), ref.buf);
587-
if (force && hashcmp(prev, object))
587+
if (force && !is_null_sha1(prev) && hashcmp(prev, object))
588588
printf(_("Updated tag '%s' (was %s)\n"), tag, find_unique_abbrev(prev, DEFAULT_ABBREV));
589589

590590
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)