Skip to content

Commit 432617e

Browse files
committed
fix: assure that worktree-roots are never considered ignored (#1458).
If they were, they would more easily be deleted by tooling like `gix clean`.
1 parent 7c1e027 commit 432617e

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

gix-dir/src/walk/classify.rs

+2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ pub fn path(
169169
.map(|platform| platform.excluded_kind())
170170
})
171171
.map_err(Error::ExcludesAccess)?
172+
.filter(|_| filename_start_idx > 0)
172173
{
173174
out.status = entry::Status::Ignored(excluded);
174175
}
@@ -256,6 +257,7 @@ pub fn path(
256257
if let Some(excluded) = ctx
257258
.excludes
258259
.as_mut()
260+
.filter(|_| !rela_path.is_empty())
259261
.map_or(Ok(None), |stack| {
260262
stack
261263
.at_entry(rela_path.as_bstr(), is_dir, ctx.objects)

gix-dir/tests/walk/mod.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -4285,15 +4285,21 @@ fn top_level_slash_with_negations() -> crate::Result {
42854285
assert_eq!(
42864286
out,
42874287
walk::Outcome {
4288-
read_dir_calls: 0,
4288+
read_dir_calls: 2,
42894289
returned_entries: entries.len(),
4290-
seen_entries: 1,
4290+
seen_entries: 5,
42914291
}
42924292
);
42934293
assert_eq!(
42944294
entries,
4295-
&[entry("", Ignored(Expendable), Directory)],
4296-
"This is wrong - the root can never be listed"
4295+
&[
4296+
entry_nokind(".git", Pruned).with_property(DotGit).with_match(Always),
4297+
entry(".github/workflow.yml", Tracked, File),
4298+
entry(".gitignore", Tracked, File),
4299+
entry("file", Untracked, File),
4300+
entry("readme.md", Tracked, File),
4301+
],
4302+
"the top-level is never considered ignored"
42974303
);
42984304

42994305
let ((out, _root), entries) = collect(&root, None, |keep, ctx| {
@@ -4319,14 +4325,10 @@ fn top_level_slash_with_negations() -> crate::Result {
43194325
assert_eq!(
43204326
entries,
43214327
&[
4322-
entry_nokind(".git", Ignored(Expendable))
4323-
.with_property(DotGit)
4324-
.with_match(Always),
4325-
entry("file", Ignored(Expendable), File)
4328+
entry_nokind(".git", Pruned).with_property(DotGit).with_match(Always),
4329+
entry("file", Untracked, File)
43264330
],
4327-
"This is still wrong, but consistent within what it should do.\
4328-
Top-level `.git` should always be Pruned, even if ignored.\
4329-
Except for `file` which should be untracked."
4331+
"And the negated file is correctly detected as untracked"
43304332
);
43314333
}
43324334
Ok(())

0 commit comments

Comments
 (0)