Web lists-archives.com

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

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"

  - 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.