MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / git_worktree_root

Function git_worktree_root

src/worktree.rs:41–53  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

39/// checkout and each linked worktree report their own distinct directory,
40/// which is exactly the distinction this module relies on.
41pub 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///

Callers 13

discover_project_rootFunction · 0.85
newMethod · 0.85
containsMethod · 0.85
append_location_metadataFunction · 0.85
backfill_one_sessionFunction · 0.85
hook_project_rootFunction · 0.85

Calls 4

discoverFunction · 0.85
realpathFunction · 0.85
git_may_resolve_repoFunction · 0.85
git_outputFunction · 0.70

Tested by

no test coverage detected