|
1 | 1 | //! sync git api (various methods)
|
2 | 2 |
|
3 |
| -use super::CommitId; |
| 3 | +use super::{CommitId, ShowUntrackedFilesConfig}; |
4 | 4 | use crate::{
|
5 | 5 | error::{Error, Result},
|
6 | 6 | sync::config::untracked_files_config_repo,
|
@@ -125,23 +125,31 @@ pub fn stage_add_file(repo_path: &str, path: &Path) -> Result<()> {
|
125 | 125 | }
|
126 | 126 |
|
127 | 127 | /// 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<()> { |
129 | 133 | scope_time!("stage_add_all");
|
130 | 134 |
|
131 | 135 | let repo = repo(repo_path)?;
|
132 | 136 |
|
133 | 137 | let mut index = repo.index()?;
|
134 | 138 |
|
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 |
139 | 141 | } else {
|
| 142 | + untracked_files_config_repo(&repo)? |
| 143 | + }; |
| 144 | + |
| 145 | + if stage_untracked.include_untracked() { |
140 | 146 | index.add_all(
|
141 | 147 | vec![pattern],
|
142 | 148 | IndexAddOption::DEFAULT,
|
143 | 149 | None,
|
144 | 150 | )?;
|
| 151 | + } else { |
| 152 | + index.update_all(vec![pattern], None)?; |
145 | 153 | }
|
146 | 154 |
|
147 | 155 | index.write()?;
|
@@ -291,7 +299,7 @@ mod tests {
|
291 | 299 |
|
292 | 300 | assert_eq!(status_count(StatusType::WorkingDir), 3);
|
293 | 301 |
|
294 |
| - stage_add_all(repo_path, "a/d").unwrap(); |
| 302 | + stage_add_all(repo_path, "a/d", None).unwrap(); |
295 | 303 |
|
296 | 304 | assert_eq!(status_count(StatusType::WorkingDir), 1);
|
297 | 305 | assert_eq!(status_count(StatusType::Stage), 2);
|
@@ -354,7 +362,7 @@ mod tests {
|
354 | 362 |
|
355 | 363 | assert_eq!(get_statuses(repo_path), (0, 0));
|
356 | 364 |
|
357 |
| - stage_add_all(repo_path, "*").unwrap(); |
| 365 | + stage_add_all(repo_path, "*", None).unwrap(); |
358 | 366 |
|
359 | 367 | assert_eq!(get_statuses(repo_path), (0, 0));
|
360 | 368 |
|
@@ -420,7 +428,7 @@ mod tests {
|
420 | 428 | assert_eq!(status_count(StatusType::WorkingDir), 1);
|
421 | 429 |
|
422 | 430 | //expect to fail
|
423 |
| - assert!(stage_add_all(repo_path, "sub").is_err()); |
| 431 | + assert!(stage_add_all(repo_path, "sub", None).is_err()); |
424 | 432 |
|
425 | 433 | Ok(())
|
426 | 434 | }
|
|
0 commit comments