expressive error msg when run in bare repo (closes #100)

This commit is contained in:
Stephan Dilly 2020-05-30 13:05:11 +02:00
parent 67544ab2ce
commit 8643844913
6 changed files with 20 additions and 6 deletions

View file

@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- error when diffing huge files ([#96](https://github.com/extrawurst/gitui/issues/96))
- expressive error when run in bare repos ([#100](https://github.com/extrawurst/gitui/issues/100))
## [0.4.0] - 2020-05-25

View file

@ -45,6 +45,7 @@ presentation slides: https://github.com/extrawurst/gitui-presentation
# known limitations
* no support for [bare repositories](https://git-scm.com/book/en/v2/Git-on-the-Server-Getting-Git-on-a-Server)
* [core.hooksPath](https://git-scm.com/docs/githooks) config not supported
* revert/reset hunk in working dir (see [#11](https://github.com/extrawurst/gitui/issues/11))

View file

@ -19,7 +19,6 @@ pub use crate::{
sync::{
diff::{DiffLine, DiffLineType, FileDiff},
status::{StatusItem, StatusItemType},
utils::is_repo,
},
};
use std::{

View file

@ -21,7 +21,8 @@ pub use reset::{
pub use stash::{get_stashes, stash_apply, stash_drop, stash_save};
pub use tags::{get_tags, Tags};
pub use utils::{
commit, stage_add_all, stage_add_file, stage_addremoved,
commit, is_bare_repo, is_repo, stage_add_all, stage_add_file,
stage_addremoved,
};
#[cfg(test)]

View file

@ -15,6 +15,17 @@ pub fn is_repo(repo_path: &str) -> bool {
.is_ok()
}
/// checks if the git repo at path `repo_path` is a bare repo
pub fn is_bare_repo(repo_path: &str) -> Result<bool> {
let repo = Repository::open_ext(
repo_path,
RepositoryOpenFlags::empty(),
Vec::<&Path>::new(),
)?;
Ok(repo.is_bare())
}
///
pub fn repo(repo_path: &str) -> Result<Repository> {
let repo = Repository::open_ext(

View file

@ -59,8 +59,8 @@ static SPINNER_INTERVAL: Duration = Duration::from_millis(50);
fn main() -> Result<()> {
process_cmdline()?;
if invalid_path() {
eprintln!("invalid git path\nplease run gitui inside of a git repository");
if !valid_path()? {
eprintln!("invalid git path\nplease run gitui inside of a valid git (non-bare) repository");
return Ok(());
}
@ -149,8 +149,9 @@ fn draw<B: Backend>(
})
}
fn invalid_path() -> bool {
!asyncgit::is_repo(asyncgit::CWD)
fn valid_path() -> Result<bool> {
Ok(asyncgit::sync::is_repo(asyncgit::CWD)
&& !asyncgit::sync::is_bare_repo(asyncgit::CWD)?)
}
fn select_event(