diff --git a/CHANGELOG.md b/CHANGELOG.md index c3e31f3b..effeb5e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 7e9a9756..e4fe1abc 100644 --- a/README.md +++ b/README.md @@ -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)) diff --git a/asyncgit/src/lib.rs b/asyncgit/src/lib.rs index 27086d69..689fa33f 100644 --- a/asyncgit/src/lib.rs +++ b/asyncgit/src/lib.rs @@ -19,7 +19,6 @@ pub use crate::{ sync::{ diff::{DiffLine, DiffLineType, FileDiff}, status::{StatusItem, StatusItemType}, - utils::is_repo, }, }; use std::{ diff --git a/asyncgit/src/sync/mod.rs b/asyncgit/src/sync/mod.rs index e7c90942..456be51c 100644 --- a/asyncgit/src/sync/mod.rs +++ b/asyncgit/src/sync/mod.rs @@ -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)] diff --git a/asyncgit/src/sync/utils.rs b/asyncgit/src/sync/utils.rs index 3d9ef85e..5509fb6c 100644 --- a/asyncgit/src/sync/utils.rs +++ b/asyncgit/src/sync/utils.rs @@ -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 { + let repo = Repository::open_ext( + repo_path, + RepositoryOpenFlags::empty(), + Vec::<&Path>::new(), + )?; + + Ok(repo.is_bare()) +} + /// pub fn repo(repo_path: &str) -> Result { let repo = Repository::open_ext( diff --git a/src/main.rs b/src/main.rs index 6475178b..4a0a19ac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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( }) } -fn invalid_path() -> bool { - !asyncgit::is_repo(asyncgit::CWD) +fn valid_path() -> Result { + Ok(asyncgit::sync::is_repo(asyncgit::CWD) + && !asyncgit::sync::is_bare_repo(asyncgit::CWD)?) } fn select_event(