git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: <rsbecker@nexbridge.com>
To: "'Junio C Hamano'" <gitster@pobox.com>,
	"'Git Mailing List'" <git@vger.kernel.org>
Cc: "'M Hickford'" <mirth.hickford@gmail.com>
Subject: RE: Suggestion: error "tag ... already exists" should distinguish between tagging different or same commit:
Date: Mon, 7 Jul 2025 19:12:58 -0400	[thread overview]
Message-ID: <00ca01dbef94$b155f380$1401da80$@nexbridge.com> (raw)
In-Reply-To: <xmqqfrf73ahu.fsf@gitster.g>

On July 7, 2025 6:24 PM, Junio C Hamano wrote:
>Junio C Hamano <gitster@pobox.com> writes:
>
>> Or simply something like this.  I am not convinced (yet) that this is
>> a good idea; I merely is showing that the implementation would look
>> like this.
>>
>> ----- >8 -----
>> Subject: tag: allow idempotent "git tag" without "--force"
>>
>> When "git tag T O" is told to create a tag pointing at an object O
>> without the "--force" option, it refuses with "tag T already exists",
>> even when T points at O (which makes it a no-op).
>>
>> Let's allow this "idempotent" case by special casing.
>>
>> Signed-off-by: Junio C Hamano <gitster@pobox.com>
>> ---
>>  builtin/tag.c  |  2 +-
>>  t/t7004-tag.sh | 12 +++++++++---
>>  2 files changed, 10 insertions(+), 4 deletions(-)
>
>As I see nobody biting, I am inclined to say that this is not such a
brilliant idea.  Let's
>chuck it.
>
>>
>> diff --git c/builtin/tag.c w/builtin/tag.c index
>> 4742b27d16..5380a46494 100644
>> --- c/builtin/tag.c
>> +++ w/builtin/tag.c
>> @@ -660,7 +660,7 @@ int cmd_tag(int argc,
>>
>>  	if (refs_read_ref(get_main_ref_store(the_repository), ref.buf,
&prev))
>>  		oidclr(&prev, the_repository->hash_algo);
>> -	else if (!force)
>> +	else if (!force && (create_tag_object || !oideq(&object, &prev)))
>>  		die(_("tag '%s' already exists"), tag);
>>
>>  	opt.message_given = msg.given || msgfile; diff --git
>> c/t/t7004-tag.sh w/t/t7004-tag.sh index 10835631ca..9a253a44a8 100755
>> --- c/t/t7004-tag.sh
>> +++ w/t/t7004-tag.sh
>> @@ -126,7 +126,7 @@ test_expect_success 'annotated tag with
--create-reflog
>has correct message' '
>>  '
>>
>>  test_expect_success '--create-reflog does not create reflog on failure'
'
>> -	test_must_fail git tag --create-reflog mytag &&
>> +	test_must_fail git tag --create-reflog mytag no-such-object &&
>>  	test_must_fail git reflog exists refs/tags/mytag  '
>>
>> @@ -183,8 +183,14 @@ test_expect_success 'listing tags using a
>> non-matching pattern should output not
>>
>>  # special cases for creating tags:
>>
>> -test_expect_success 'trying to create a tag with the name of one
existing should
>fail' '
>> -	test_must_fail git tag mytag
>> +test_expect_success 'recreating a tag without --force' '
>> +	# light-weight tag pointing at the same thing
>> +	# now succeeds
>> +	git tag mytag HEAD &&
>> +	# light-weight tag pointing at a different thing
>> +	test_must_fail git tag mytag HEAD: &&
>> +	# creating annotated tag, pointing at the same object.
>> +	test_must_fail git tag -a -m anno mytag $taggedobject
>>  '
>>
>>  test_expect_success 'trying to create a tag with a non-valid name should
fail' '

Considering that git tag T O will generally require a git push --force and
always a
git pull --force in order to update tags on the upstream and receiving an
update
to the tag locally, I think requiring git tag --force T O when O is
different from the
current tag is a reasonable idea from a consistency standpoint. I do support
the
notion of git tag T O not requiring a --force if O is already where the tag
is
pointing. The only counter case I can really see in this is when -s is used
to allow
the sign to be updated but even then, does --force really change anything
when
only signing (I think not) because O does not change. If O changes when
signing,
I think that --force is almost essential to avoid messing up the signatures.

--Randall


  reply	other threads:[~2025-07-07 23:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-09  7:00 Suggestion: error "tag ... already exists" should distinguish between tagging different or same commit: M Hickford
2025-06-09 18:42 ` Junio C Hamano
2025-06-09 19:37   ` Hilco Wijbenga
2025-06-09 20:15     ` Andreas Schwab
2025-06-09 20:19     ` Junio C Hamano
2025-06-09 21:03       ` Hilco Wijbenga
2025-06-10  7:00   ` M Hickford
2025-06-10 14:51     ` Junio C Hamano
2025-07-07 22:24       ` Junio C Hamano
2025-07-07 23:12         ` rsbecker [this message]
2025-07-11 19:08           ` Junio C Hamano
2025-07-11 19:10       ` [PATCH] tag: allow idempotent "git tag" without "--force" Junio C Hamano
2025-07-11 20:57         ` Justin Tobler
2025-07-11 21:40           ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='00ca01dbef94$b155f380$1401da80$@nexbridge.com' \
    --to=rsbecker@nexbridge.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=mirth.hickford@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).