Re: [PATCH v2] worktree list: add --branch to select worktrees by branch
Hi Jasper
On 29/10/2026 04:46, Jasper Mayone wrote:
Show 5 quoted lines
> > So I would like to drop --branch and instead make %(worktreepath) use
> the same information, so that it names the worktree of a branch that
> is being rebased or bisected. That is a smaller change with no new
> option, so the naming question Eric raised and the --filter-command
> idea Junio floated do not come up.
That would certainly be a useful improvement, there are a few differences compared to adding something to "git worktree list" though
- "git for-each-ref" does not have an option for NUL terminated output
and %(worktreepath) may contain a newline. If is possible to work
round that using one of the quoting options, though it is a pain to
use those if you're not using one of the supported languages.
- there is no way to know from the output whether deleting a worktree
will delete the whole repository.
- I'm not sure that it handles branches that are checked out in more
than one worktree. For warning that a branch is in use somewhere that
does not matter, but if you want to track down all the places it is
checked out it does.
Show 5 quoted lines
> Is that change in behavior acceptable? A script that reads
> %(worktreepath) would now get a path for a branch that is being
> rebased. I think that is a fix, since the rest of Git already
> considers that branch checked out, but I would like to hear if anyone
> relies on the empty value.
I think we can consider the change in behavior to be a bug fix.
> Phillip, thank you for the review. Your point that "git worktree
> list" output does not say which entry is the main worktree still
> stands, and I can send that as a separate patch if it is wanted.
As Eric said, we only need to mark the main worktree if we're filtering the list of worktrees, otherwise it is always the first one listed.
Thanks
Phillip