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

"Git worktree list" on paths with newlines

From
KSKang-Che Sung <explorer09@gmail.com>
Date
Feb 25, 2022, 08:32 UTC
Message-ID
<CADDzAfNTuuAWn1ynswTayRqgNNcPn3ou=v6c+z_tRsu5uoqJZA@mail.gmail.com>
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?
Next: Junio C Hamano
Message 1 of 3 in “"Git worktree list" on paths with newlines”
  1. Kang-Che SungFeb 25, 2022
  2. Junio C HamanoFeb 25, 2022
  3. Eric SunshineFeb 28, 2022

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.