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
This commit is contained in:
Junio C Hamano
2020-03-05 10:43:02 -08:00
4 changed files with 38 additions and 16 deletions

View File

@ -211,7 +211,6 @@ struct worktree *find_worktree(struct worktree **list,
const char *arg)
{
struct worktree *wt;
char *path;
char *to_free = NULL;
if ((wt = find_worktree_by_suffix(list, arg)))
@ -219,11 +218,17 @@ struct worktree *find_worktree(struct worktree **list,
if (prefix)
arg = to_free = prefix_filename(prefix, arg);
path = real_pathdup(arg, 0);
if (!path) {
free(to_free);
wt = find_worktree_by_path(list, arg);
free(to_free);
return wt;
}
struct worktree *find_worktree_by_path(struct worktree **list, const char *p)
{
char *path = real_pathdup(p, 0);
if (!path)
return NULL;
}
for (; *list; list++) {
const char *wt_path = real_path_if_valid((*list)->path);
@ -231,7 +236,6 @@ struct worktree *find_worktree(struct worktree **list,
break;
}
free(path);
free(to_free);
return *list;
}