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

Re: [PATCH] builtin-branch - allow deleting a fully specified branch-name

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 10, 2009, 03:18 UTC
Message-ID
<7vbpr519jq.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<200904092119.10520.mlevedahl@gmail.com>
Mark Levedahl <mlevedahl@gmail.com> writes:
Show 17 quoted lines
> On Thursday 09 April 2009 20:39:46 Junio C Hamano wrote:
>> Mark Levedahl <mlevedahl@gmail.com> writes:
>> > This change allows, for instance
>> > 	git branch -d refs/heads/foo
>> > to succeed. Without this patch, the code just assumes that the
>> > given branch name should be appended to "refs/heads" or
>> > "refs/remotes", thus attempting (and failing) in the above case
>> > to delete "refs/heads/refs/heads/foo"
>>
>> Your logic is broken.
>>
>> Why doesn't the user simply say "git branch -d foo"?  The command takes
>> "the branch name", not "arbitrary ref name".
>
> 1) git branch -d refs/<whatever> used to work,  I haven't bisected to find 
> when this stopped working, but the change broke one of my scripts, so this is 
> not new behavior, it is restoration of previous behavior.
I need to look at the history, if that is the case then perhaps Ok.
> 2) If I create branch  refs/frotz/bar , how do I ever delete it?

By this you must mean .git/refs/heads/refs/frotz/bar, right? Then shouldn't "git branch -d refs/frotz/bar" just work as is? If you are talking about .git/refs/frotz/bar, "git branch" should not touch it, it is not even a branch.

> Also, the following all work
> 3) git branch refs/heads/foo
> 4) git branch -m refs/heads/foo refs/heads/bar 

If you mean it creates .git/refs/heads/refs/heads/foo, then sure it should. If it creates .git/refs/heads/foo, I think it is broken.

> 5) git  [checkout|pull|push|fetch|show] refs/heads/foo

Among these, checkout is the only special case that can take "branch name" to switch branches. Everything else takes extended SHA-1 expression. Checkout can interpret the first argument as "branch to switch to", but it does not necessarily so---think "detached HEAD", and also think "checking out paths out of tree-ish".

> So, why is "git branch -d" so special?

"git branch -d", "git branch -m" and friends all take branch name, and as such it can use "@{-1}" to _name_ 'the previous branch". In that context, you are _not_ naming the commit at the tip of the branch. You are naming the branch itself.

All other commands happen to take a branch name because that is just one case of extended SHA-1 expression to name an object. In that context, a refname (which a branch name is a special case of) refers to the commit pointed by it. E.g.

        "git checkout HEAD~20 -- Makefile"
        "git show refs/heads/foo"
        "git show heads/foo"
        "git show foo"
Previous: Mark LevedahlNext: Mark Levedahl
Message 4 of 24 in “builtin-branch - allow deleting a fully specified branch-name”
  1. builtin-branch - allow deleting a fully specified branch-nameMark Levedahl, Apr 10, 2009
  2. Junio C HamanoApr 10, 2009
  3. Mark LevedahlApr 10, 2009
  4. Junio C HamanoApr 10, 2009
  5. Mark LevedahlApr 11, 2009
  6. Jeff KingApr 12, 2009
  7. Junio C HamanoApr 12, 2009
  8. Jeff KingApr 13, 2009
  9. Junio C HamanoApr 13, 2009
  10. Jeff KingApr 13, 2009
  11. 1/5 doc: clarify --no-track optionJeff King, Apr 13, 2009
  12. 2/5 doc: refer to tracking configuration as "upstream"Jeff King, Apr 13, 2009
  13. 3/5 doc/checkout: refer to git-branch(1) as appropriateJeff King, Apr 13, 2009
  14. 4/5 doc/checkout: split checkout and branch creation in synopsisJeff King, Apr 13, 2009
  15. 5/5 docs/checkout: clarify what "non-branch" meansJeff King, Apr 13, 2009
  16. Junio C HamanoApr 13, 2009
  17. Mark LevedahlApr 14, 2009
  18. Junio C HamanoApr 14, 2009
  19. Jakub NarebskiApr 14, 2009
  20. Jeff KingApr 15, 2009
  21. Jeff KingApr 15, 2009
  22. Jeff KingApr 13, 2009
  23. Jeff KingApr 13, 2009
  24. Sverre RabbelierApr 13, 2009

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.