Skip to content

Commit

Permalink
support Stage all/Unstage all (closes #82)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Dilly committed Jun 2, 2020
1 parent 0bf1833 commit dbd7dd3
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions asyncgit/src/sync/reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -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));
}
Expand Down
44 changes: 42 additions & 2 deletions src/components/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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 =
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 =>
{
Expand Down
1 change: 1 addition & 0 deletions src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
12 changes: 12 additions & 0 deletions src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit dbd7dd3

Please sign in to comment.