worktree add: be tolerant of corrupt worktrees
[gitweb.git] / worktree.c
index d6a0ee7f730d96a7e8cc04095ddafb43c937105a..c79b3e42bb5b4362660419ce95c844d6248aa3b3 100644 (file)
@@ -222,9 +222,12 @@ struct worktree *find_worktree(struct worktree **list,
                free(to_free);
                return NULL;
        }
-       for (; *list; list++)
-               if (!fspathcmp(path, real_path((*list)->path)))
+       for (; *list; list++) {
+               const char *wt_path = real_path_if_valid((*list)->path);
+
+               if (wt_path && !fspathcmp(path, wt_path))
                        break;
+       }
        free(path);
        free(to_free);
        return *list;