path: root/builtin
diff options
authorJunio C Hamano <>2020-03-05 18:43:02 (GMT)
committerJunio C Hamano <>2020-03-05 18:43:02 (GMT)
commit49e5043b09fffb0411e8bae19d60014e72a36fd0 (patch)
tree5d6afc8117d4bb235bfc36958e1375b0433a69c8 /builtin
parent2cbb0586697585995908c325a0c70aad37602274 (diff)
parentbb69b3b009c0093417942dba136b81fbf614c4ed (diff)
Merge branch 'es/worktree-avoid-duplication-fix'
In rare cases "git worktree add <path>" could think that <path> was already a registered worktree even when it wasn't and refuse to add the new worktree. This has been corrected. * es/worktree-avoid-duplication-fix: worktree: don't allow "add" validation to be fooled by suffix matching worktree: add utility to find worktree by pathname worktree: improve find_worktree() documentation
Diffstat (limited to 'builtin')
1 files changed, 1 insertions, 8 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c
index d6bc526..24f2280 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -234,14 +234,7 @@ static void validate_worktree_add(const char *path, const struct add_opts *opts)
die(_("'%s' already exists"), path);
worktrees = get_worktrees(0);
- /*
- * find_worktree()'s suffix matching may undesirably find the main
- * rather than a linked worktree (for instance, when the basenames
- * of the main worktree and the one being created are the same).
- * We're only interested in linked worktrees, so skip the main
- * worktree with +1.
- */
- wt = find_worktree(worktrees + 1, NULL, path);
+ wt = find_worktree_by_path(worktrees, path);
if (!wt)
goto done;