honor options in stage_all command (see #933)

This commit is contained in:
Stephan Dilly 2021-10-23 15:34:49 +02:00
parent 5c661be159
commit 389bd75d46
5 changed files with 34 additions and 12 deletions

View file

@ -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)) - 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)) - 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 ## [0.18] - 2021-10-11
**rebase merge with conflicts** **rebase merge with conflicts**

View file

@ -167,7 +167,7 @@ mod tests {
.write_all(b"file3")?; .write_all(b"file3")?;
} }
stage_add_all(repo_path, "*").unwrap(); stage_add_all(repo_path, "*", None).unwrap();
commit(repo_path, "msg").unwrap(); commit(repo_path, "msg").unwrap();
{ {

View file

@ -1,6 +1,6 @@
//! sync git api (various methods) //! sync git api (various methods)
use super::CommitId; use super::{CommitId, ShowUntrackedFilesConfig};
use crate::{ use crate::{
error::{Error, Result}, error::{Error, Result},
sync::config::untracked_files_config_repo, sync::config::untracked_files_config_repo,
@ -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 /// 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"); scope_time!("stage_add_all");
let repo = repo(repo_path)?; let repo = repo(repo_path)?;
let mut index = repo.index()?; let mut index = repo.index()?;
let config = untracked_files_config_repo(&repo)?; let stage_untracked = if let Some(config) = stage_untracked {
config
if config.include_none() {
index.update_all(vec![pattern], None)?;
} else { } else {
untracked_files_config_repo(&repo)?
};
if stage_untracked.include_untracked() {
index.add_all( index.add_all(
vec![pattern], vec![pattern],
IndexAddOption::DEFAULT, IndexAddOption::DEFAULT,
None, None,
)?; )?;
} else {
index.update_all(vec![pattern], None)?;
} }
index.write()?; index.write()?;
@ -291,7 +299,7 @@ mod tests {
assert_eq!(status_count(StatusType::WorkingDir), 3); 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::WorkingDir), 1);
assert_eq!(status_count(StatusType::Stage), 2); assert_eq!(status_count(StatusType::Stage), 2);
@ -354,7 +362,7 @@ mod tests {
assert_eq!(get_statuses(repo_path), (0, 0)); 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)); assert_eq!(get_statuses(repo_path), (0, 0));
@ -420,7 +428,7 @@ mod tests {
assert_eq!(status_count(StatusType::WorkingDir), 1); assert_eq!(status_count(StatusType::WorkingDir), 1);
//expect to fail //expect to fail
assert!(stage_add_all(repo_path, "sub").is_err()); assert!(stage_add_all(repo_path, "sub", None).is_err());
Ok(()) Ok(())
} }

View file

@ -1,7 +1,7 @@
use super::{ use super::{
filetree::FileTreeComponent, filetree::FileTreeComponent,
utils::filetree::{FileTreeItem, FileTreeItemKind}, utils::filetree::{FileTreeItem, FileTreeItemKind},
CommandBlocking, DrawableComponent, CommandBlocking, DrawableComponent, SharedOptions,
}; };
use crate::{ use crate::{
components::{CommandInfo, Component, EventState}, components::{CommandInfo, Component, EventState},
@ -22,6 +22,7 @@ pub struct ChangesComponent {
is_working_dir: bool, is_working_dir: bool,
queue: Queue, queue: Queue,
key_config: SharedKeyConfig, key_config: SharedKeyConfig,
options: SharedOptions,
} }
impl ChangesComponent { impl ChangesComponent {
@ -33,6 +34,7 @@ impl ChangesComponent {
queue: Queue, queue: Queue,
theme: SharedTheme, theme: SharedTheme,
key_config: SharedKeyConfig, key_config: SharedKeyConfig,
options: SharedOptions,
) -> Self { ) -> Self {
Self { Self {
files: FileTreeComponent::new( files: FileTreeComponent::new(
@ -45,6 +47,7 @@ impl ChangesComponent {
is_working_dir, is_working_dir,
queue, queue,
key_config, key_config,
options,
} }
} }
@ -95,10 +98,14 @@ impl ChangesComponent {
return Ok(true); return Ok(true);
} }
let config =
self.options.borrow().status_show_untracked;
//TODO: check if we can handle the one file case with it aswell //TODO: check if we can handle the one file case with it aswell
sync::stage_add_all( sync::stage_add_all(
CWD, CWD,
tree_item.info.full_path.as_str(), tree_item.info.full_path.as_str(),
config,
)?; )?;
return Ok(true); return Ok(true);
@ -113,7 +120,9 @@ impl ChangesComponent {
} }
fn index_add_all(&mut self) -> Result<()> { 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)); self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));

View file

@ -164,6 +164,7 @@ impl Status {
queue.clone(), queue.clone(),
theme.clone(), theme.clone(),
key_config.clone(), key_config.clone(),
options.clone(),
), ),
index: ChangesComponent::new( index: ChangesComponent::new(
&strings::title_index(&key_config), &strings::title_index(&key_config),
@ -172,6 +173,7 @@ impl Status {
queue.clone(), queue.clone(),
theme.clone(), theme.clone(),
key_config.clone(), key_config.clone(),
options.clone(),
), ),
diff: DiffComponent::new( diff: DiffComponent::new(
queue.clone(), queue.clone(),