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

Re: [PATCH 2/2] ref-filter: name the worktree of a branch being rebased or bisected

From
JMJasper Mayone <me@jaspermayone.com>
Date
Nov 2, 2026, 17:57 UTC
Message-ID
<20261102175722.76770-1-me@jaspermayone.com>
In-Reply-To
<37d53d40-66b6-46bb-a38d-0d3534ca112a@gmail.com>
Phillip Wood <phillip.wood123@gmail.com> writes:
> Those commands also reject branches that are being updated by a rebase
> via "update-ref" commands. If we're interested in checkouts we don't
> want to list those, but it means that "%(worktree)" will still give
> different results.

Yes, that difference is on purpose. I will say so in the commit message and the documentation.

> I don't really follow this logic. At the moment neither "git
> for-each-ref", nor "git worktree list" show this - there is no way for
> a script to find out which worktree is working on a given branch. We
> can choose to add it to one or both commands.

You are right, that paragraph is wrong. No command shows it today, and this patch adds it to %(worktreepath) only. I will rewrite it.

> If we want it to behave like prepare_checked_out_branches() we should
> use that function, rather than copying some of it to a separate file.
Agreed. For v4 I have added a small function to branch.c,
    const char *branch_checked_out_worktree(const char *refname);

which reads the list that prepare_checked_out_branches() builds and skips the BRANCH_CHECKOUT_KIND_UPDATE_REF entries. ref-filter calls it and drops its own hashmap, so the patch now removes more code than it adds in ref-filter.c. t6302, t3203, t3200, t2400 and t2403 pass with it.

> That sounds a bit confusing - "* (no branch, rebasing topic)" already
> tells us what we need to know, why do we need "+ topic" as well?

I agree. In v4 "git branch" will not mark the branch with "+" in the worktree that is rebasing or bisecting it, since the "*" line already names it. The "also in the worktree" sentence in git-branch.adoc goes away with that.

Show 7 quoted lines
> It is not a new problem, but I think it would be helpful to add
> something like
>
>     As the path may contain a newline, [...]
>
>     Note that if a branch checked out in more than one worktree,
>     `%(worktreepath)` will only show one of those worktrees.

Thanks, I will add that as a separate documentation patch before this one.

Show 7 quoted lines
>> +		if (wt->is_bare)
>> +			continue;
>
> This is a change in behavior. We currently print the git_dir of bare
> worktrees. I think you can argue that this change is a bug fix as the
> user asked for the worktree path, but it should be explained in the
> commit message.

Agreed. With a bare repository and a linked worktree, today "git branch" in the linked worktree shows "+ main" for the bare repository's HEAD, and %(worktreepath) gives the path of the bare repository. main is not checked out anywhere, and "git worktree add" already lets you check it out. I will explain that in the commit message and add a test for it.

Thanks, Jasper

Previous: Phillip WoodNext: Junio C Hamano
Message 22 of 33 in “worktree list: add --merged and --no-merged”
  1. 0/1 worktree list: add --merged and --no-mergedJasper Mayone, Oct 21, 2026
  2. 1/1 worktree list: add --merged and --no-mergedJasper Mayone, Oct 21, 2026
  3. Junio C HamanoOct 23, 2026
  4. Eric SunshineOct 24, 2026
  5. worktree list: add --branch to select worktrees by branchJasper Mayone, Oct 24, 2026
  6. Phillip WoodOct 25, 2026
  7. Phillip WoodOct 26, 2026
  8. Eric SunshineOct 28, 2026
  9. Junio C HamanoOct 28, 2026
  10. Kristoffer HaugsbakkOct 28, 2026
  11. Jasper MayoneOct 29, 2026
  12. Eric SunshineOct 29, 2026
  13. Phillip WoodOct 29, 2026
  14. Ben KnobleOct 29, 2026
  15. Phillip WoodOct 29, 2026
  16. 0/2 worktree: treat a branch being rebased or bisected as checked outJasper Mayone, Oct 30, 2026
  17. 1/2 worktree remove: refuse a worktree in the middle of a rebase or bisectJasper Mayone, Oct 30, 2026
  18. Phillip WoodNov 2, 2026
  19. Jasper MayoneNov 2, 2026
  20. 2/2 ref-filter: name the worktree of a branch being rebased or bisectedJasper Mayone, Oct 30, 2026
  21. Phillip WoodNov 2, 2026
  22. Jasper MayoneNov 2, 2026
  23. Junio C HamanoOct 30, 2026
  24. Jasper MayoneOct 30, 2026
  25. 0/4 worktree: treat a branch being rebased or bisected as checked outJasper Mayone, Nov 2, 2026
  26. 1/4 worktree remove: refuse a worktree in the middle of an operationJasper Mayone, Nov 2, 2026
  27. 2/4 doc: for-each-ref: say how to read %(worktreepath) safelyJasper Mayone, Nov 2, 2026
  28. 3/4 ref-filter: name the worktree of a branch being rebased or bisectedJasper Mayone, Nov 2, 2026
  29. 4/4 branch: do not mark the branch the current worktree is rebasingJasper Mayone, Nov 2, 2026
  30. Harald NordgrenOct 21, 2026
  31. Junio C HamanoOct 21, 2026
  32. Harald NordgrenOct 22, 2026
  33. Kristoffer HaugsbakkOct 22, 2026

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.