Skip to content

Commit e6414dc

Browse files
authored
Support bare repository (#106)
1 parent 82f67da commit e6414dc

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/git.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,31 @@ impl Repository {
223223
}
224224

225225
fn check_git_repository(path: &Path) -> Result<()> {
226+
if !is_inside_work_tree(path) && !is_bare_repository(path) {
227+
let msg = "not a git repository (or any of the parent directories)";
228+
return Err(msg.into());
229+
}
230+
Ok(())
231+
}
232+
233+
fn is_inside_work_tree(path: &Path) -> bool {
226234
let output = Command::new("git")
227235
.arg("rev-parse")
228236
.arg("--is-inside-work-tree")
229237
.current_dir(path)
230238
.output()
231239
.unwrap();
232-
if !output.status.success() || output.stdout == b"false\n" {
233-
let msg = "not a git repository (or any of the parent directories)";
234-
return Err(msg.into());
235-
}
236-
Ok(())
240+
output.status.success() && output.stdout == b"true\n"
241+
}
242+
243+
fn is_bare_repository(path: &Path) -> bool {
244+
let output = Command::new("git")
245+
.arg("rev-parse")
246+
.arg("--is-bare-repository")
247+
.current_dir(path)
248+
.output()
249+
.unwrap();
250+
output.status.success() && output.stdout == b"true\n"
237251
}
238252

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

0 commit comments

Comments
 (0)