Absolute, symlink-resolved toplevel of the git working tree that `dir` belongs to, or `None` when `dir` isn't inside a git repo (or `git` is missing on PATH). `git rev-parse --show-toplevel` returns the per-worktree root: the main checkout and each linked worktree report their own distinct directory, which is exactly the distinction this module relies on.
(dir: &Path)
| 39 | /// checkout and each linked worktree report their own distinct directory, |
| 40 | /// which is exactly the distinction this module relies on. |
| 41 | pub fn git_worktree_root(dir: &Path) -> Option<PathBuf> { |
| 42 | // gix discovery walks up the same way `git rev-parse` does but without |
| 43 | // a subprocess spawn. A discovered bare repo (no workdir) matches |
| 44 | // `--show-toplevel` failing. |
| 45 | if let Ok(repo) = gix::discover(dir) { |
| 46 | return realpath(repo.workdir()?); |
| 47 | } |
| 48 | if !git_may_resolve_repo(dir) { |
| 49 | return None; |
| 50 | } |
| 51 | let trimmed = git_output(dir, &["rev-parse", "--show-toplevel"])?; |
| 52 | realpath(Path::new(&trimmed)) |
| 53 | } |
| 54 | |
| 55 | /// Absolute, symlink-resolved path to the repository's git common directory. |
| 56 | /// |
no test coverage detected