Skip to main content

find_git_root

Function find_git_root 

Source
pub fn find_git_root(from: &Path) -> Option<PathBuf>
Expand description

Walk up from from to find the nearest .git directory.

Handles git worktrees where .git is a file containing gitdir: <path> instead of a directory — resolves to the main repository root.

Returns the parent of .git (the repository root). Returns None if no .git is found before reaching the filesystem root or hitting the iteration limit (symlink cycle protection).