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

Re: [PATCH v2 1/1] branch: introduce --show-current display option

From
Jeff King <peff@peff.net>
Date
Oct 11, 2018, 00:34 UTC
Message-ID
<20181011003440.GD13853@sigill.intra.peff.net>
In-Reply-To
<20181010205432.11990-2-daniels@umanovskis.se>
On Wed, Oct 10, 2018 at 10:54:32PM +0200, Daniels Umanovskis wrote:
> When called with --show-current, git branch will print the current
> branch name and terminate. Only the actual name gets printed,
> without refs/heads. In detached HEAD state, nothing is output.

I also wondered what happens in an unborn-branch state (i.e., we are on refs/heads/master, but have not yet made any commits).

In that case, resolve_ref_unsafe() will return the branch name, but a null oid. And you'll print that. Which seems sensible.

> Intended both for scripting and interactive/informative use.
> Unlike git branch --list, no filtering is needed to just get the
> branch name.

We should not advertise this to be used for scripting. The git-branch command is porcelain, and we reserve the right to change its output between versions, or based on user config. Fortunately, there is already a blessed way to get this in a script, which is:

  git symbolic-ref [--short] HEAD

I'm not opposed to having "branch --show-current" as a more user-facing alternative for people who want to query the state. I do wonder if people would want it to show extra information, like:

  - if we're detached, from where (like the normal "branch --list"
    shows)
  - are we on an unborn branch
  - are we ahead/behind an upstream (like "branch -v")

I guess that's slowly reinventing the first line of "git status -b". Maybe that's a good thing; possibly this should just be a way to get that data without doing the rest of git-status, and it's perhaps more discoverable since it's part of git-branch. I dunno.

It just seems like in its current form it might be in an uncanny valley where it is not quite scriptable plumbing, but not as informative as other porcelain.

-Peff
Previous: Daniels UmanovskisNext: Rafael Ascensão
Message 3 of 30 in “branch: introduce --show-current display option”
  1. 0/1 branch: introduce --show-current display optionDaniels Umanovskis, Oct 10, 2018
  2. 1/1 branch: introduce --show-current display optionDaniels Umanovskis, Oct 10, 2018
  3. Jeff KingOct 11, 2018
  4. Rafael AscensãoOct 11, 2018
  5. Daniels UmanovskisOct 11, 2018
  6. Jeff KingOct 11, 2018
  7. Rafael AscensãoOct 11, 2018
  8. Daniels UmanovskisOct 11, 2018
  9. Jeff KingOct 11, 2018
  10. Rafael AscensãoOct 11, 2018
  11. Junio C HamanoOct 11, 2018
  12. Daniels UmanovskisOct 11, 2018
  13. Jeff KingOct 11, 2018
  14. branch: introduce --show-current display optionDaniels Umanovskis, Oct 11, 2018
  15. Junio C HamanoOct 11, 2018
  16. Daniels UmanovskisOct 11, 2018
  17. branch: introduce --show-current display optionDaniels Umanovskis, Oct 12, 2018
  18. Eric SunshineOct 12, 2018
  19. Junio C HamanoOct 16, 2018
  20. Eric SunshineOct 16, 2018
  21. Johannes SchindelinOct 17, 2018
  22. Eric SunshineOct 17, 2018
  23. Johannes SchindelinOct 18, 2018
  24. Eric SunshineOct 18, 2018
  25. Junio C HamanoOct 16, 2018
  26. Rafael AscensãoOct 17, 2018
  27. Daniels UmanovskisOct 17, 2018
  28. SZEDER GáborOct 11, 2018
  29. SZEDER GáborOct 11, 2018
  30. Daniels UmanovskisOct 11, 2018

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.