diff --git a/Cargo.lock b/Cargo.lock index 3b4db43..b2a3a01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -284,7 +284,7 @@ checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" [[package]] name = "ppi" -version = "1.0.0" +version = "1.1.0" dependencies = [ "clap", "dirs", diff --git a/Cargo.toml b/Cargo.toml index dfee31b..9e22615 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ppi" -version = "1.0.0" +version = "1.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/main.rs b/src/main.rs index 76147ef..98f8de7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -102,8 +102,9 @@ fn main() -> Result<(),Errors> { std::io::stdin().read_line(&mut String::new())?; } - - + eprintln!("checking out appropriate branch"); + handle_process(std::process::Command::new("git") + .args(["checkout", skelly_branch.as_str()]))?; // let branch = repo.branches(Some(git2::BranchType::Remote))?.find(|branch|{ // if let Ok(branch) = branch{ // if let Ok(Some(name)) = branch.0.name(){ @@ -148,15 +149,21 @@ fn main() -> Result<(),Errors> { } let pwd = repo.path().parent().expect("very bad cloning into the root dir happening"); eprintln!("rebasing skeleton's commits down into single commit {:?}", pwd); - // I give up git2 documentation/api is just too bad for me to do this - std::process::Command::new("git") + // I give up git2 documentation/api is just too bad for me to do this with it + + + handle_process(std::process::Command::new("git") .current_dir(pwd) - .args(["reset", "--mixed" , oldest_commit.id().as_bytes().iter().map(|byte|format!("{:x}",byte)).collect::().chars().take(7).collect::().as_str()]) - .status()?; - std::process::exit(std::process::Command::new("git") + .args(["reset", "--mixed" , oldest_commit.id().as_bytes().iter().map(|byte|format!("{:x}",byte)).collect::().chars().take(7).collect::().as_str()]))?; + + handle_process(std::process::Command::new("git") .current_dir(pwd) - .args(["commit", "--amend", "-am", format!("").as_str(), oldest_commit.id().as_bytes().iter().map(|byte|format!("{:x}",byte)).collect::().chars().take(7).collect::().as_str()]) - .status()?.code().ok_or(Errors::Unknown)?); + .args(["add", "--all"]))?; + + handle_process(std::process::Command::new("git") + .current_dir(pwd) + .args(["commit", "--amend", "-am", format!("initialized from {} skeleton", skelly_name).as_str()]))?; + std::process::exit(0) } None=>{ eprintln!("failed to provide a path to clone the skeleton directory into"); @@ -187,7 +194,11 @@ fn cli_fallback, P:AsRef>(source:S, dest: P)->Result<(),Cli .arg("clone") .arg(source) .arg(dest.as_ref()); - if !child.spawn()?.wait()?.success() { + handle_process(&mut child) +} + +fn handle_process<'proc,P:Into<&'proc mut std::process::Command>>(cmd:P) -> Result<(),CliError>{ + if !cmd.into().status()?.success() { Err(CliError::NonZero) } else{