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

Function git_common_dir

src/worktree.rs:59–80  ·  view source on GitHub ↗

Absolute, symlink-resolved path to the repository's git common directory. For a linked worktree this is the main checkout's `.git` directory, which is the stable local identity all linked worktrees share.

(dir: &Path)

Source from the content-addressed store, hash-verified

57/// For a linked worktree this is the main checkout's `.git` directory, which is
58/// the stable local identity all linked worktrees share.
59pub fn git_common_dir(dir: &Path) -> Option<PathBuf> {
60 if let Ok(repo) = gix::discover(dir) {
61 let common_dir = repo.common_dir().to_path_buf();
62 let resolved = if common_dir.is_absolute() {
63 common_dir
64 } else {
65 dir.join(common_dir)
66 };
67 return Some(resolved.canonicalize().unwrap_or(resolved));
68 }
69 if !git_may_resolve_repo(dir) {
70 return None;
71 }
72 let raw = git_output(dir, &["rev-parse", "--git-common-dir"])?;
73 let common_dir = PathBuf::from(raw);
74 let resolved = if common_dir.is_absolute() {
75 common_dir
76 } else {
77 dir.join(common_dir)
78 };
79 Some(resolved.canonicalize().unwrap_or(resolved))
80}
81
82/// Cheap pre-flight for the `git` subprocess fallbacks in this crate: `git`
83/// can only resolve a repository for `dir` when a `.git` entry exists

Calls 3

discoverFunction · 0.85
git_may_resolve_repoFunction · 0.85
git_outputFunction · 0.70