Skip to content

Commit 2916a78

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

File tree

2 files changed

+27
-7
lines changed

2 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: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,24 +159,37 @@ 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+
use gix::status::UntrackedFiles;
165+
166+
match value {
167+
ShowUntrackedFilesConfig::All => UntrackedFiles::Files,
168+
ShowUntrackedFilesConfig::Normal => {
169+
UntrackedFiles::Collapsed
170+
}
171+
ShowUntrackedFilesConfig::No => UntrackedFiles::None,
172+
}
173+
}
174+
}
175+
162176
/// guarantees sorting
163177
pub fn get_status(
164178
repo_path: &RepoPath,
165179
status_type: StatusType,
166-
_show_untracked: Option<ShowUntrackedFilesConfig>,
180+
show_untracked: Option<ShowUntrackedFilesConfig>,
167181
) -> Result<Vec<StatusItem>> {
168182
scope_time!("get_status");
169183

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

177-
let status = repo
178-
.status(gix::progress::Discard)?
179-
.untracked_files(gix::status::UntrackedFiles::Files);
188+
let mut status = repo.status(gix::progress::Discard)?;
189+
190+
if let Some(config) = show_untracked {
191+
status = status.untracked_files(config.into());
192+
}
180193

181194
let mut res = Vec::new();
182195

0 commit comments

Comments
 (0)