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

Re: [BUG] branch renamed to 'HEAD'

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 28, 2017, 00:33 UTC
Message-ID
<xmqqzih7kvbz.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<CA+P7+xpVt6NtSajqMX8OQ_SKdC9tfHH40JgK=9DgBxo9nMaWLA@mail.gmail.com>
Jacob Keller <jacob.keller@gmail.com> writes:
> What about changing interpret-branch-name gains a flag to return a
> fully qualified ref rather than returning just the name? That seems
> like it would be more reasonable behavior.

There are two kinds of callers to i-b-n. The ones that want a local branch name because they are parsing special places on the command line that using a local branch name makes difference (as opposed to using any extended SHA-1 expression), like "git checkout master" (which means different thing from "git checkout master^0"). And the ones that can use any object name.

It depends on how your flag works, but if it means "add refs/heads/ when you got a local branch name", then that would not work well for the former callers, as end-user inputs @{-1} and refs/heads/master would become indistinguishable. The former is expanded to 'master' (if you were on that branch) and ends up being refs/heads/master. "git checkout refs/heads/master" would be (unless you have a branch with that name, i.e. refs/heads/refs/heads/master) a request to detach HEAD at the commit, but the user wanted to be on the previous branch. And the latter iclass of callers are probably already happy with or without the flag, so they won't be helped, either.

A flag to affect the behaviour (as opposed to &flag as a secondary return value, like Peff's patch does) can be made to work. Perhaps a flag that says "keep the input as is if the result is not a local branch name" would pass an input "@" intact and that may be sufficient to allow "git branch -m @" to rename the current branch to "@" (I do not think it is a sensible rename, though ;-). But probably some callers need to keep the original input and compare with the result to see if we expanded anything if we go that route. At that point, I am not sure if there are much differences in the ease of use between the two approaches.

Previous: Jacob KellerNext: Jeff King
Message 11 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.