git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Feature request: highlight local worktree in `worktree list`
@ 2024-03-20  8:00 Matt Hickford
  2024-03-20 10:02 ` Jeff King
  2024-03-20 22:24 ` Rubén Justo
  0 siblings, 2 replies; 7+ messages in thread
From: Matt Hickford @ 2024-03-20  8:00 UTC (permalink / raw
  To: Git Mailing List

Hi. `git branch` lists branches. It highlights the current branch with
an asterisk and (for me) the colour green. This is handy for quick
reading.

`git worktree list` lists worktrees. It would be neat to highlight the
local worktree.

Another idea: `git branch -v` shows the commit subject and
ahead/behind counts for each branch, eg. "[ahead 1, behind 1] avoid
RegexReplace". It would be neat for `git worktree list -v` (or
similar) to show the commit subject and ahead/behind counts.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Feature request: highlight local worktree in `worktree list`
  2024-03-20  8:00 Feature request: highlight local worktree in `worktree list` Matt Hickford
@ 2024-03-20 10:02 ` Jeff King
  2024-03-20 14:38   ` Junio C Hamano
  2024-03-21 13:00   ` Matt Hickford
  2024-03-20 22:24 ` Rubén Justo
  1 sibling, 2 replies; 7+ messages in thread
From: Jeff King @ 2024-03-20 10:02 UTC (permalink / raw
  To: Matt Hickford; +Cc: Git Mailing List

On Wed, Mar 20, 2024 at 08:00:00AM +0000, Matt Hickford wrote:

> Hi. `git branch` lists branches. It highlights the current branch with
> an asterisk and (for me) the colour green. This is handy for quick
> reading.
> 
> `git worktree list` lists worktrees. It would be neat to highlight the
> local worktree.
> 
> Another idea: `git branch -v` shows the commit subject and
> ahead/behind counts for each branch, eg. "[ahead 1, behind 1] avoid
> RegexReplace". It would be neat for `git worktree list -v` (or
> similar) to show the commit subject and ahead/behind counts.

I'm not sure if this is a dumb idea or not, but: what if git-branch
learned to display branches associated with worktrees (just like "-r"
lists remote branches, etc).

Then you'd get the all of the display niceties you want, along with
other features like sorting, limiting by merge, etc. You can even show
the worktree paths with a custom format that uses %(worktreepath).

I think the only thing it wouldn't do is show worktrees that are
detached from any branch at all. I'm not sure if that's important to
your workflow or not.

-Peff


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Feature request: highlight local worktree in `worktree list`
  2024-03-20 10:02 ` Jeff King
@ 2024-03-20 14:38   ` Junio C Hamano
  2024-03-20 20:39     ` Jeff King
  2024-03-21 13:00   ` Matt Hickford
  1 sibling, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2024-03-20 14:38 UTC (permalink / raw
  To: Jeff King; +Cc: Matt Hickford, Git Mailing List

Jeff King <peff@peff.net> writes:

> I'm not sure if this is a dumb idea or not, but: what if git-branch
> learned to display branches associated with worktrees (just like "-r"
> lists remote branches, etc).

A branch usually, but not necessarily, is checked out in at most one
worktree, so the display may become a bit more cluttered when more
than one checks out the same branch, but it is similar to how a commit
pointed at by multiple refs are shown with --decorate, so I do not think
it is such a huge deal.

> I think the only thing it wouldn't do is show worktrees that are
> detached from any branch at all. I'm not sure if that's important to
> your workflow or not.

If such a mode in "git branch --list" were written, I would imagine
that the output from such a mode will include detached HEAD from
other worktrees as well.  Perhaps something like this?

    $ git branch --list --worktrees
      (HEAD detached from ffa877cd2f, checked out in worktree 'buildtest')
      jch (checked out in worktree 'integration')
      maint
    * master (checked out in the primary worktree)
      next
      seen
      jk/branch-list-with-worktree



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Feature request: highlight local worktree in `worktree list`
  2024-03-20 14:38   ` Junio C Hamano
@ 2024-03-20 20:39     ` Jeff King
  0 siblings, 0 replies; 7+ messages in thread
From: Jeff King @ 2024-03-20 20:39 UTC (permalink / raw
  To: Junio C Hamano; +Cc: Matt Hickford, Git Mailing List

On Wed, Mar 20, 2024 at 07:38:57AM -0700, Junio C Hamano wrote:

> > I think the only thing it wouldn't do is show worktrees that are
> > detached from any branch at all. I'm not sure if that's important to
> > your workflow or not.
> 
> If such a mode in "git branch --list" were written, I would imagine
> that the output from such a mode will include detached HEAD from
> other worktrees as well.  Perhaps something like this?

Good point. I was thinking it only iterated on refs, but of course we
already show a detached HEAD in the main worktree.

-Peff


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Feature request: highlight local worktree in `worktree list`
  2024-03-20  8:00 Feature request: highlight local worktree in `worktree list` Matt Hickford
  2024-03-20 10:02 ` Jeff King
@ 2024-03-20 22:24 ` Rubén Justo
  2024-03-21  0:53   ` Chris Torek
  1 sibling, 1 reply; 7+ messages in thread
From: Rubén Justo @ 2024-03-20 22:24 UTC (permalink / raw
  To: Matt Hickford, Git Mailing List; +Cc: Jeff King, Junio C Hamano

On Wed, Mar 20, 2024 at 08:00:00 +0000, Matt Hickford wrote:
> Hi. `git branch` lists branches. It highlights the current branch with
> an asterisk and (for me) the colour green. This is handy for quick
> reading.
>
> `git worktree list` lists worktrees. It would be neat to highlight the
> local worktree.
>
> Another idea: `git branch -v` shows the commit subject and
> ahead/behind counts for each branch, eg. "[ahead 1, behind 1] avoid
> RegexReplace". It would be neat for `git worktree list -v` (or
> similar) to show the commit subject and ahead/behind counts.

Both ideas sound good.  And so do what Peff has suggested.

I want to point out that maybe "git branch [--list] -v -v" has gone
unnoticed.  It does not fully meet the expectations expressed in this
thread, but perhaps it can be of some help:

    $ git init -b foo /tmp/main
    Initialized empty Git repository in /tmp/main/.git/
    $ cd /tmp/main
    $ git commit --allow-empty -m test
    [foo (root-commit) 87382f1] test
    $ git worktree add ../wt
    Preparing worktree (new branch 'wt')
    HEAD is now at 87382f1 test
    $ git branch --set-upstream-to=wt
    Branch 'foo' set up to track local branch 'wt'.
    $ cd /tmp/wt
    $ git branch -v -v
    + foo 87382f1 (/tmp/main) [wt] test
    * wt  87382f1 test
    $ git commit --allow-empty -m test_2
    [wt df39c54] test_2
    $ git branch -v -v
    + foo 87382f1 (/tmp/main) [wt: behind 1] test
    * wt  df39c54 test_2

"git branch --list" has a much richer machinery than "git worktree list".
Perhaps the display machinery of both commands can converge in some way.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Feature request: highlight local worktree in `worktree list`
  2024-03-20 22:24 ` Rubén Justo
@ 2024-03-21  0:53   ` Chris Torek
  0 siblings, 0 replies; 7+ messages in thread
From: Chris Torek @ 2024-03-21  0:53 UTC (permalink / raw
  To: Rubén Justo
  Cc: Matt Hickford, Git Mailing List, Jeff King, Junio C Hamano

On Wed, Mar 20, 2024 at 3:24 PM Rubén Justo <rjusto@gmail.com> wrote:
> "git branch --list" has a much richer machinery than "git worktree list".
> Perhaps the display machinery of both commands can converge in some way.

I have no concrete suggestions for such, but I will note that there is a
`git for-each-ref` plumbing command for refs, but no `git for-each-worktree`
plumbing command for worktrees.  Given the relationship here (each
worktree has a worktree-specific set of refs), perhaps that's a point
of leverage, as it were?

Chris


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Feature request: highlight local worktree in `worktree list`
  2024-03-20 10:02 ` Jeff King
  2024-03-20 14:38   ` Junio C Hamano
@ 2024-03-21 13:00   ` Matt Hickford
  1 sibling, 0 replies; 7+ messages in thread
From: Matt Hickford @ 2024-03-21 13:00 UTC (permalink / raw
  To: Jeff King; +Cc: Git Mailing List

On Wed, 20 Mar 2024 at 10:02, Jeff King <peff@peff.net> wrote:
>
> On Wed, Mar 20, 2024 at 08:00:00AM +0000, Matt Hickford wrote:
>
> > Hi. `git branch` lists branches. It highlights the current branch with
> > an asterisk and (for me) the colour green. This is handy for quick
> > reading.
> >
> > `git worktree list` lists worktrees. It would be neat to highlight the
> > local worktree.
> >
> > Another idea: `git branch -v` shows the commit subject and
> > ahead/behind counts for each branch, eg. "[ahead 1, behind 1] avoid
> > RegexReplace". It would be neat for `git worktree list -v` (or
> > similar) to show the commit subject and ahead/behind counts.
>
> I'm not sure if this is a dumb idea or not, but: what if git-branch
> learned to display branches associated with worktrees (just like "-r"
> lists remote branches, etc).
>
> Then you'd get the all of the display niceties you want, along with
> other features like sorting, limiting by merge, etc. You can even show
> the worktree paths with a custom format that uses %(worktreepath).
>
> I think the only thing it wouldn't do is show worktrees that are
> detached from any branch at all. I'm not sure if that's important to
> your workflow or not.

I frequently run `git worktree list` to review my work in each tree.
Or to choose an inactive tree for new work. Example output:

E:/product1  ea601b57e (detached HEAD)
E:/product2  b255bd1b6 [json]
E:/product3  0d7623530 [optimise]
E:/product4  7bf8297c7 (detached HEAD)
E:/product5  a8f89cabc (detached HEAD)
E:/product6  89a022651 [xml]

The more information the better -- highlighting the local workspace,
ref names when HEAD is detached:

  E:/product1  ea601b57e (detached HEAD, main)
  E:/product2  b255bd1b6 [json]
  E:/product3  0d7623530 [optimise]
* E:/product4  7bf8297c7 (detached HEAD)
  E:/product5  a8f89cabc (detached HEAD, origin/random)
  E:/product6  89a022651 [xml]

A verbose option with commit subjects and ahead-behind counts:

  E:/product1  ea601b57e (detached HEAD, main)           Articulate splines
  E:/product2  b255bd1b6 [json]                          [ahead 1]
Correct syntax error
  E:/product3  0d7623530 [optimise]                      Optimise algorithm
* E:/product4  7bf8297c7 (detached HEAD)                 Reformat doc
  E:/product5  a8f89cabc (detached HEAD, origin/random)  Seed random generator
  E:/product6  89a022651 [xml]                           Replace with XML


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-03-21 13:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-20  8:00 Feature request: highlight local worktree in `worktree list` Matt Hickford
2024-03-20 10:02 ` Jeff King
2024-03-20 14:38   ` Junio C Hamano
2024-03-20 20:39     ` Jeff King
2024-03-21 13:00   ` Matt Hickford
2024-03-20 22:24 ` Rubén Justo
2024-03-21  0:53   ` Chris Torek

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).