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

Function git_sync_files

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

Source from the content-addressed store, hash-verified

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)?)
6006 .into_diagnostic()
6007 .wrap_err("failed to canonicalize git repository root")?;
6008 let local_path = if local_path.is_absolute() {
6009 local_path.to_path_buf()
6010 } else {
6011 std::env::current_dir()
6012 .into_diagnostic()
6013 .wrap_err("failed to resolve current directory")?
6014 .join(local_path)
6015 };
6016 let local_path = std::fs::canonicalize(local_path)
6017 .into_diagnostic()
6018 .wrap_err("failed to canonicalize local upload path")?;
6019 let relative_path = local_path
6020 .strip_prefix(&repo_root)
6021 .into_diagnostic()
6022 .wrap_err_with(|| {
6023 format!(
6024 "local path '{}' is not inside git repository '{}'",
6025 local_path.display(),
6026 repo_root.display()
6027 )
6028 })?;
6029
6030 let is_file = local_path.is_file();
6031 let base_dir = if is_file {
6032 local_path
6033 .parent()
6034 .map(Path::to_path_buf)
6035 .ok_or_else(|| miette::miette!("path has no parent: {}", local_path.display()))?
6036 } else {
6037 local_path.clone()
6038 };
6039 let pathspec = if relative_path.as_os_str().is_empty() {
6040 None
6041 } else {
6042 Some(relative_path.to_string_lossy().into_owned())
6043 };
6044
6045 let mut command = Command::new("git");
6046 scrub_git_env(&mut command);
6047 let output = command
6048 .args(["ls-files", "-co", "--exclude-standard", "-z"])
6049 .args(pathspec.as_deref())
6050 .current_dir(&repo_root)
6051 .output()
6052 .into_diagnostic()
6053 .wrap_err("failed to run git ls-files")?;
6054
6055 if !output.status.success() {
6056 return Err(miette::miette!(
6057 "git ls-files failed with status {}",
6058 output.status
6059 ));
6060 }
6061

Calls 5

git_repo_rootFunction · 0.85
scrub_git_envFunction · 0.85
pushMethod · 0.80
is_emptyMethod · 0.45
successMethod · 0.45