fix crash when renaming/removing a file

This commit is contained in:
Stephan Dilly 2020-03-18 11:32:55 +01:00
parent ca6650b9de
commit cd2938e9c1
3 changed files with 5 additions and 8 deletions

View file

@ -20,7 +20,6 @@ Over the last 2 years my go to GUI tool for this was [fork](https://git-fork.com
* [x] show added files on working dir changes
* [x] support committing
* [x] popup centered
* [ ] crash: renamed files cannot be added to index
* [ ] allow selecting/diff index items
* [ ] support unstaging
* [ ] polling in thread

View file

@ -4,6 +4,7 @@ use crate::{
git_utils::{self, Diff, DiffLine, DiffLineType},
};
use crossterm::event::{Event, KeyCode, MouseEvent};
use git2::IndexAddOption;
use std::{borrow::Cow, cmp, path::Path};
use tui::{
backend::Backend,
@ -270,13 +271,9 @@ impl App {
let mut index = repo.index().unwrap();
let path = Path::new(self.status.wt_items[i].path.as_str());
if path.is_file() {
if let Ok(_) = index.add_path(path) {
index.write().unwrap();
self.update();
}
} else {
unimplemented!("can only add files");
if let Ok(_) = index.add_all(path, IndexAddOption::DISABLE_PATHSPEC_MATCH, None) {
index.write().unwrap();
self.update();
}
}
}

View file

@ -60,6 +60,7 @@ impl StatusLists {
StatusOptions::default()
.show(show)
.include_untracked(true)
.renames_head_to_index(true)
.recurse_untracked_dirs(true),
))
.unwrap();