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

Re: [PATCH 3/3] branch: forbid refs/heads/HEAD

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 21, 2017, 08:57 UTC
Message-ID
<xmqqpo9gg9pa.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1508561424.2516.19.camel@gmail.com>
Kaartic Sivaraam <kaartic.sivaraam@gmail.com> writes:
Show 8 quoted lines
>> The only difference is improved tests where we use show-ref to make
>> sure refs/heads/HEAD does not exist when it shouldn't, exercise
>> update-ref to create and delete refs/heads/HEAD, and also make sure
>> it can be deleted with "git branch -d".
>
> In which case you might also like to ensure that it's possible to
> "rename" the branch with a name "HEAD" to recover from historical
> mistakes.

Perhaps. I didn't think it was all that needed---as long as you can delete, you can recreate at the same commit with a more desirable name, and it is not like users have tons of repositories with misnamed branches that they need to fix. The code may already handle it, or there may need even more code to support the rename; I didn't check.

Show 9 quoted lines
>>  int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
>>  {
>>  	strbuf_branchname(sb, name, INTERPRET_BRANCH_LOCAL);
>> -	if (name[0] == '-')
>> +	if (*name == '-' || !strcmp(name, "HEAD"))
>>  		return -1;
>
> I guess this makes the check for "HEAD" in builtin/branch::cmd_branch()
>  (line 796) redundant. May be it could be removed?

Perhaps. But I think that is better done as a follow-up "now the lower level consistently handles, let's remove the extra check that has become unnecessary" separate patch.

Show 7 quoted lines
> So, may be the following test could also be added (untested yet),
>
> test_expect_success 'branch -m can rename refs/heads/HEAD' '
> 	git update-ref refs/heads/HEAD HEAD^ &&
> 	git branch -m HEAD head &&
> 	test_must_fail git show-ref refs/heads/HEAD
> '

Yeah, that would be a good material for that separate follow-up patch.

Thanks.
Previous: Kaartic SivaraamNext: Kaartic Sivaraam
Message 13 of 26 in “a small branch API clean-up”
  1. 0/3 a small branch API clean-upJunio C Hamano, Oct 13, 2017
  2. 2/3 branch: split validate_new_branchname() into twoJunio C Hamano, Oct 13, 2017
  3. Kaartic SivaraamOct 21, 2017
  4. Junio C HamanoOct 21, 2017
  5. 1/3 branch: streamline "attr_only" handling in validate_new_branchname()Junio C Hamano, Oct 13, 2017
  6. Eric SunshineOct 13, 2017
  7. 3/3 branch: forbid refs/heads/HEADJunio C Hamano, Oct 13, 2017
  8. Jeff KingOct 13, 2017
  9. Junio C HamanoOct 14, 2017
  10. Junio C HamanoOct 14, 2017
  11. Jeff KingOct 16, 2017
  12. Kaartic SivaraamOct 21, 2017
  13. Junio C HamanoOct 21, 2017
  14. Kaartic SivaraamOct 22, 2017
  15. Kaartic SivaraamOct 21, 2017
  16. Junio C HamanoOct 21, 2017
  17. Kaartic SivaraamOct 22, 2017
  18. 1/2 branch: forbid refs/heads/HEADKaartic Sivaraam, Nov 14, 2017
  19. 2/2 builtin/branch: remove redundant check for HEADKaartic Sivaraam, Nov 14, 2017
  20. Kaartic SivaraamNov 14, 2017
  21. Junio C HamanoNov 14, 2017
  22. Kaartic SivaraamNov 15, 2017
  23. 3/4 branch: correctly reject refs/heads/{-dash,HEAD}Junio C Hamano, Nov 15, 2017
  24. Kaartic SivaraamNov 16, 2017
  25. Junio C HamanoNov 16, 2017
  26. Kaartic SivaraamNov 16, 2017

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.