* "Git worktree list" on paths with newlines
@ 2022-02-25 8:32 Kang-Che Sung
2022-02-25 17:11 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Kang-Che Sung @ 2022-02-25 8:32 UTC (permalink / raw)
To: git
Dear Git developers,
I'm not sure if this is a good place to ask a question about the Git worktree
feature.
I'm writing a shell script that parses the "git worktree list --porcelain"
format, and I've run into trouble on determining the end of the worktree path.
Consider a repository with a "test1" branch, and I create a worktree through a
command like this:
$ git worktree add "$(printf 'directory\nHEAD\nbranch\n\nxyz')" test1
Git does allow me to create a worktree with newlines in its name (in a Unix
file system, of course). After that, "git worktree list --porcelain" would show
a somewhat tricked output, and it would break my parsing script.
(What my script does is find out what worktrees check out branches of a
specific pattern, and remove the worktrees found )
I wish "git worktree list --porcelain" would show directory names with some
quoting or escaping so that tricky names can be handled easily for any program
that reads the porcelain output. But I didn't see any command line option that
enables quoting or escaping of file names.
Does anyone have an idea on what I could do?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: "Git worktree list" on paths with newlines
2022-02-25 8:32 "Git worktree list" on paths with newlines Kang-Che Sung
@ 2022-02-25 17:11 ` Junio C Hamano
2022-02-28 8:43 ` Eric Sunshine
0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2022-02-25 17:11 UTC (permalink / raw)
To: Kang-Che Sung; +Cc: git
Kang-Che Sung <explorer09@gmail•com> writes:
> I wish "git worktree list --porcelain" would show directory names with some
> quoting or escaping so that tricky names can be handled easily for any program
> that reads the porcelain output. But I didn't see any command line option that
> enables quoting or escaping of file names.
>
> Does anyone have an idea on what I could do?
I agree that an output mode that claims to be --porcelain should
produce output that is machine-parseable without ambiguity.
The usual practice is to use quote_c_style() for output without
"-z", and with "-z", just use the NUL as the termination character,
as you shouldn't be listing strings with embedded NUL.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-28 8:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-25 8:32 "Git worktree list" on paths with newlines Kang-Che Sung
2022-02-25 17:11 ` Junio C Hamano
2022-02-28 8:43 ` Eric Sunshine
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox