Skip to content

Commit 1b3694b

Browse files
committed
Take show_untracked into account
1 parent 25d031b commit 1b3694b

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

asyncgit/src/sync/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ pub fn untracked_files_config_repo(
5656
}
5757
}
5858

59+
// This does not reflect how git works according to its docs that say: "If this variable is not
60+
// specified, it defaults to `normal`."
61+
//
62+
// https://git-scm.com/docs/git-config#Documentation/git-config.txt-statusshowUntrackedFiles
63+
//
64+
// Note that this might become less relevant over time as more code gets migrated to `gitoxide`
65+
// because `gitoxide` respects `status.showUntrackedFiles` by default.
5966
Ok(ShowUntrackedFilesConfig::All)
6067
}
6168

asyncgit/src/sync/status.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,24 +159,33 @@ pub fn is_workdir_clean(
159159
Ok(statuses.is_empty())
160160
}
161161

162+
impl From<ShowUntrackedFilesConfig> for gix::status::UntrackedFiles {
163+
fn from(value: ShowUntrackedFilesConfig) -> Self {
164+
match value {
165+
ShowUntrackedFilesConfig::All => Self::Files,
166+
ShowUntrackedFilesConfig::Normal => Self::Collapsed,
167+
ShowUntrackedFilesConfig::No => Self::None,
168+
}
169+
}
170+
}
171+
162172
/// guarantees sorting
163173
pub fn get_status(
164174
repo_path: &RepoPath,
165175
status_type: StatusType,
166-
_show_untracked: Option<ShowUntrackedFilesConfig>,
176+
show_untracked: Option<ShowUntrackedFilesConfig>,
167177
) -> Result<Vec<StatusItem>> {
168178
scope_time!("get_status");
169179

170-
// TODO: take parameter `show_untracked` into account, trying to replicate the existing
171-
// behaviour.
172-
173180
let repo: gix::Repository =
174181
gix::ThreadSafeRepository::discover_with_environment_overrides(repo_path.gitpath())
175182
.map(Into::into)?;
176183

177-
let status = repo
178-
.status(gix::progress::Discard)?
179-
.untracked_files(gix::status::UntrackedFiles::Files);
184+
let mut status = repo.status(gix::progress::Discard)?;
185+
186+
if let Some(config) = show_untracked {
187+
status = status.untracked_files(config.into());
188+
}
180189

181190
let mut res = Vec::new();
182191

asyncgit/src/sync/utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ mod tests {
289289
File::create(root.join(Path::new("a/f3.txt")))?
290290
.write_all(b"foo")?;
291291

292+
repo.config()?.set_str("status.showUntrackedFiles", "all")?;
293+
292294
assert_eq!(status_count(StatusType::WorkingDir), 3);
293295

294296
stage_add_all(repo_path, "a/d", None).unwrap();
@@ -351,6 +353,8 @@ mod tests {
351353
File::create(root.join(Path::new("f3.txt")))?
352354
.write_all(b"foo")?;
353355

356+
repo.config()?.set_str("status.showUntrackedFiles", "all")?;
357+
354358
assert_eq!(get_statuses(repo_path), (3, 0));
355359

356360
repo.config()?.set_str("status.showUntrackedFiles", "no")?;

0 commit comments

Comments
 (0)