(local_path: &Path)
| 5968 | } |
| 5969 | |
| 5970 | pub fn git_repo_root(local_path: &Path) -> Result<PathBuf> { |
| 5971 | let git_dir = if local_path.is_dir() { |
| 5972 | local_path |
| 5973 | } else { |
| 5974 | local_path |
| 5975 | .parent() |
| 5976 | .ok_or_else(|| miette::miette!("path has no parent: {}", local_path.display()))? |
| 5977 | }; |
| 5978 | let mut command = Command::new("git"); |
| 5979 | scrub_git_env(&mut command); |
| 5980 | let output = command |
| 5981 | .args(["rev-parse", "--show-toplevel"]) |
| 5982 | .current_dir(git_dir) |
| 5983 | .output() |
| 5984 | .into_diagnostic() |
| 5985 | .wrap_err("failed to run git rev-parse")?; |
| 5986 | |
| 5987 | if !output.status.success() { |
| 5988 | return Err(miette::miette!( |
| 5989 | "git rev-parse --show-toplevel failed with status {}", |
| 5990 | output.status |
| 5991 | )); |
| 5992 | } |
| 5993 | |
| 5994 | let root = String::from_utf8_lossy(&output.stdout).trim().to_string(); |
| 5995 | if root.is_empty() { |
| 5996 | return Err(miette::miette!( |
| 5997 | "git rev-parse returned empty repository root" |
| 5998 | )); |
| 5999 | } |
| 6000 | |
| 6001 | Ok(PathBuf::from(root)) |
| 6002 | } |
| 6003 | |
| 6004 | pub fn git_sync_files(local_path: &Path) -> Result<(PathBuf, Vec<String>)> { |
| 6005 | let repo_root = std::fs::canonicalize(git_repo_root(local_path)?) |
no test coverage detected