Skip to content

Commit 1a26732

Browse files
committed
assure that we don't artificially make non-recursable directories visible
A repository may be emitted on its own accord, without having to go through the folding logic which filters directories that have been 'prefix' matched.
1 parent e944e74 commit 1a26732

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
lines changed

gix-dir/src/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl Status {
191191
}
192192

193193
impl Kind {
194-
fn is_recursable_dir(&self) -> bool {
194+
pub(super) fn is_recursable_dir(&self) -> bool {
195195
matches!(self, Kind::Directory)
196196
}
197197

gix-dir/src/walk/classify.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,6 @@ pub fn path(
253253
.map_err(Error::ExcludesAccess)?
254254
{
255255
if emit_ignored.is_some() {
256-
if kind.map_or(false, |d| d.is_dir()) && out.pathspec_match.is_none() {
257-
// we have patterns that didn't match at all. Try harder.
258-
out.pathspec_match = ctx
259-
.pathspec
260-
.directory_matches_prefix(rela_path.as_bstr(), true)
261-
.then_some(PathspecMatch::Prefix);
262-
}
263256
if matches!(
264257
for_deletion,
265258
Some(
@@ -275,6 +268,10 @@ pub fn path(
275268
),
276269
);
277270
}
271+
if kind.map_or(false, |d| d.is_recursable_dir()) && out.pathspec_match.is_none() {
272+
// we have patterns that didn't match at all, *yet*. We want to look inside.
273+
out.pathspec_match = Some(PathspecMatch::Prefix);
274+
}
278275
}
279276
return Ok(out
280277
.with_status(entry::Status::Ignored(excluded))

gix-dir/tests/fixtures/many.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ git init partial-checkout-non-cone
159159
mkdir d && touch d/file-created-manually
160160
)
161161

162+
git init precious-nested-repository
163+
(cd precious-nested-repository
164+
echo '$precious*/' > .gitignore
165+
git init precious-repo
166+
git add .gitignore && git commit -m "init"
167+
)
168+
162169
git init only-untracked
163170
(cd only-untracked
164171
>a

gix-dir/tests/walk/mod.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,38 @@ fn untracked_and_ignored_for_deletion_nonmatching_wildcard_spec() -> crate::Resu
12081208
);
12091209
Ok(())
12101210
}
1211+
#[test]
1212+
fn nested_precious_repo_respects_wildcards() -> crate::Result {
1213+
let root = fixture("precious-nested-repository");
1214+
for for_deletion in [
1215+
Some(ForDeletionMode::FindNonBareRepositoriesInIgnoredDirectories),
1216+
Some(ForDeletionMode::FindRepositoriesInIgnoredDirectories),
1217+
] {
1218+
let (_out, entries) = collect_filtered(
1219+
&root,
1220+
None,
1221+
|keep, ctx| {
1222+
walk(
1223+
&root,
1224+
ctx,
1225+
walk::Options {
1226+
emit_ignored: Some(CollapseDirectory),
1227+
emit_untracked: CollapseDirectory,
1228+
emit_pruned: false,
1229+
for_deletion,
1230+
..options()
1231+
},
1232+
keep,
1233+
)
1234+
},
1235+
Some("*foo/"),
1236+
);
1237+
// NOTE: do not use `_out` as `.git` directory contents can change, it's controlled by Git, causing flakiness.
1238+
1239+
assert_eq!(entries, [], "nothing matches, of course");
1240+
}
1241+
Ok(())
1242+
}
12111243

12121244
#[test]
12131245
fn nested_ignored_dirs_for_deletion_nonmatching_wildcard_spec() -> crate::Result {

0 commit comments

Comments
 (0)