Skip to content

Commit

Permalink
Add stderr to GitError (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Haap authored Jan 16, 2022
1 parent 8329cac commit 1890d0a
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 77 deletions.
146 changes: 73 additions & 73 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustygit"
version = "0.4.2"
version = "0.4.3"
authors = ["Keir Lawson <keirlawson@gmail.com>"]
edition = "2018"
description = "A simple interface for runnig Git commands"
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum GitError {
InvalidUrl,
#[error("Ref name is invalid")]
InvalidRefName,
#[error("git failed with the following stdout: {stdout}")]
#[error("git failed with the following stdout: {stdout} stderr: {stderr}")]
GitError{
stdout: String,
stderr: String
Expand Down
28 changes: 26 additions & 2 deletions tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use rustygit::Repository;
use rustygit::{Repository, types::BranchName, error::GitError};
use std::fs;
use std::fs::File;
use std::io::Write;
use std::process::Command;
use std::str;
use std::str::{self, FromStr};
use tempfile;

#[test]
Expand Down Expand Up @@ -318,3 +318,27 @@ fn test_get_hash() {

assert_ne!(hash1_short, hash2_short);
}

#[test]
fn test_get_error() {
let dir = tempfile::tempdir().unwrap();

let repo = Repository::init(&dir).unwrap();

fs::write(&dir.as_ref().join("somefile"), "Some content").unwrap();
repo.add(vec!["somefile"]).unwrap();
repo.commit_all("Commit 1").unwrap();

let result = repo.switch_branch(&BranchName::from_str("no_branch").unwrap());
if let Err(e) = result {
match e {
GitError::GitError { stdout, stderr } => {
assert!(stdout.is_empty());
assert_eq!(stderr, "error: pathspec 'no_branch' did not match any file(s) known to git\n");
}
_ => assert!(false, "Expected GitError, got {:?}", e),
}
} else {
assert!(false, "Expected failing checkout of a unknown branch");
}
}

0 comments on commit 1890d0a

Please sign in to comment.