Thread View: linux.kernel.git
4 messages
4 total messages
Started by "D. Ben Knoble"
Mon, 09 Nov 2026 12:36
Re: [PATCH v4 2/4] doc: for-each-ref: say how to read %(worktreepath) safely
Author: "D. Ben Knoble"
Date: Mon, 09 Nov 2026 12:36
Date: Mon, 09 Nov 2026 12:36
51 lines
13886 bytes
13886 bytes
On Mon, Nov 2, 2026 at 1:29 PM Jasper Mayone <me@jaspermayone.com> wrote: > > The path that %(worktreepath) gives can contain a newline, which > breaks a script that reads one record per line. Say how to avoid > that: use a quoting option, or end the atom with %00 and look for the > NUL before the LF that ends the record. > > Also say that only one worktree is shown when a branch is checked out > in more than one worktree. I was under the impression a branch could not be checked out in multiple worktrees due to possible races from each worktree performing updates; or at least, that the porcelain would refuse to create such worktrees. Has that limitation been lifted recently? > Suggested-by: Phillip Wood <phillip.wood123@gmail.com> > Signed-off-by: Jasper Mayone <me@jaspermayone.com> > --- > Documentation/git-for-each-ref.adoc | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/Documentation/git-for-each-ref.adoc b/Documentation/git-for-each-ref.adoc > index a7b31e8aaf..9247737aa7 100644 > --- a/Documentation/git-for-each-ref.adoc > +++ b/Documentation/git-for-each-ref.adoc > @@ -183,7 +183,12 @@ but if used together the last option is selected. > `worktreepath`:: > The absolute path to the worktree in which the ref is checked > out, if it is checked out in any linked worktree. Empty string > - otherwise. > + otherwise. If the ref is checked out in more than one worktree, > + only one of them is shown. The path can contain a newline, so > + use one of the quoting options such as `--shell`, or follow > + `%(worktreepath)` with `%00` and parse the output by looking for > + the `NUL` after the path and then for the `LF` that ends each > + record. > > `ahead-behind:<commit-ish>`:: > Two integers, separated by a space, demonstrating the number of > -- > 2.56.0 > -- D. Ben Knoble
Re: [PATCH v4 2/4] doc: for-each-ref: say how to read %(worktreepath) safely
Author: Phillip Wood
Date: Mon, 09 Nov 2026 15:10
Date: Mon, 09 Nov 2026 15:10
59 lines
13475 bytes
13475 bytes
Hi Ben On 09/11/2026 12:36, D. Ben Knoble wrote: > On Mon, Nov 2, 2026 at 1:29 PM Jasper Mayone <me@jaspermayone.com> wrote: >> >> The path that %(worktreepath) gives can contain a newline, which >> breaks a script that reads one record per line. Say how to avoid >> that: use a quoting option, or end the atom with %00 and look for the >> NUL before the LF that ends the record. >> >> Also say that only one worktree is shown when a branch is checked out >> in more than one worktree. > > I was under the impression a branch could not be checked out in > multiple worktrees due to possible races from each worktree performing > updates; or at least, that the porcelain would refuse to create such > worktrees. > > Has that limitation been lifted recently? No, it is not encouraged, but it is possible to checkout the same branch in more than one worktree with "git worktree add --force", or "git checkout --ignore-other-worktrees". Those options have existed for some time. It's also possible to bypass the checks by using "git symbolic-ref". Thanks Phillip >> Suggested-by: Phillip Wood <phillip.wood123@gmail.com> >> Signed-off-by: Jasper Mayone <me@jaspermayone.com> >> --- >> Documentation/git-for-each-ref.adoc | 7 ++++++- >> 1 file changed, 6 insertions(+), 1 deletion(-) >> >> diff --git a/Documentation/git-for-each-ref.adoc b/Documentation/git-for-each-ref.adoc >> index a7b31e8aaf..9247737aa7 100644 >> --- a/Documentation/git-for-each-ref.adoc >> +++ b/Documentation/git-for-each-ref.adoc >> @@ -183,7 +183,12 @@ but if used together the last option is selected. >> `worktreepath`:: >> The absolute path to the worktree in which the ref is checked >> out, if it is checked out in any linked worktree. Empty string >> - otherwise. >> + otherwise. If the ref is checked out in more than one worktree, >> + only one of them is shown. The path can contain a newline, so >> + use one of the quoting options such as `--shell`, or follow >> + `%(worktreepath)` with `%00` and parse the output by looking for >> + the `NUL` after the path and then for the `LF` that ends each >> + record. >> >> `ahead-behind:<commit-ish>`:: >> Two integers, separated by a space, demonstrating the number of >> -- >> 2.56.0 >> > >
Re: [PATCH v4 2/4] doc: for-each-ref: say how to read %(worktreepath) safely
Author: Ben Knoble
Date: Mon, 09 Nov 2026 17:27
Date: Mon, 09 Nov 2026 17:27
35 lines
12307 bytes
12307 bytes
> Le 9 nov. 2026 à 10:10, Phillip Wood <phillip.wood123@gmail.com> a écrit : > > Hi Ben > >> On 09/11/2026 12:36, D. Ben Knoble wrote: >>> On Mon, Nov 2, 2026 at 1:29 PM Jasper Mayone <me@jaspermayone.com> wrote: >>> >>> The path that %(worktreepath) gives can contain a newline, which >>> breaks a script that reads one record per line. Say how to avoid >>> that: use a quoting option, or end the atom with %00 and look for the >>> NUL before the LF that ends the record. >>> >>> Also say that only one worktree is shown when a branch is checked out >>> in more than one worktree. >> I was under the impression a branch could not be checked out in >> multiple worktrees due to possible races from each worktree performing >> updates; or at least, that the porcelain would refuse to create such >> worktrees. >> Has that limitation been lifted recently? > > No, it is not encouraged, but it is possible to checkout the same branch in more than one worktree with "git worktree add --force", or "git checkout --ignore-other-worktrees". Those options have existed for some time. It's also possible to bypass the checks by using "git symbolic-ref". > > Thanks > > Phillip > Faulty memory, then, thanks.
Re: [PATCH v4 2/4] doc: for-each-ref: say how to read %(worktreepath) safely
Author: Junio C Hamano
Date: Mon, 09 Nov 2026 20:17
Date: Mon, 09 Nov 2026 20:17
37 lines
14310 bytes
14310 bytes
Ben Knoble <ben.knoble@gmail.com> writes: >>> I was under the impression a branch could not be checked out in >>> multiple worktrees due to possible races from each worktree performing >>> updates; or at least, that the porcelain would refuse to create such >>> worktrees. Phillip's answer covers everything, but I am not sure if "possible races" is a good explanation to describe the reason this is strongly discouraged. You checkout 'main' in worktree A and worktree B, so their working tree files and their index files all match what is recorded at the commit pointed at by 'main'. You then make changes and commit your changes in worktree A. The 'main' branch now points at a newly created commit, and the working tree files and the index in worktree A are in sync with the new commit (note: unlike the initial state, I am not saying "all match" in this case, as this commit may have been a partial one. The important thing is that from the end-user's perspective who has been working in worktree A, things are consistent without any unexpected change). In the meantime, if worktree B weren't doing anything, its index and the working tree files have not changed since the beginning. Yet because 'main' (hence HEAD) moved, "git status" in worktree B reports as if it reverted the change made in the updated 'main'. That would be a grave confusion, and that is what we want to avoid by forbidding a single branch from being checked out in multiple worktrees. But given that worktree B was doing absolutely nothing while worktree A was doing its own thing, I would not call this a "race". It is something else. Thanks.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads