MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / git_repo_root

Function git_repo_root

crates/openshell-cli/src/run.rs:5970–6002  ·  view source on GitHub ↗
(local_path: &Path)

Source from the content-addressed store, hash-verified

5968}
5969
5970pub 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
6004pub fn git_sync_files(local_path: &Path) -> Result<(PathBuf, Vec<String>)> {
6005 let repo_root = std::fs::canonicalize(git_repo_root(local_path)?)

Callers 1

git_sync_filesFunction · 0.85

Calls 3

scrub_git_envFunction · 0.85
successMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected