Skip to content

Commit 34241c9

Browse files
author
cshinaver
committed
(#1069) smartlog does not panic when run in a non-git directory
1 parent 7520d22 commit 34241c9

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

git-branchless-smartlog/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,13 @@ pub fn smartlog(
758758
reverse,
759759
} = options;
760760

761-
let repo = Repo::from_dir(&git_run_info.working_directory)?;
761+
let repo = match Repo::from_dir(&git_run_info.working_directory) {
762+
Ok(repo) => repo,
763+
Err(err) => {
764+
writeln!(effects.get_error_stream(), "{err}",)?;
765+
return Ok(Err(ExitCode(1)));
766+
}
767+
};
762768
let head_info = repo.get_head_info()?;
763769
let conn = repo.get_db_conn()?;
764770
let event_log_db = EventLogDb::new(&conn)?;

git-branchless-smartlog/tests/test_smartlog.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,26 @@ fn test_smartlog_sparse_main_false_head() -> eyre::Result<()> {
650650
Ok(())
651651
}
652652

653+
#[cfg(unix)]
654+
#[test]
655+
fn test_error_without_panic_on_missing_repo() -> eyre::Result<()> {
656+
let git = make_git()?;
657+
658+
{
659+
let (_stdout, stderr) = git.branchless_with_options(
660+
"smartlog",
661+
&[],
662+
&GitRunOptions {
663+
expected_exit_code: 1,
664+
..Default::default()
665+
},
666+
)?;
667+
insta::assert_snapshot!(stderr, @"could not open repository: could not find repository from '<repo-path>'; class=Repository (6); code=NotFound (-3)");
668+
}
669+
670+
Ok(())
671+
}
672+
653673
#[test]
654674
fn test_smartlog_hidden() -> eyre::Result<()> {
655675
let git = make_git()?;

0 commit comments

Comments
 (0)