git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git tag -a HEAD leads to ambiguous branch name

From
Jeff King <peff@peff.net>
Date
Dec 1, 2024, 22:44 UTC
Message-ID
<20241201224408.GJ145938@coredump.intra.peff.net>
In-Reply-To
<xmqqh67ss1a5.fsf@gitster.g>
On Thu, Nov 28, 2024 at 08:30:10AM +0900, Junio C Hamano wrote:
Show 19 quoted lines
> diff --git c/builtin/tag.c w/builtin/tag.c
> index 93d10d5915..c91aba5e26 100644
> --- c/builtin/tag.c
> +++ w/builtin/tag.c
> @@ -449,7 +449,7 @@ static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
>  
>  static int strbuf_check_tag_ref(struct strbuf *sb, const char *name)
>  {
> -	if (name[0] == '-')
> +	if (name[0] == '-' || !strcmp(name, "HEAD"))
>  		return -1;
>  
>  	strbuf_reset(sb);
> 
> but this (together with what "git branch" uses) is unsatisfactory
> for at least two reasons.
> 
>  - This helper function and object-name.c:strbuf_check_branch_ref()
>    should not be named with "strbuf_" prefix. 
Agreed here.
Show 5 quoted lines
>  - The right place to do these checks is check_refname_format(), but
>    it would retroactively forbid porcelains from using HEAD as the
>    name of a branch or a tag (which is technically allowed, but it
>    is dubious anybody wants to do so because it is so cumbersome to
>    use).

But I don't know about this. I thought when we outlawed "git branch HEAD" that it was quite intentional _not_ to forbid these names at the lowest level in order to retain backwards compatibility. They are just about preventing common UI mistakes.

I'm OK with revisiting that decision, but:
  1. I think it's orthogonal to adding a similar UI-level check for
     git-tag.
  2. We'd probably need some deprecation period or breaking-changes
     moment to do the switch.
Show 11 quoted lines
> There is a dubious test in t5604 that expects you can create such a
> tag.  t5604.22 wants to create one:
> 
> test_expect_success 'clone with reference from a tagged repository' '
> 	(
> 		cd A && git tag -a -m tagged HEAD
> 	) &&
> 	git clone --reference=A A I
> '
> 
> and t5604.24 wants to use it.

Weird. Comes from 09116a1c31 (refs: loosen over-strict "format" check, 2011-11-16). I don't see any reason it could not just be "foo".

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 5 in “git tag -a HEAD leads to ambiguous branch name”
  1. git@jowil.deNov 27, 2024
  2. Jeff KingNov 27, 2024
  3. Junio C HamanoNov 27, 2024
  4. Jeff KingDec 1, 2024
  5. Junio C HamanoDec 2, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.