Skip to content

Commit 95d10ee

Browse files
committed
fix: pathspec prefixes still allows directory collapsing.
1 parent bb48c4c commit 95d10ee

File tree

3 files changed

+79
-2
lines changed

3 files changed

+79
-2
lines changed

gix-dir/src/walk/readdir.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,10 @@ impl Mark {
210210
} else {
211211
dir_info.disk_kind
212212
},
213-
pathspec_match: filter_dir_pathspec(dir_info.pathspec_match),
213+
pathspec_match: ctx
214+
.pathspec
215+
.pattern_matching_relative_path(dir_rela_path, Some(true), ctx.pathspec_attributes)
216+
.map(|m| m.kind.into()),
214217
..dir_info
215218
};
216219
if opts.should_hold(empty_info.status) {

gix-dir/tests/fixtures/many.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ mkdir untracked-and-ignored-for-collapse
201201
echo "ignored/" >> .gitignore
202202
echo "*.o" >> .gitignore
203203

204-
mkdir untracked ignored mixed ignored-inside
204+
mkdir -p untracked ignored/empty mixed ignored-inside
205205
touch untracked/a ignored/b mixed/c mixed/c.o ignored-inside/d.o
206206
)
207207

gix-dir/tests/walk/mod.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,80 @@ fn complex_empty() -> crate::Result {
168168
Ok(())
169169
}
170170

171+
#[test]
172+
fn ignored_with_prefix_pathspec_collapses_just_like_untracked() -> crate::Result {
173+
let root = fixture("untracked-and-ignored-for-collapse");
174+
let ((out, _root), entries) = collect_filtered(
175+
&root,
176+
None,
177+
|keep, ctx| {
178+
walk(
179+
&root,
180+
ctx,
181+
walk::Options {
182+
for_deletion: Some(Default::default()),
183+
emit_untracked: CollapseDirectory,
184+
emit_ignored: Some(CollapseDirectory),
185+
..options()
186+
},
187+
keep,
188+
)
189+
},
190+
["untracked", "no-match"],
191+
);
192+
193+
assert_eq!(
194+
out,
195+
walk::Outcome {
196+
read_dir_calls: 2,
197+
returned_entries: entries.len(),
198+
seen_entries: 6,
199+
}
200+
);
201+
assert_eq!(
202+
entries,
203+
[entryps("untracked", Untracked, Directory, Prefix)],
204+
"prefix matches allow untracked directories to collapse"
205+
);
206+
207+
let ((out, _root), entries) = collect_filtered(
208+
&root,
209+
None,
210+
|keep, ctx| {
211+
walk(
212+
&root,
213+
ctx,
214+
walk::Options {
215+
for_deletion: Some(Default::default()),
216+
emit_untracked: CollapseDirectory,
217+
emit_ignored: Some(CollapseDirectory),
218+
..options()
219+
},
220+
keep,
221+
)
222+
},
223+
["ignored", "ignored-inside"],
224+
);
225+
226+
assert_eq!(
227+
out,
228+
walk::Outcome {
229+
read_dir_calls: 4,
230+
returned_entries: entries.len(),
231+
seen_entries: 8,
232+
}
233+
);
234+
assert_eq!(
235+
entries,
236+
[
237+
entryps("ignored", Ignored(Expendable), Directory, Prefix),
238+
entryps("ignored-inside", Ignored(Expendable), Directory, Prefix)
239+
],
240+
"prefix matches allow ignored directories to collapse as well"
241+
);
242+
Ok(())
243+
}
244+
171245
#[test]
172246
fn only_untracked_with_cwd_handling() -> crate::Result {
173247
let root = fixture("only-untracked");

0 commit comments

Comments
 (0)