pub fn worktree_root(dir: &Path) -> Option<&Path>Expand description
The root of the working tree dir sits in: the nearest ancestor holding a
.git entry, or None outside a checkout.
The answer is a working tree root, never the .git directory several
worktrees share. A linked worktree keeps a .git file at its root
(gitdir: …/worktrees/<name>) rather than a directory, and both spellings
count here, so git worktree add produces a checkout that resolves to its
own store. Two worktrees are two different sets of files, and a graph built
from one answers questions about the other wrongly.
Walking up matters as much as the file/directory distinction: a hook fires
with whatever working directory the tool call had, which is often a
subdirectory, and only the root has the .git entry.