Skip to content

Commit dbd7dd3

Browse files
author
Stephan Dilly
committed
support Stage all/Unstage all (closes #82)
1 parent 0bf1833 commit dbd7dd3

File tree

5 files changed

+58
-4
lines changed

5 files changed

+58
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Changed
1010
- 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))
1111
- `arrow-up`/`down` on bottom/top of status file list switches focus ([#105](https://github.com/extrawurst/gitui/issues/105))
12+
- New `Stage all [a]`/`Unstage all [a]` in changes lists ([#82](https://github.com/extrawurst/gitui/issues/82))
1213

1314
## [0.5.0] - 2020-06-01
1415

asyncgit/src/sync/reset.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use scopetime::scope_time;
55
use std::{fs, path::Path};
66

77
///
8-
pub fn reset_stage(repo_path: &str, path: &Path) -> Result<()> {
8+
pub fn reset_stage(repo_path: &str, path: &str) -> Result<()> {
99
scope_time!("reset_stage");
1010

1111
let repo = repo(repo_path)?;
@@ -299,7 +299,7 @@ mod tests {
299299

300300
assert_eq!(get_statuses(repo_path), (0, 1));
301301

302-
reset_stage(repo_path, file_path).unwrap();
302+
reset_stage(repo_path, file_path.to_str().unwrap()).unwrap();
303303

304304
assert_eq!(get_statuses(repo_path), (1, 0));
305305
}

src/components/changes.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ impl ChangesComponent {
9797
return Ok(true);
9898
}
9999
} else {
100-
let path =
101-
Path::new(tree_item.info.full_path.as_str());
100+
let path = tree_item.info.full_path.as_str();
102101
sync::reset_stage(CWD, path)?;
103102
return Ok(true);
104103
}
@@ -107,6 +106,26 @@ impl ChangesComponent {
107106
Ok(false)
108107
}
109108

109+
fn index_add_all(&mut self) -> Result<()> {
110+
sync::stage_add_all(CWD, "*")?;
111+
112+
self.queue
113+
.borrow_mut()
114+
.push_back(InternalEvent::Update(NeedsUpdate::ALL));
115+
116+
Ok(())
117+
}
118+
119+
fn stage_remove_all(&mut self) -> Result<()> {
120+
sync::reset_stage(CWD, "*")?;
121+
122+
self.queue
123+
.borrow_mut()
124+
.push_back(InternalEvent::Update(NeedsUpdate::ALL));
125+
126+
Ok(())
127+
}
128+
110129
fn dispatch_reset_workdir(&mut self) -> bool {
111130
if let Some(tree_item) = self.selection() {
112131
let is_folder =
@@ -160,6 +179,11 @@ impl Component for ChangesComponent {
160179
let some_selection = self.selection().is_some();
161180

162181
if self.is_working_dir {
182+
out.push(CommandInfo::new(
183+
commands::STAGE_ALL,
184+
some_selection,
185+
self.focused(),
186+
));
163187
out.push(CommandInfo::new(
164188
commands::STAGE_ITEM,
165189
some_selection,
@@ -181,6 +205,11 @@ impl Component for ChangesComponent {
181205
some_selection,
182206
self.focused(),
183207
));
208+
out.push(CommandInfo::new(
209+
commands::UNSTAGE_ALL,
210+
some_selection,
211+
self.focused(),
212+
));
184213
out.push(
185214
CommandInfo::new(
186215
commands::COMMIT_OPEN,
@@ -221,6 +250,17 @@ impl Component for ChangesComponent {
221250
}
222251
Ok(true)
223252
}
253+
254+
keys::STATUS_STAGE_ALL if !self.is_empty() => {
255+
if self.is_working_dir {
256+
self.index_add_all()?;
257+
} else {
258+
self.stage_remove_all()?;
259+
}
260+
261+
Ok(true)
262+
}
263+
224264
keys::STATUS_RESET_FILE
225265
if self.is_working_dir =>
226266
{

src/keys.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub const SHIFT_DOWN: KeyEvent =
4444
with_mod(KeyCode::Down, KeyModifiers::SHIFT);
4545
pub const ENTER: KeyEvent = no_mod(KeyCode::Enter);
4646
pub const STATUS_STAGE_FILE: KeyEvent = no_mod(KeyCode::Enter);
47+
pub const STATUS_STAGE_ALL: KeyEvent = no_mod(KeyCode::Char('a'));
4748
pub const STATUS_RESET_FILE: KeyEvent =
4849
with_mod(KeyCode::Char('D'), KeyModifiers::SHIFT);
4950
pub const STATUS_IGNORE_FILE: KeyEvent = no_mod(KeyCode::Char('i'));

src/strings.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,24 @@ pub mod commands {
140140
CMD_GROUP_CHANGES,
141141
);
142142
///
143+
pub static STAGE_ALL: CommandText = CommandText::new(
144+
"Stage All [a]",
145+
"stage all changes (in unstaged files)",
146+
CMD_GROUP_CHANGES,
147+
);
148+
///
143149
pub static UNSTAGE_ITEM: CommandText = CommandText::new(
144150
"Unstage Item [enter]",
145151
"unstage currently selected file or entire path",
146152
CMD_GROUP_CHANGES,
147153
);
148154
///
155+
pub static UNSTAGE_ALL: CommandText = CommandText::new(
156+
"Unstage all [a]",
157+
"unstage all files (in staged files)",
158+
CMD_GROUP_CHANGES,
159+
);
160+
///
149161
pub static RESET_ITEM: CommandText = CommandText::new(
150162
"Reset Item [D]",
151163
"revert changes in selected file or entire path",

0 commit comments

Comments
 (0)