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

[PATCH 0/3] git-worktree: fix "add" being fooled by suffix matching

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Feb 24, 2020, 09:08 UTC
Message-ID
<20200224090848.54321-1-sunshine@sunshineco.com>
In-Reply-To
<CAPig+cQh8hxeoVjLHDKhAcZVQPpPT5v0AUY8gsL9=qfJ7z-L2A@mail.gmail.com>

"git worktree add <path>" performs various checks before approving <path> as a valid location for the new worktree. One such check is asking whether <path> is already a registered worktree. Unfortunately, this check can be fooled by the magic suffix matching performed by find_worktree() as a convenience to minimize typing when identifying worktrees on the command-line.

That the check could be fooled was a known issue, and a special-case work-around for accidental matching against the main worktree was already in place even when the validation check was first implemented[1]. Since that time, an additional case of accidental suffix matching has been reported[2], which was not covered by the existing special case.

Rather than adding more band-aids to the validation to work around magic matching performed by find_worktree(), this patch series fixes the problem once and for all by locating a worktree deterministically based only on pathname.

[1]: https://lore.kernel.org/git/CAPig+cQh8hxeoVjLHDKhAcZVQPpPT5v0AUY8gsL9=qfJ7z-L2A@mail.gmail.com/ [2]: https://lore.kernel.org/git/0308570E-AAA3-43B8-A592-F4DA9760DBED@synopsys.com/

Eric Sunshine (3):
  worktree: improve find_worktree() documentation
  worktree: add utility to find worktree by pathname
  worktree: don't allow "add" validation to be fooled by suffix matching
 builtin/worktree.c      |  9 +--------
 t/t2400-worktree-add.sh |  9 +++++++++
 worktree.c              | 16 ++++++++++------
 worktree.h              | 20 ++++++++++++++++++--
 4 files changed, 38 insertions(+), 16 deletions(-)
-- 
2.25.1.526.gf05a752211
Previous: Eric SunshineNext: Eric Sunshine
Message 3 of 8 in “BUG: git worktree add directory-path fails due to over-aggressive disallowing of worktrees with same suffix”
  1. Cameron GunninFeb 11, 2019
  2. Eric SunshineFeb 12, 2019
  3. 0/3 git-worktree: fix "add" being fooled by suffix matchingEric Sunshine, Feb 24, 2020
  4. 2/3 worktree: add utility to find worktree by pathnameEric Sunshine, Feb 24, 2020
  5. 3/3 worktree: don't allow "add" validation to be fooled by suffix matchingEric Sunshine, Feb 24, 2020
  6. Junio C HamanoFeb 24, 2020
  7. 1/3 worktree: improve find_worktree() documentationEric Sunshine, Feb 24, 2020
  8. Junio C HamanoFeb 24, 2020

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.