Skip to content

Commit 8643844

Browse files
author
Stephan Dilly
committed
expressive error msg when run in bare repo (closes #100)
1 parent 67544ab commit 8643844

File tree

6 files changed

+20
-6
lines changed

6 files changed

+20
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Fixed
1515
- error when diffing huge files ([#96](https://github.com/extrawurst/gitui/issues/96))
16+
- expressive error when run in bare repos ([#100](https://github.com/extrawurst/gitui/issues/100))
1617

1718
## [0.4.0] - 2020-05-25
1819

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ presentation slides: https://github.com/extrawurst/gitui-presentation
4545

4646
# known limitations
4747

48+
* no support for [bare repositories](https://git-scm.com/book/en/v2/Git-on-the-Server-Getting-Git-on-a-Server)
4849
* [core.hooksPath](https://git-scm.com/docs/githooks) config not supported
4950
* revert/reset hunk in working dir (see [#11](https://github.com/extrawurst/gitui/issues/11))
5051

asyncgit/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub use crate::{
1919
sync::{
2020
diff::{DiffLine, DiffLineType, FileDiff},
2121
status::{StatusItem, StatusItemType},
22-
utils::is_repo,
2322
},
2423
};
2524
use std::{

asyncgit/src/sync/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ pub use reset::{
2121
pub use stash::{get_stashes, stash_apply, stash_drop, stash_save};
2222
pub use tags::{get_tags, Tags};
2323
pub use utils::{
24-
commit, stage_add_all, stage_add_file, stage_addremoved,
24+
commit, is_bare_repo, is_repo, stage_add_all, stage_add_file,
25+
stage_addremoved,
2526
};
2627

2728
#[cfg(test)]

asyncgit/src/sync/utils.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ pub fn is_repo(repo_path: &str) -> bool {
1515
.is_ok()
1616
}
1717

18+
/// checks if the git repo at path `repo_path` is a bare repo
19+
pub fn is_bare_repo(repo_path: &str) -> Result<bool> {
20+
let repo = Repository::open_ext(
21+
repo_path,
22+
RepositoryOpenFlags::empty(),
23+
Vec::<&Path>::new(),
24+
)?;
25+
26+
Ok(repo.is_bare())
27+
}
28+
1829
///
1930
pub fn repo(repo_path: &str) -> Result<Repository> {
2031
let repo = Repository::open_ext(

src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ static SPINNER_INTERVAL: Duration = Duration::from_millis(50);
5959
fn main() -> Result<()> {
6060
process_cmdline()?;
6161

62-
if invalid_path() {
63-
eprintln!("invalid git path\nplease run gitui inside of a git repository");
62+
if !valid_path()? {
63+
eprintln!("invalid git path\nplease run gitui inside of a valid git (non-bare) repository");
6464
return Ok(());
6565
}
6666

@@ -149,8 +149,9 @@ fn draw<B: Backend>(
149149
})
150150
}
151151

152-
fn invalid_path() -> bool {
153-
!asyncgit::is_repo(asyncgit::CWD)
152+
fn valid_path() -> Result<bool> {
153+
Ok(asyncgit::sync::is_repo(asyncgit::CWD)
154+
&& !asyncgit::sync::is_bare_repo(asyncgit::CWD)?)
154155
}
155156

156157
fn select_event(

0 commit comments

Comments
 (0)