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

Re: [BUG] branch renamed to 'HEAD'

From
Jeff King <peff@peff.net>
Date
Feb 27, 2017, 08:01 UTC
Message-ID
<20170227080158.de2xarctzscfdsp2@sigill.intra.peff.net>
In-Reply-To
<20170227074915.xljfe5jox756rlyv@sigill.intra.peff.net>
On Mon, Feb 27, 2017 at 02:49:15AM -0500, Jeff King wrote:
Show 7 quoted lines
> > >         $ git branch -m -f orig @
> [...]
> 
> Regardless of the original intent, I think it is wrong to convert "@" to
> a branch named "HEAD". I think the bug is in strbuf_check_branch_ref(),
> which blindly sticks "refs/heads/" in front of any value we get from
> interpret_branch_name(), which clearly does not make sense for HEAD.

I do think the bug is in strbuf_check_branch_ref(), but it's hard for it to do a better job. It needs to feed arbitrary expressions into interpret_branch_name() to resolve things like "@{upstream}", "@{-1}", "foo@{upstream}", etc.

The problem is that it expects a branch name to come out of interpret_branch_name(), which _mostly_ happens. The exception is HEAD, which is a "special" name. But the returned value doesn't indicate whether it is special or not.

My first thought was that we might be handling "@" in the wrong place. But it needs to happen here to make things like "@@{upstream}" work (which turns "@" into HEAD, and then finds its upstream).

So I think the options are:
  1. Before calling interpret_branch_name(), strbuf_check_branch_ref()
     checks for "@". I don't like this because it's making assumptions
     about how the result will be parsed and interpreted.
  2. interpret_branch_name() returns a flag that says "this isn't
     _really_ a branch name".
  3. After interpret_branch_name() returns, check whether the result is
     "HEAD".

Doing (2) is the "right" thing in the sense that the "is it a branch" logic remains with the matching parsing code. But we have to surface that value (maybe across recursion via reinterpret?). Since we're unlikely to ever grow a return value that matches this case except "HEAD", it might be simplest to just do (3).

-Peff
Previous: Jeff KingNext: Jeff King
Message 5 of 14 in “[BUG] branch renamed to 'HEAD'”
  1. Luc Van OostenryckFeb 27, 2017
  2. Karthik NayakFeb 27, 2017
  3. Luc Van OostenryckFeb 27, 2017
  4. Jeff KingFeb 27, 2017
  5. Jeff KingFeb 27, 2017
  6. Jeff KingFeb 27, 2017
  7. Luc Van OostenryckFeb 27, 2017
  8. Junio C HamanoFeb 27, 2017
  9. Jeff KingFeb 28, 2017
  10. Jacob KellerFeb 27, 2017
  11. Junio C HamanoFeb 28, 2017
  12. Jeff KingFeb 28, 2017
  13. Jacob KellerFeb 28, 2017
  14. Jeff KingFeb 28, 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.