Skip to content

Commit 12cf3a0

Browse files
[cli] improve git output (MystenLabs#18636)
## Description Check if git is installed. Ouput the git clone or git fetch message ## Test plan 1. git is not installed ``` sui move build Git is not installed or not in the PATH. Failed to build Move modules: Failed to resolve dependencies for package 'gitt' Caused by: 0: Fetching 'Sui' 1: Git is not installed or not in the PATH.. ``` 2.network error ``` sui move build FETCHING GIT DEPENDENCY https://github.com/MystenLabs/sui.git Cloning into '/home/sun/.move/https___github_com_MystenLabs_sui_git_framework__testnet'... fatal: unable to access 'https://github.com/MystenLabs/sui.git/': Could not resolve host: github.com Failed to build Move modules: Failed to resolve dependencies for package 'up' Caused by: 0: Parsing manifest for 'Sui' 1: No such file or directory (os error 2). ``` 3.Show the progress of git ``` sui move build FETCHING GIT DEPENDENCY https://github.com/MystenLabs/sui.git Cloning into '/home/sun/.move/https___github_com_MystenLabs_sui_git_framework__testnet'... remote: Enumerating objects: 345462, done. remote: Counting objects: 100% (5589/5589), done. remote: Compressing objects: 100% (2204/2204), done. Receiving objects: 9% (33800/345462), 35.71 MiB | 4.38 MiB/s ``` --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [x] CLI: Improve error and status messages for `sui move build`. - [ ] Rust SDK:
1 parent c0a1fe8 commit 12cf3a0

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

external-crates/move/crates/move-package/src/resolution/dependency_cache.rs

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ impl DependencyCache {
6666
if !self.fetched_deps.insert(repository_path.clone()) {
6767
return Ok(());
6868
}
69+
70+
if Command::new("git").arg("--version").output().is_err() {
71+
writeln!(progress_output, "Git is not installed or not in the PATH.")?;
72+
return Err(anyhow::anyhow!("Git is not installed or not in the PATH."));
73+
}
74+
6975
let git_path = repository_path;
7076
let os_git_url = OsStr::new(git_url.as_str());
7177
let os_git_rev = OsStr::new(git_rev.as_str());
@@ -78,15 +84,25 @@ impl DependencyCache {
7884
git_url,
7985
)?;
8086
// If the cached folder does not exist, download and clone accordingly
81-
Command::new("git")
87+
if let Ok(mut output) = Command::new("git")
8288
.args([OsStr::new("clone"), os_git_url, git_path.as_os_str()])
83-
.output()
84-
.map_err(|_| {
89+
.spawn()
90+
{
91+
output.wait().map_err(|_| {
8592
anyhow::anyhow!(
8693
"Failed to clone Git repository for package '{}'",
8794
dep_name
8895
)
8996
})?;
97+
if output.stdout.is_some() {
98+
writeln!(progress_output, "{:?}", output)?;
99+
}
100+
} else {
101+
return Err(anyhow::anyhow!(
102+
"Failed to clone Git repository for package '{}'",
103+
dep_name
104+
));
105+
}
90106

91107
Command::new("git")
92108
.args([
@@ -158,31 +174,31 @@ impl DependencyCache {
158174
//
159175
// NOTE: this means that you must run the package system with a working network
160176
// connection.
161-
let status = Command::new("git")
177+
178+
if let Ok(mut output) = Command::new("git")
162179
.args([
163180
OsStr::new("-C"),
164181
git_path.as_os_str(),
165182
OsStr::new("fetch"),
166183
OsStr::new("origin"),
167184
])
168-
.stdin(Stdio::null())
169-
.stdout(Stdio::null())
170-
.stderr(Stdio::null())
171-
.status()
172-
.map_err(|_| {
185+
.spawn()
186+
{
187+
output.wait().map_err(|_| {
173188
anyhow::anyhow!(
174189
"Failed to fetch latest Git state for package '{}', to skip set \
175190
--skip-fetch-latest-git-deps",
176191
dep_name
177192
)
178193
})?;
179-
180-
if !status.success() {
194+
if output.stdout.is_some() {
195+
writeln!(progress_output, "{:?}", output)?;
196+
}
197+
} else {
181198
return Err(anyhow::anyhow!(
182-
"Failed to fetch to latest Git state for package '{}', to skip set \
183-
--skip-fetch-latest-git-deps | Exit status: {}",
184-
dep_name,
185-
status
199+
"Failed to fetch latest Git state for package '{}', to skip set \
200+
--skip-fetch-latest-git-deps",
201+
dep_name
186202
));
187203
}
188204

0 commit comments

Comments
 (0)