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

Re: [PATCH 0/2] branch: introduce --current display option

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 9, 2018, 20:59 UTC
Message-ID
<xmqq8t36q1k6.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20181009182006.9446-1-daniels@umanovskis.se>
Daniels Umanovskis <daniels@umanovskis.se> writes:
> I often find myself needing the current branch name, for which
> currently there's git rev-parse --abrev-ref HEAD. I would expect
> `git branch` to have an option to output the branch name instead.
[jc:  wrapped an overlong line]

If "git branch" had many operations that work on multiple branches by default, and we were adding an option to work on a single branch that is currently checked out, then I would find "--current" is a very good name for an option that turns all these operations to work only on the one that is currently checked out.

But I do not think that is what is going on. There is "--list" that lists branches whose name match given patterns, and at the end-user level (I haven't seen the implementation) this is another mode of that operation that limits itself to the one that is currently checked out, and you do not even allowed to give the "--list" option explicitly so that in the future when "git branch" learns to perform an operation other than "list" (let's call it 'distim') to bunch of branches by default, you cannot say "git --distim --current" to limit the distimming to the branch that you are currently on.

I do not offhand know if we want "show the current one only" option that is "command mode" sitting next to "list", "delete", "rename" etc., or "limit the operation to the one that is currently cheked out". If we want the former, the name of the option must *NOT* be just "current". Have a verb in its name to avoid it from getting mistaken as a botched attempt to do the latter. Somethng like "--show-current", "--list-current", "--display-current", etc.

Even if we were doing the latter (i.e. focused "this is only for listing/showing"), if we do not want to close the door to later extend the concept of "current" to the former (i.e. "--show-current" becomes a convenience synonym for "--list --current-only") we also need to think about what to do with the detached HEAD state. When the concept of "current" is extended to become "usually an operation can work on multiple branches but we are limiting it to the current one", detached HEAD state is conceptually "not having any current branch". We could fail the operation (i.e. you told me to distim the branch but there is no such branch) or make it a silent no-op (i.e. you told me to distim no branch, so nothing happened and there is no error).

My inclination is to recommend to:
 (1) name the "show the current one" not "--current" but with some
     verb
 (2) display nothing when there is no current branch (i.e. detached
     HEAD) and without any error.
Previous: Daniels UmanovskisNext: Eric Sunshine
Message 2 of 9 in “branch: introduce --current display option”
  1. 0/2 branch: introduce --current display optionDaniels Umanovskis, Oct 9, 2018
  2. Junio C HamanoOct 9, 2018
  3. Eric SunshineOct 10, 2018
  4. Eric SunshineOct 10, 2018
  5. Rafael AscensãoOct 10, 2018
  6. brian m. carlsonOct 10, 2018
  7. Ævar Arnfjörð BjarmasonOct 10, 2018
  8. Daniels UmanovskisOct 10, 2018
  9. Stefan BellerOct 10, 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.