Skip to content

Commit

Permalink
[cli] improve git output (#18636)
Browse files Browse the repository at this point in the history
## 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:
  • Loading branch information
vegetabledogdog authored Sep 14, 2024
1 parent c0a1fe8 commit 12cf3a0
Showing 1 changed file with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ impl DependencyCache {
if !self.fetched_deps.insert(repository_path.clone()) {
return Ok(());
}

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."));
}

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());
Expand All @@ -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([
Expand Down Expand Up @@ -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
));
}

Expand Down

0 comments on commit 12cf3a0

Please sign in to comment.