Find the worktree root directory from a starting path. Uses `git rev-parse` to determine if the path is inside a git worktree. Returns the worktree directory if so, or `None` if it's a normal repository.
(start_path: &Path)
| 137 | /// Uses `git rev-parse` to determine if the path is inside a git worktree. |
| 138 | /// Returns the worktree directory if so, or `None` if it's a normal repository. |
| 139 | pub fn find_worktree_root(start_path: &Path) -> Result<Option<PathBuf>, Box<dyn Error>> { |
| 140 | let info = detect_git_repo(start_path)?; |
| 141 | |
| 142 | if info.is_worktree { |
| 143 | Ok(Some(info.toplevel)) |
| 144 | } else { |
| 145 | Ok(None) |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | #[cfg(test)] |
| 150 | mod tests { |