From 2f796c2a0258155ef4f2d567ef59dc2d2b8420ca Mon Sep 17 00:00:00 2001 From: vegetabledogdog Date: Fri, 12 Jul 2024 23:08:05 +0800 Subject: [PATCH 1/2] [cli] improve git output --- .../src/resolution/dependency_cache.rs | 46 +++++++++++++------ 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/external-crates/move/crates/move-package/src/resolution/dependency_cache.rs b/external-crates/move/crates/move-package/src/resolution/dependency_cache.rs index 6752f3f2fe39d..c4f2c2891103a 100644 --- a/external-crates/move/crates/move-package/src/resolution/dependency_cache.rs +++ b/external-crates/move/crates/move-package/src/resolution/dependency_cache.rs @@ -66,6 +66,12 @@ impl DependencyCache { if !self.fetched_deps.insert(repository_path.clone()) { return Ok(()); } + + if let Err(_) = Command::new("git").arg("--version").output() { + writeln!(progress_output, "Git is not installed or not in the PATH.")?; + return Err(anyhow::anyhow!("Git is not installed or not in the PATH.")); + } + let git_path = repository_path; let os_git_url = OsStr::new(git_url.as_str()); let os_git_rev = OsStr::new(git_rev.as_str()); @@ -78,15 +84,25 @@ impl DependencyCache { git_url, )?; // If the cached folder does not exist, download and clone accordingly - Command::new("git") + if let Ok(mut output) = Command::new("git") .args([OsStr::new("clone"), os_git_url, git_path.as_os_str()]) - .output() - .map_err(|_| { + .spawn() + { + output.wait().map_err(|_| { anyhow::anyhow!( "Failed to clone Git repository for package '{}'", dep_name ) })?; + if output.stdout.is_some() { + writeln!(progress_output, "{:?}", output)?; + } + } else { + return Err(anyhow::anyhow!( + "Failed to clone Git repository for package '{}'", + dep_name + )); + } Command::new("git") .args([ @@ -158,31 +174,31 @@ impl DependencyCache { // // NOTE: this means that you must run the package system with a working network // connection. - let status = Command::new("git") + + if let Ok(mut output) = Command::new("git") .args([ OsStr::new("-C"), git_path.as_os_str(), OsStr::new("fetch"), OsStr::new("origin"), ]) - .stdin(Stdio::null()) - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .status() - .map_err(|_| { + .spawn() + { + output.wait().map_err(|_| { anyhow::anyhow!( "Failed to fetch latest Git state for package '{}', to skip set \ --skip-fetch-latest-git-deps", dep_name ) })?; - - if !status.success() { + if output.stdout.is_some() { + writeln!(progress_output, "{:?}", output)?; + } + } else { return Err(anyhow::anyhow!( - "Failed to fetch to latest Git state for package '{}', to skip set \ - --skip-fetch-latest-git-deps | Exit status: {}", - dep_name, - status + "Failed to fetch latest Git state for package '{}', to skip set \ + --skip-fetch-latest-git-deps", + dep_name )); } From 34e819cd99a7861d2757063863c5f5c851123469 Mon Sep 17 00:00:00 2001 From: vegetabledogdog Date: Sat, 14 Sep 2024 13:35:16 +0800 Subject: [PATCH 2/2] [cli] cargo move-clippy --- .../move/crates/move-package/src/resolution/dependency_cache.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external-crates/move/crates/move-package/src/resolution/dependency_cache.rs b/external-crates/move/crates/move-package/src/resolution/dependency_cache.rs index c4f2c2891103a..4cd38aa334b9e 100644 --- a/external-crates/move/crates/move-package/src/resolution/dependency_cache.rs +++ b/external-crates/move/crates/move-package/src/resolution/dependency_cache.rs @@ -67,7 +67,7 @@ impl DependencyCache { return Ok(()); } - if let Err(_) = Command::new("git").arg("--version").output() { + if Command::new("git").arg("--version").output().is_err() { writeln!(progress_output, "Git is not installed or not in the PATH.")?; return Err(anyhow::anyhow!("Git is not installed or not in the PATH.")); }