Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: print git dep missing msg on cargo near new #246

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading