(args: &[&str], cwd: &Path)
| 23 | } |
| 24 | |
| 25 | fn run_git(args: &[&str], cwd: &Path) -> Result<String, WorktreeError> { |
| 26 | let output = Command::new("git") |
| 27 | .args(args) |
| 28 | .current_dir(cwd) |
| 29 | .output() |
| 30 | .map_err(|e| WorktreeError::GitError(e.to_string()))?; |
| 31 | |
| 32 | if !output.status.success() { |
| 33 | let stderr = String::from_utf8_lossy(&output.stderr); |
| 34 | return Err(WorktreeError::GitError(stderr.to_string())); |
| 35 | } |
| 36 | |
| 37 | Ok(String::from_utf8_lossy(&output.stdout).trim().to_string()) |
| 38 | } |
| 39 | |
| 40 | fn is_git_repo(path: &Path) -> bool { |
| 41 | path.join(".git").exists() || run_git(&["rev-parse", "--git-dir"], path).is_ok() |
no test coverage detected