pub fn worktree_root_for_git_dir(git_dir: &Path) -> Result<Option<PathBuf>>Expand description
Resolve the working-tree root for a repository identified by its git
directory, returning Ok(None) for a bare repository.
This is the repository-intrinsic worktree resolution (it does not consult
GIT_WORK_TREE/GIT_DIR or CLI overrides — those are the caller’s job):
- for a linked worktree (a git directory that has both a
commondirand agitdiradministrative file), the directory containing the worktree’s.gitlink, canonicalised; - otherwise, if
core.bareis true the repository is bare andOk(None)is returned immediately —core.baretakes precedence for the main repo, so a bare repo ignorescore.worktreeand the.git-parent fallback; - otherwise, a
core.worktreesetting in<git_dir>/config(absolute, or relative to the git directory), canonicalised; - otherwise, when the git directory is a
.gitdirectory, its parent (the ordinary non-bare layout) — returned verbatim, not canonicalised; - otherwise the repository is bare and
Ok(None)is returned.
Ok(None) means specifically “bare” (case 0 or case 4). A GitError::Io is
returned if a path that should exist cannot be canonicalised, and a
GitError::InvalidPath if a .git directory has no parent (a malformed
layout).