git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* BUG: git worktree add directory-path fails due to over-aggressive disallowing of worktrees with same suffix
@ 2019-02-11 23:50 Cameron Gunnin
  2019-02-12 22:44 ` Eric Sunshine
  0 siblings, 1 reply; 8+ messages in thread
From: Cameron Gunnin @ 2019-02-11 23:50 UTC (permalink / raw)
  To: git@vger.kernel.org

The bug:
  git init worktree-test-repo
  git --git-dir=worktree-test-repo/.git commit --allow-empty -m "first commit"
  git --git-dir=worktree-test-repo/.git branch branch1
  git --git-dir=worktree-test-repo/.git branch branch2
  mkdir unique-path-1 unique-path-2
  cd unique-path-1
  git --git-dir=../worktree-test-repo/.git worktree add subdir branch1
  cd ../unique-path-2
  git --git-dir=../worktree-test-repo/.git worktree add subdir branch2
  # FAILS WITH: fatal: 'subdir' is a missing but already registered worktree; use 'add -f' to override, or 'prune' or 'remove' to clear

Note: the following will succeed, implying that it is the suffix matching that is going awry:
  cd ..
  git --git-dir=worktree-test-repo/.git worktree add unique-path-2/subdir branch2

This appears to have been introduced by the following commit:
  commit cb56f55c16c128e18449c9417dc045f787c1b663
  Author: Eric Sunshine <sunshine@sunshineco.com>
  Date:   Tue Aug 28 17:20:22 2018 -0400

      worktree: disallow adding same path multiple times

The intention of the above commit was to avoid a bad case where a worktree at a given path was removed manually then re-created via 'git worktree add', leading to two entries in 'git worktree list' for the same directory. However, the bug shown here is a valid use case, as we're technically using two different paths.

The fix, I think, should be applied to builtin/worktree.c to the validate_worktree_add method. After finding a worktree that matches the suffix (via find_worktree), it should check that the absolute path of the found worktree is the same as the absolute path of the worktree being added, and allow the add when they are different. Or, perhaps there should be a way to invoke 'find_worktree' such that it only finds absolute path matches.

Thank you for your time,
- Cameron Gunnin


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-02-24 21:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-11 23:50 BUG: git worktree add directory-path fails due to over-aggressive disallowing of worktrees with same suffix Cameron Gunnin
2019-02-12 22:44 ` Eric Sunshine
2020-02-24  9:08   ` [PATCH 0/3] git-worktree: fix "add" being fooled by suffix matching Eric Sunshine
2020-02-24  9:08     ` [PATCH 1/3] worktree: improve find_worktree() documentation Eric Sunshine
2020-02-24  9:08     ` [PATCH 2/3] worktree: add utility to find worktree by pathname Eric Sunshine
2020-02-24  9:08     ` [PATCH 3/3] worktree: don't allow "add" validation to be fooled by suffix matching Eric Sunshine
2020-02-24 21:06       ` Junio C Hamano
2020-02-24 21:02     ` [PATCH 0/3] git-worktree: fix "add" being " Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).