Skip to content

Commit

Permalink
Propagate git errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jdjfisher committed Apr 17, 2023
1 parent d9e7d6e commit ed6724c
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 16 deletions.
211 changes: 210 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ categories = ["command-line-utilities"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.70"
clap = { version = "4.2.2", features = ["derive"] }
console = "0.15.5"

[dev-dependencies]
assert_cmd = "2.0.11"
assert_fs = "1.0.13"
predicates = "3.0.3"
15 changes: 7 additions & 8 deletions src/git.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
use crate::Args;
use std::{
io,
process::{Command, Stdio},
};
use anyhow::{bail, Result};
use std::process::{Command, Stdio};

pub fn checkout_target(target: &String, args: &Args) -> Result<(), io::Error> {
pub fn checkout_target(target: &String, args: &Args) -> Result<()> {
let status = base_git_command(&args)
.args(["-c", "advice.detachedHead=false"])
.args(["checkout", target])
.stdout(Stdio::inherit())
.status()?;

if !status.success() {
panic!("checkout failed");
bail!("checkout failed");
}

Ok(())
}

pub fn get_commits(args: &Args) -> Result<Vec<String>, io::Error> {
pub fn get_commits(args: &Args) -> Result<Vec<String>> {
let output = base_git_command(&args)
.arg("rev-list")
.arg(&args.target)
.arg("--reverse")
.output()?;

// TODO: Inherit stderr?
if !output.status.success() {
panic!("failed to load commits");
bail!("failed to load commits");
}

let raw = String::from_utf8_lossy(&output.stdout);
Expand Down
Loading

0 comments on commit ed6724c

Please sign in to comment.