Skip to content

Commit

Permalink
honor options in stage_all command (see #933)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Dilly committed Oct 23, 2021
1 parent 69d09c4 commit 45d6448
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- add highlighting matches in fuzzy finder ([#893](https://github.com/extrawurst/gitui/issues/893))
- support `home` and `end` keys in branchlist ([#957](https://github.com/extrawurst/gitui/issues/957))

## Fixed
- honor options (for untracked files) in `stage_all` command ([#933](https://github.com/extrawurst/gitui/issues/933))

## [0.18] - 2021-10-11

**rebase merge with conflicts**
Expand Down
2 changes: 1 addition & 1 deletion asyncgit/src/sync/reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ mod tests {
.write_all(b"file3")?;
}

stage_add_all(repo_path, "*").unwrap();
stage_add_all(repo_path, "*", None).unwrap();
commit(repo_path, "msg").unwrap();

{
Expand Down
26 changes: 17 additions & 9 deletions asyncgit/src/sync/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! sync git api (various methods)

use super::CommitId;
use super::{CommitId, ShowUntrackedFilesConfig};
use crate::{
error::{Error, Result},
sync::config::untracked_files_config_repo,
Expand Down Expand Up @@ -125,23 +125,31 @@ pub fn stage_add_file(repo_path: &str, path: &Path) -> Result<()> {
}

/// like `stage_add_file` but uses a pattern to match/glob multiple files/folders
pub fn stage_add_all(repo_path: &str, pattern: &str) -> Result<()> {
pub fn stage_add_all(
repo_path: &str,
pattern: &str,
stage_untracked: Option<ShowUntrackedFilesConfig>,
) -> Result<()> {
scope_time!("stage_add_all");

let repo = repo(repo_path)?;

let mut index = repo.index()?;

let config = untracked_files_config_repo(&repo)?;

if config.include_none() {
index.update_all(vec![pattern], None)?;
let stage_untracked = if let Some(config) = stage_untracked {
config
} else {
untracked_files_config_repo(&repo)?
};

if stage_untracked.include_untracked() {
index.add_all(
vec![pattern],
IndexAddOption::DEFAULT,
None,
)?;
} else {
index.update_all(vec![pattern], None)?;
}

index.write()?;
Expand Down Expand Up @@ -291,7 +299,7 @@ mod tests {

assert_eq!(status_count(StatusType::WorkingDir), 3);

stage_add_all(repo_path, "a/d").unwrap();
stage_add_all(repo_path, "a/d", None).unwrap();

assert_eq!(status_count(StatusType::WorkingDir), 1);
assert_eq!(status_count(StatusType::Stage), 2);
Expand Down Expand Up @@ -354,7 +362,7 @@ mod tests {

assert_eq!(get_statuses(repo_path), (0, 0));

stage_add_all(repo_path, "*").unwrap();
stage_add_all(repo_path, "*", None).unwrap();

assert_eq!(get_statuses(repo_path), (0, 0));

Expand Down Expand Up @@ -420,7 +428,7 @@ mod tests {
assert_eq!(status_count(StatusType::WorkingDir), 1);

//expect to fail
assert!(stage_add_all(repo_path, "sub").is_err());
assert!(stage_add_all(repo_path, "sub", None).is_err());

Ok(())
}
Expand Down
13 changes: 11 additions & 2 deletions src/components/changes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{
filetree::FileTreeComponent,
utils::filetree::{FileTreeItem, FileTreeItemKind},
CommandBlocking, DrawableComponent,
CommandBlocking, DrawableComponent, SharedOptions,
};
use crate::{
components::{CommandInfo, Component, EventState},
Expand All @@ -22,6 +22,7 @@ pub struct ChangesComponent {
is_working_dir: bool,
queue: Queue,
key_config: SharedKeyConfig,
options: SharedOptions,
}

impl ChangesComponent {
Expand All @@ -33,6 +34,7 @@ impl ChangesComponent {
queue: Queue,
theme: SharedTheme,
key_config: SharedKeyConfig,
options: SharedOptions,
) -> Self {
Self {
files: FileTreeComponent::new(
Expand All @@ -45,6 +47,7 @@ impl ChangesComponent {
is_working_dir,
queue,
key_config,
options,
}
}

Expand Down Expand Up @@ -95,10 +98,14 @@ impl ChangesComponent {
return Ok(true);
}

let config =
self.options.borrow().status_show_untracked;

//TODO: check if we can handle the one file case with it aswell
sync::stage_add_all(
CWD,
tree_item.info.full_path.as_str(),
config,
)?;

return Ok(true);
Expand All @@ -113,7 +120,9 @@ impl ChangesComponent {
}

fn index_add_all(&mut self) -> Result<()> {
sync::stage_add_all(CWD, "*")?;
let config = self.options.borrow().status_show_untracked;

sync::stage_add_all(CWD, "*", config)?;

self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));

Expand Down
2 changes: 2 additions & 0 deletions src/tabs/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ impl Status {
queue.clone(),
theme.clone(),
key_config.clone(),
options.clone(),
),
index: ChangesComponent::new(
&strings::title_index(&key_config),
Expand All @@ -172,6 +173,7 @@ impl Status {
queue.clone(),
theme.clone(),
key_config.clone(),
options.clone(),
),
diff: DiffComponent::new(
queue.clone(),
Expand Down

0 comments on commit 45d6448

Please sign in to comment.