Skip to content

Commit

Permalink
(arxanas#1069) smartlog does not panic when run in a non-git directory
Browse files Browse the repository at this point in the history
  • Loading branch information
cshinaver committed Oct 10, 2023
1 parent 7520d22 commit f145dfb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
11 changes: 10 additions & 1 deletion git-branchless-smartlog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,16 @@ pub fn smartlog(
reverse,
} = options;

let repo = Repo::from_dir(&git_run_info.working_directory)?;
let repo = match Repo::from_dir(&git_run_info.working_directory) {
Ok(repo) => repo,
Err(err) => {
writeln!(
effects.get_error_stream(),
"{err}",
)?;
return Ok(Err(ExitCode(1)));
}
};
let head_info = repo.get_head_info()?;
let conn = repo.get_db_conn()?;
let event_log_db = EventLogDb::new(&conn)?;
Expand Down
18 changes: 18 additions & 0 deletions git-branchless-smartlog/tests/test_smartlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,24 @@ fn test_smartlog_sparse_main_false_head() -> eyre::Result<()> {
Ok(())
}

#[test]
fn test_error_without_panic_on_missing_repo() -> eyre::Result<()> {
let git = make_git()?;

{
let (_stdout, stderr) = git.branchless_with_options(
"smartlog",
&[],
&GitRunOptions {
expected_exit_code: 1,
..Default::default()
})?;
insta::assert_snapshot!(stderr, @"could not open repository: could not find repository from '<repo-path>'; class=Repository (6); code=NotFound (-3)");
}

Ok(())
}

#[test]
fn test_smartlog_hidden() -> eyre::Result<()> {
let git = make_git()?;
Expand Down

0 comments on commit f145dfb

Please sign in to comment.