Skip to main content

resolve_git_root

Function resolve_git_root 

Source
pub fn resolve_git_root(start: &Path) -> Option<PathBuf>
Expand description

Resolve the git repository root, handling worktrees.

Walks up from start looking for .git:

  • Directory → parent is the repo root (normal repo).
  • File with gitdir: .../worktrees/{name} → strip to find the common .git directory, then return its parent (the main working tree root).
  • File without /worktrees/ (e.g. submodule) → return that directory.
  • Not found → returns None (non-git directory; caller uses original path).