Skip to content

Commit

Permalink
tag: --force does not have to warn when creating tags
Browse files Browse the repository at this point in the history
"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>
  • Loading branch information
Phil Hord authored and Junio C Hamano committed Mar 13, 2013
1 parent 03a0fb0 commit 3ae851e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion builtin/tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
die(_("%s: cannot lock the ref"), ref.buf);
if (write_ref_sha1(lock, object, NULL) < 0)
die(_("%s: cannot update the ref"), ref.buf);
if (force && hashcmp(prev, object))
if (force && !is_null_sha1(prev) && hashcmp(prev, object))
printf(_("Updated tag '%s' (was %s)\n"), tag, find_unique_abbrev(prev, DEFAULT_ABBREV));

strbuf_release(&buf);
Expand Down
12 changes: 12 additions & 0 deletions t/t7004-tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ test_expect_success 'creating a tag using HEAD directly should succeed' '
tag_exists myhead
'

test_expect_success '--force can create a tag with the name of one existing' '
tag_exists mytag &&
git tag --force mytag &&
tag_exists mytag'

test_expect_success '--force is moot with a non-existing tag name' '
git tag newtag >expect &&
git tag --force forcetag >actual &&
test_cmp expect actual
'
git tag -d newtag forcetag

# deleting tags:

test_expect_success 'trying to delete an unknown tag should fail' '
Expand Down

0 comments on commit 3ae851e

Please sign in to comment.