Skip to content

Commit

Permalink
chore: Gracefully handle missing git on cargo near new (#246)
Browse files Browse the repository at this point in the history
while a fuller solution might be done in scope of #238 

this pr is a quicker clarification of error

![image](https://github.com/user-attachments/assets/fa31cf55-86a7-4bc4-8e3e-25926d144e31)

![image](https://github.com/user-attachments/assets/5f179aa6-e626-49de-b117-cc2dd0aca4ca)

Co-authored-by: dj8yf0μl <[email protected]>
  • Loading branch information
dj8yfo and dj8yf0μl authored Nov 8, 2024
1 parent 7ad06bb commit fa934ed
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions cargo-near/src/commands/new/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::process::Stdio;

use color_eyre::eyre::{ContextCompat, WrapErr};

use crate::posthog_tracking;
use color_eyre::{
eyre::{ContextCompat, WrapErr},
Section,
};

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(input_context = near_cli_rs::GlobalContext)]
Expand Down Expand Up @@ -61,13 +63,26 @@ impl NewContext {
.spawn(posthog_tracking::track_usage)
.unwrap();

let status = std::process::Command::new("git")
let child_result = std::process::Command::new("git")
.arg("init")
.current_dir(project_dir)
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()?;
if !status.success() {
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn();
let child = match child_result {
Ok(child) => child,
Err(io_err) if io_err.kind() == std::io::ErrorKind::NotFound => {
return Err(io_err)
.wrap_err("`git` executable isn't available")
.note("Git from https://git-scm.com/ is required to be available in PATH")?;
}
Err(io_err) => {
return Err(io_err)?;
}
};
let output = child.wait_with_output()?;
if !output.status.success() {
println!("{}", String::from_utf8_lossy(&output.stderr));
return Err(color_eyre::eyre::eyre!(
"Failed to execute process: `git init`"
));
Expand Down

0 comments on commit fa934ed

Please sign in to comment.