From dbd7dd33ea119889e1e42f0198e30d59dd3413ec Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Tue, 2 Jun 2020 16:01:54 +0200 Subject: [PATCH] support `Stage all`/`Unstage all` (closes #82) --- CHANGELOG.md | 1 + asyncgit/src/sync/reset.rs | 4 ++-- src/components/changes.rs | 44 ++++++++++++++++++++++++++++++++++++-- src/keys.rs | 1 + src/strings.rs | 12 +++++++++++ 5 files changed, 58 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31fa5109b1..925091e5e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - changed hotkeys for selecting stage/workdir (**[w] / [s]** now to change between workdir and stage) and added hotkeys (`[1234]`) to switch to tabs directly ([#92](https://github.com/extrawurst/gitui/issues/92)) - `arrow-up`/`down` on bottom/top of status file list switches focus ([#105](https://github.com/extrawurst/gitui/issues/105)) +- New `Stage all [a]`/`Unstage all [a]` in changes lists ([#82](https://github.com/extrawurst/gitui/issues/82)) ## [0.5.0] - 2020-06-01 diff --git a/asyncgit/src/sync/reset.rs b/asyncgit/src/sync/reset.rs index 870dbecad9..7f04082d9f 100644 --- a/asyncgit/src/sync/reset.rs +++ b/asyncgit/src/sync/reset.rs @@ -5,7 +5,7 @@ use scopetime::scope_time; use std::{fs, path::Path}; /// -pub fn reset_stage(repo_path: &str, path: &Path) -> Result<()> { +pub fn reset_stage(repo_path: &str, path: &str) -> Result<()> { scope_time!("reset_stage"); let repo = repo(repo_path)?; @@ -299,7 +299,7 @@ mod tests { assert_eq!(get_statuses(repo_path), (0, 1)); - reset_stage(repo_path, file_path).unwrap(); + reset_stage(repo_path, file_path.to_str().unwrap()).unwrap(); assert_eq!(get_statuses(repo_path), (1, 0)); } diff --git a/src/components/changes.rs b/src/components/changes.rs index 2584510658..60a71ac568 100644 --- a/src/components/changes.rs +++ b/src/components/changes.rs @@ -97,8 +97,7 @@ impl ChangesComponent { return Ok(true); } } else { - let path = - Path::new(tree_item.info.full_path.as_str()); + let path = tree_item.info.full_path.as_str(); sync::reset_stage(CWD, path)?; return Ok(true); } @@ -107,6 +106,26 @@ impl ChangesComponent { Ok(false) } + fn index_add_all(&mut self) -> Result<()> { + sync::stage_add_all(CWD, "*")?; + + self.queue + .borrow_mut() + .push_back(InternalEvent::Update(NeedsUpdate::ALL)); + + Ok(()) + } + + fn stage_remove_all(&mut self) -> Result<()> { + sync::reset_stage(CWD, "*")?; + + self.queue + .borrow_mut() + .push_back(InternalEvent::Update(NeedsUpdate::ALL)); + + Ok(()) + } + fn dispatch_reset_workdir(&mut self) -> bool { if let Some(tree_item) = self.selection() { let is_folder = @@ -160,6 +179,11 @@ impl Component for ChangesComponent { let some_selection = self.selection().is_some(); if self.is_working_dir { + out.push(CommandInfo::new( + commands::STAGE_ALL, + some_selection, + self.focused(), + )); out.push(CommandInfo::new( commands::STAGE_ITEM, some_selection, @@ -181,6 +205,11 @@ impl Component for ChangesComponent { some_selection, self.focused(), )); + out.push(CommandInfo::new( + commands::UNSTAGE_ALL, + some_selection, + self.focused(), + )); out.push( CommandInfo::new( commands::COMMIT_OPEN, @@ -221,6 +250,17 @@ impl Component for ChangesComponent { } Ok(true) } + + keys::STATUS_STAGE_ALL if !self.is_empty() => { + if self.is_working_dir { + self.index_add_all()?; + } else { + self.stage_remove_all()?; + } + + Ok(true) + } + keys::STATUS_RESET_FILE if self.is_working_dir => { diff --git a/src/keys.rs b/src/keys.rs index 09cd642f00..ab18369c84 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -44,6 +44,7 @@ pub const SHIFT_DOWN: KeyEvent = with_mod(KeyCode::Down, KeyModifiers::SHIFT); pub const ENTER: KeyEvent = no_mod(KeyCode::Enter); pub const STATUS_STAGE_FILE: KeyEvent = no_mod(KeyCode::Enter); +pub const STATUS_STAGE_ALL: KeyEvent = no_mod(KeyCode::Char('a')); pub const STATUS_RESET_FILE: KeyEvent = with_mod(KeyCode::Char('D'), KeyModifiers::SHIFT); pub const STATUS_IGNORE_FILE: KeyEvent = no_mod(KeyCode::Char('i')); diff --git a/src/strings.rs b/src/strings.rs index b2fa145c70..0b944f12b7 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -140,12 +140,24 @@ pub mod commands { CMD_GROUP_CHANGES, ); /// + pub static STAGE_ALL: CommandText = CommandText::new( + "Stage All [a]", + "stage all changes (in unstaged files)", + CMD_GROUP_CHANGES, + ); + /// pub static UNSTAGE_ITEM: CommandText = CommandText::new( "Unstage Item [enter]", "unstage currently selected file or entire path", CMD_GROUP_CHANGES, ); /// + pub static UNSTAGE_ALL: CommandText = CommandText::new( + "Unstage all [a]", + "unstage all files (in staged files)", + CMD_GROUP_CHANGES, + ); + /// pub static RESET_ITEM: CommandText = CommandText::new( "Reset Item [D]", "revert changes in selected file or entire path",