Skip to content

Commit 45d6448

Browse files
author
Stephan Dilly
committed
honor options in stage_all command (see #933)
1 parent 69d09c4 commit 45d6448

File tree

5 files changed

+34
-12
lines changed

5 files changed

+34
-12
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- add highlighting matches in fuzzy finder ([#893](https://github.com/extrawurst/gitui/issues/893))
1414
- support `home` and `end` keys in branchlist ([#957](https://github.com/extrawurst/gitui/issues/957))
1515

16+
## Fixed
17+
- honor options (for untracked files) in `stage_all` command ([#933](https://github.com/extrawurst/gitui/issues/933))
18+
1619
## [0.18] - 2021-10-11
1720

1821
**rebase merge with conflicts**

asyncgit/src/sync/reset.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ mod tests {
167167
.write_all(b"file3")?;
168168
}
169169

170-
stage_add_all(repo_path, "*").unwrap();
170+
stage_add_all(repo_path, "*", None).unwrap();
171171
commit(repo_path, "msg").unwrap();
172172

173173
{

asyncgit/src/sync/utils.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! sync git api (various methods)
22
3-
use super::CommitId;
3+
use super::{CommitId, ShowUntrackedFilesConfig};
44
use crate::{
55
error::{Error, Result},
66
sync::config::untracked_files_config_repo,
@@ -125,23 +125,31 @@ pub fn stage_add_file(repo_path: &str, path: &Path) -> Result<()> {
125125
}
126126

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

131135
let repo = repo(repo_path)?;
132136

133137
let mut index = repo.index()?;
134138

135-
let config = untracked_files_config_repo(&repo)?;
136-
137-
if config.include_none() {
138-
index.update_all(vec![pattern], None)?;
139+
let stage_untracked = if let Some(config) = stage_untracked {
140+
config
139141
} else {
142+
untracked_files_config_repo(&repo)?
143+
};
144+
145+
if stage_untracked.include_untracked() {
140146
index.add_all(
141147
vec![pattern],
142148
IndexAddOption::DEFAULT,
143149
None,
144150
)?;
151+
} else {
152+
index.update_all(vec![pattern], None)?;
145153
}
146154

147155
index.write()?;
@@ -291,7 +299,7 @@ mod tests {
291299

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

294-
stage_add_all(repo_path, "a/d").unwrap();
302+
stage_add_all(repo_path, "a/d", None).unwrap();
295303

296304
assert_eq!(status_count(StatusType::WorkingDir), 1);
297305
assert_eq!(status_count(StatusType::Stage), 2);
@@ -354,7 +362,7 @@ mod tests {
354362

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

357-
stage_add_all(repo_path, "*").unwrap();
365+
stage_add_all(repo_path, "*", None).unwrap();
358366

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

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

422430
//expect to fail
423-
assert!(stage_add_all(repo_path, "sub").is_err());
431+
assert!(stage_add_all(repo_path, "sub", None).is_err());
424432

425433
Ok(())
426434
}

src/components/changes.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::{
22
filetree::FileTreeComponent,
33
utils::filetree::{FileTreeItem, FileTreeItemKind},
4-
CommandBlocking, DrawableComponent,
4+
CommandBlocking, DrawableComponent, SharedOptions,
55
};
66
use crate::{
77
components::{CommandInfo, Component, EventState},
@@ -22,6 +22,7 @@ pub struct ChangesComponent {
2222
is_working_dir: bool,
2323
queue: Queue,
2424
key_config: SharedKeyConfig,
25+
options: SharedOptions,
2526
}
2627

2728
impl ChangesComponent {
@@ -33,6 +34,7 @@ impl ChangesComponent {
3334
queue: Queue,
3435
theme: SharedTheme,
3536
key_config: SharedKeyConfig,
37+
options: SharedOptions,
3638
) -> Self {
3739
Self {
3840
files: FileTreeComponent::new(
@@ -45,6 +47,7 @@ impl ChangesComponent {
4547
is_working_dir,
4648
queue,
4749
key_config,
50+
options,
4851
}
4952
}
5053

@@ -95,10 +98,14 @@ impl ChangesComponent {
9598
return Ok(true);
9699
}
97100

101+
let config =
102+
self.options.borrow().status_show_untracked;
103+
98104
//TODO: check if we can handle the one file case with it aswell
99105
sync::stage_add_all(
100106
CWD,
101107
tree_item.info.full_path.as_str(),
108+
config,
102109
)?;
103110

104111
return Ok(true);
@@ -113,7 +120,9 @@ impl ChangesComponent {
113120
}
114121

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

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

src/tabs/status.rs

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ impl Status {
164164
queue.clone(),
165165
theme.clone(),
166166
key_config.clone(),
167+
options.clone(),
167168
),
168169
index: ChangesComponent::new(
169170
&strings::title_index(&key_config),
@@ -172,6 +173,7 @@ impl Status {
172173
queue.clone(),
173174
theme.clone(),
174175
key_config.clone(),
176+
options.clone(),
175177
),
176178
diff: DiffComponent::new(
177179
queue.clone(),

0 commit comments

Comments
 (0)