Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,31 @@ impl Repository {
}

fn check_git_repository(path: &Path) -> Result<()> {
if !is_inside_work_tree(path) && !is_bare_repository(path) {
let msg = "not a git repository (or any of the parent directories)";
return Err(msg.into());
}
Ok(())
}

fn is_inside_work_tree(path: &Path) -> bool {
let output = Command::new("git")
.arg("rev-parse")
.arg("--is-inside-work-tree")
.current_dir(path)
.output()
.unwrap();
if !output.status.success() || output.stdout == b"false\n" {
let msg = "not a git repository (or any of the parent directories)";
return Err(msg.into());
}
Ok(())
output.status.success() && output.stdout == b"true\n"
}

fn is_bare_repository(path: &Path) -> bool {
let output = Command::new("git")
.arg("rev-parse")
.arg("--is-bare-repository")
.current_dir(path)
.output()
.unwrap();
output.status.success() && output.stdout == b"true\n"
}

fn load_all_commits(path: &Path, sort: SortCommit, stashes: &[Commit]) -> Vec<Commit> {
Expand Down
Loading