Resolves the common git directory (the main repository's `.git`). Uses `git rev-parse --git-common-dir` to find the shared `.git` directory. In a normal repository, this is the repo's `.git` directory. In a worktree, this points to the main repository's `.git` directory.
(repo_path: &Path)
| 120 | /// In a normal repository, this is the repo's `.git` directory. |
| 121 | /// In a worktree, this points to the main repository's `.git` directory. |
| 122 | pub fn resolve_git_common_dir(repo_path: &Path) -> Result<PathBuf, Box<dyn Error>> { |
| 123 | let result = run_git_rev_parse(repo_path, &["--git-common-dir"])?; |
| 124 | let common_dir = Path::new(&result); |
| 125 | let resolved = if common_dir.is_absolute() { |
| 126 | common_dir.to_path_buf() |
| 127 | } else { |
| 128 | repo_path.join(common_dir) |
| 129 | }; |
| 130 | resolved |
| 131 | .canonicalize() |
| 132 | .map_err(|e| format!("Cannot resolve common dir {}: {e}", resolved.display()).into()) |
| 133 | } |
| 134 | |
| 135 | /// Find the worktree root directory from a starting path. |
| 136 | /// |