From cd2938e9c1fab2d044ebb72960b5775a01bcbe87 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Wed, 18 Mar 2020 11:32:55 +0100 Subject: [PATCH] fix crash when renaming/removing a file --- README.md | 1 - src/app.rs | 11 ++++------- src/git_status.rs | 1 + 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0126630b..1d151059 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/app.rs b/src/app.rs index 11ba65fd..315ba2de 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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(); } } } diff --git a/src/git_status.rs b/src/git_status.rs index 7d4e5eaf..4ac95a43 100644 --- a/src/git_status.rs +++ b/src/git_status.rs @@ -60,6 +60,7 @@ impl StatusLists { StatusOptions::default() .show(show) .include_untracked(true) + .renames_head_to_index(true) .recurse_untracked_dirs(true), )) .unwrap();