mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
can rest files on index (revert)
This commit is contained in:
parent
278ed70d8d
commit
63785873e4
4 changed files with 62 additions and 19 deletions
|
|
@ -13,7 +13,6 @@ Over the last 2 years my go to GUI tool for this was [fork](https://git-fork.com
|
|||
* [x] (un)stage files
|
||||
* [x] inspect diffs
|
||||
* [x] commit
|
||||
* [ ] reset changes in status
|
||||
* [ ] input polling in thread
|
||||
* [ ] file watcher instead of polling git
|
||||
* [ ] log view
|
||||
|
|
|
|||
49
src/app.rs
49
src/app.rs
|
|
@ -173,14 +173,33 @@ impl App {
|
|||
}
|
||||
|
||||
fn commands(&self) -> Vec<CommandInfo> {
|
||||
let mut res = Vec::new();
|
||||
if !self.commit.is_visible() {
|
||||
vec![CommandInfo {
|
||||
if self.index_wd.focused() {
|
||||
let some_selection =
|
||||
self.index_wd.selection().is_some();
|
||||
res.push(CommandInfo {
|
||||
name: "Stage File [enter]".to_string(),
|
||||
enabled: some_selection,
|
||||
});
|
||||
res.push(CommandInfo {
|
||||
name: "Reset File [D]".to_string(),
|
||||
enabled: some_selection,
|
||||
});
|
||||
} else if self.index.focused() {
|
||||
res.push(CommandInfo {
|
||||
name: "Unstage File [enter]".to_string(),
|
||||
enabled: self.index.selection().is_some(),
|
||||
});
|
||||
}
|
||||
|
||||
res.push(CommandInfo {
|
||||
name: "Quit [esc,q]".to_string(),
|
||||
enabled: true,
|
||||
}]
|
||||
} else {
|
||||
Vec::new()
|
||||
});
|
||||
}
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
///
|
||||
|
|
@ -225,8 +244,14 @@ impl App {
|
|||
self.scroll(false);
|
||||
}
|
||||
|
||||
if ev == Event::Key(KeyCode::Enter.into()) {
|
||||
self.index_add_remove();
|
||||
if let Event::Key(e) = ev {
|
||||
if e.code == KeyCode::Enter {
|
||||
self.index_add_remove();
|
||||
}
|
||||
}
|
||||
|
||||
if ev == Event::Key(KeyCode::Char('D').into()) {
|
||||
self.index_reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -293,6 +318,18 @@ impl App {
|
|||
}
|
||||
}
|
||||
|
||||
fn index_reset(&mut self) {
|
||||
if self.index_wd.focused() {
|
||||
if let Some(i) = self.index_wd.selection() {
|
||||
let path = Path::new(i.path.as_str());
|
||||
|
||||
if git_utils::index_reset(path) {
|
||||
self.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn scroll(&mut self, inc: bool) {
|
||||
if inc {
|
||||
self.offset =
|
||||
|
|
|
|||
|
|
@ -86,16 +86,10 @@ impl Component for IndexComponent {
|
|||
|
||||
fn commands(&self) -> Vec<CommandInfo> {
|
||||
if self.focused {
|
||||
return vec![
|
||||
CommandInfo {
|
||||
name: "Scroll [↑↓]".to_string(),
|
||||
enabled: self.items.len() > 0,
|
||||
},
|
||||
CommandInfo {
|
||||
name: "Stage File [enter]".to_string(),
|
||||
enabled: self.selection.is_some(),
|
||||
},
|
||||
];
|
||||
return vec![CommandInfo {
|
||||
name: "Scroll [↑↓]".to_string(),
|
||||
enabled: self.items.len() > 0,
|
||||
}];
|
||||
}
|
||||
|
||||
Vec::new()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use git2::{
|
||||
DiffFormat, DiffOptions, IndexAddOption, ObjectType, Repository,
|
||||
StatusOptions, StatusShow,
|
||||
build::CheckoutBuilder, DiffFormat, DiffOptions, IndexAddOption,
|
||||
ObjectType, Repository, StatusOptions, StatusShow,
|
||||
};
|
||||
use std::path::Path;
|
||||
|
||||
|
|
@ -178,3 +178,16 @@ pub fn stage_reset(path: &Path) -> bool {
|
|||
|
||||
false
|
||||
}
|
||||
|
||||
pub fn index_reset(path: &Path) -> bool {
|
||||
let repo = repo();
|
||||
|
||||
let mut checkout_opts = CheckoutBuilder::new();
|
||||
checkout_opts.path(&path).force();
|
||||
|
||||
if let Ok(_) = repo.checkout_head(Some(&mut checkout_opts)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue