path: root/worktree.h
diff options
authorEric Sunshine <>2020-02-24 09:08:47 (GMT)
committerJunio C Hamano <>2020-02-24 21:04:30 (GMT)
commitbb4995fc3fab35b56f1ca48cda9187bcf340e643 (patch)
treec160a434298ff0fa78f16bb745b3b7ade472d066 /worktree.h
parenta80c4c22147bae6d9f9b907b81ab3f4d129ab690 (diff)
worktree: add utility to find worktree by pathname
find_worktree() employs heuristics to match user provided input -- which may be a pathname or some sort of shorthand -- with an actual worktree. Although this convenience allows a user to identify a worktree with minimal typing, the black-box nature of these heuristics makes it potentially difficult for callers which already know the exact path of a worktree to be confident that the correct worktree will be returned for any specific pathname (particularly a relative one), especially as the heuristics are enhanced and updated. Therefore, add a companion function, find_worktree_by_path(), which deterministically identifies a worktree strictly by pathname with no interpretation and no magic matching. Signed-off-by: Eric Sunshine <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'worktree.h')
1 files changed, 6 insertions, 0 deletions
diff --git a/worktree.h b/worktree.h
index b8a851b..d242a6e 100644
--- a/worktree.h
+++ b/worktree.h
@@ -62,6 +62,12 @@ struct worktree *find_worktree(struct worktree **list,
const char *arg);
+ * Return the worktree corresponding to `path`, or NULL if no such worktree
+ * exists.
+ */
+struct worktree *find_worktree_by_path(struct worktree **, const char *path);
* Return true if the given worktree is the main one.
int is_main_worktree(const struct worktree *wt);