mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 17:08:21 +00:00
fix crash running outside of git repo
This commit is contained in:
parent
923f7a46d6
commit
e51609ed91
4 changed files with 20 additions and 1 deletions
|
|
@ -58,7 +58,6 @@ GITUI_LOGGING=true gitui
|
|||
|
||||
# todo for 0.1 (first release)
|
||||
|
||||
* [ ] fix: run in non-git folder -> crash
|
||||
* [ ] (un)staging selected hunks
|
||||
* [ ] publish as homebrew-tap
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ pub use crate::{
|
|||
sync::{
|
||||
diff::{Diff, DiffLine, DiffLineType},
|
||||
status::{StatusItem, StatusItemType},
|
||||
utils::is_repo,
|
||||
},
|
||||
};
|
||||
use std::{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,16 @@ use git2::{IndexAddOption, Repository, RepositoryOpenFlags};
|
|||
use scopetime::scope_time;
|
||||
use std::path::Path;
|
||||
|
||||
///
|
||||
pub fn is_repo(repo_path: &str) -> bool {
|
||||
Repository::open_ext(
|
||||
repo_path,
|
||||
RepositoryOpenFlags::empty(),
|
||||
Vec::<&Path>::new(),
|
||||
)
|
||||
.is_ok()
|
||||
}
|
||||
|
||||
///
|
||||
pub fn repo(repo_path: &str) -> Repository {
|
||||
let repo = Repository::open_ext(
|
||||
|
|
|
|||
|
|
@ -40,6 +40,11 @@ static TICK_INTERVAL: Duration = Duration::from_secs(5);
|
|||
fn main() -> Result<()> {
|
||||
setup_logging();
|
||||
|
||||
if invalid_path() {
|
||||
eprintln!("invalid git path");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
enable_raw_mode()?;
|
||||
io::stdout().execute(EnterAlternateScreen)?;
|
||||
defer! {
|
||||
|
|
@ -87,6 +92,10 @@ fn main() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn invalid_path() -> bool {
|
||||
!asyncgit::is_repo(asyncgit::CWD)
|
||||
}
|
||||
|
||||
fn select_event(
|
||||
rx_input: &Receiver<Vec<QueueEvent>>,
|
||||
rx_git: &Receiver<AsyncNotification>,
|
||||
|
|
|
|||
Loading…
Reference in a new issue