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

Re: [RFC PATCH] object-name: add @{upstreamhead} shorthand

From
Taylor Blau <me@ttaylorr.com>
Date
Oct 27, 2024, 23:45 UTC
Message-ID
<Zx7QkaQ5IKxQFskK@nand.local>
In-Reply-To
<D56XI8GBH2GF.3MP02MGQGP5M@ferdinandy.com>
On Sun, Oct 27, 2024 at 11:07:07PM +0100, Bence Ferdinandy wrote:
Show 24 quoted lines
>
> On Fri Oct 25, 2024 at 08:24, Jeff King <peff@peff.net> wrote:
> > On Thu, Oct 24, 2024 at 08:48:29PM +0200, Bence Ferdinandy wrote:
> >
> >> > So I think rather than "branch --show-current-remote", we'd want
> >> > some option to make "branch --list" show only the currently checked out
> >> > branch, and then you could apply --format to it to get whatever
> >> > information you wanted. Something like:
> >> >
> >> >   git branch --list --is-head --format='%(upstream:remotename)'
> >>
> >> Thanks for running through this in such detail! This would be more widely
> >> useful for sure.
> >>
> >> I'd probably call the flag something like "--current", "--current-only" rather
> >> than "--is-head" though. "--is-head" sounds as if it would filter --list but
> >> not necessarily end up with a single entry.
> >
> > Yeah, I think --current would be fine.
>
> I was looking through git branch and there is a --show-current option. I was
> wondering, would it not be better to teach --show-current to also obey
> --format? It would avoid having a "--current" that only works with "--list"
> besides having a "--show-current".

Yeah, I think that supporting '--format' specifiers via 'git branch --show-current' makes sense.

In the interim you could do something gross like:
    git branch --list --format='%(upstream:remotename)' \
      --end-of-options "$(git branch --show-current)"
, but... yuck :-).

I think the right thing to do would be to teach 'git branch --show-current' to support the full range of --format specifiers. And I think the way to do that would be to treat --show-current as a special case of --list.

In the existing implementation, we special-case handling the current branch with --show-current via a separate code path in builtin/branch.c::show_current_branch_name().

It would be nice to change the implementation there to pretend as if the current branch as the pattern given to --list instead of handling printing it out separately.

I think that would be a nice small-ish project for anybody looking to get their hands dirty in the 'branch' builtin's implementation.

Thanks, Taylor

Previous: Bence FerdinandyNext: Jeff King
Message 11 of 14 in “object-name: add @{upstreamhead} shorthand”
  1. object-name: add @{upstreamhead} shorthandBence Ferdinandy, Oct 20, 2024
  2. Kristoffer HaugsbakkOct 20, 2024
  3. Bence FerdinandyOct 20, 2024
  4. Jeff KingOct 21, 2024
  5. Bence FerdinandyOct 21, 2024
  6. Taylor BlauOct 21, 2024
  7. Jeff KingOct 23, 2024
  8. Bence FerdinandyOct 24, 2024
  9. Jeff KingOct 25, 2024
  10. Bence FerdinandyOct 27, 2024
  11. Taylor BlauOct 27, 2024
  12. Jeff KingOct 28, 2024
  13. Taylor BlauOct 21, 2024
  14. Bence FerdinandyOct 21, 2024

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.