Skip to content

Commit 943ad3c

Browse files
committed
Merge branch 'jc/tag-idempotent-no-op' into seen
* jc/tag-idempotent-no-op: tag: allow idempotent "git tag" without "--force"
2 parents f2e371f + f854093 commit 943ad3c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

builtin/tag.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,8 @@ int cmd_tag(int argc,
660660

661661
if (refs_read_ref(get_main_ref_store(the_repository), ref.buf, &prev))
662662
oidclr(&prev, the_repository->hash_algo);
663+
else if (!create_tag_object && oideq(&object, &prev))
664+
exit(0);
663665
else if (!force)
664666
die(_("tag '%s' already exists"), tag);
665667

t/t7004-tag.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ test_expect_success 'annotated tag with --create-reflog has correct message' '
126126
'
127127

128128
test_expect_success '--create-reflog does not create reflog on failure' '
129-
test_must_fail git tag --create-reflog mytag &&
129+
test_must_fail git tag --create-reflog mytag no-such-object &&
130130
test_must_fail git reflog exists refs/tags/mytag
131131
'
132132

@@ -183,8 +183,14 @@ test_expect_success 'listing tags using a non-matching pattern should output not
183183

184184
# special cases for creating tags:
185185

186-
test_expect_success 'trying to create a tag with the name of one existing should fail' '
187-
test_must_fail git tag mytag
186+
test_expect_success 'recreating a tag without --force' '
187+
# light-weight tag pointing at the same thing
188+
# now succeeds
189+
git tag mytag HEAD &&
190+
# light-weight tag pointing at a different thing
191+
test_must_fail git tag mytag HEAD: &&
192+
# creating annotated tag, pointing at the same object.
193+
test_must_fail git tag -a -m anno mytag $taggedobject
188194
'
189195

190196
test_expect_success 'trying to create a tag with a non-valid name should fail' '

0 commit comments

Comments
 (0)