Skip to content

Commit

Permalink
assure that we don't artificially make non-recursable directories vis…
Browse files Browse the repository at this point in the history
…ible

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.
  • Loading branch information
Byron committed Feb 24, 2024
1 parent e944e74 commit 1a26732
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gix-dir/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl Status {
}

impl Kind {
fn is_recursable_dir(&self) -> bool {
pub(super) fn is_recursable_dir(&self) -> bool {
matches!(self, Kind::Directory)
}

Expand Down
11 changes: 4 additions & 7 deletions gix-dir/src/walk/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,6 @@ pub fn path(
.map_err(Error::ExcludesAccess)?
{
if emit_ignored.is_some() {
if kind.map_or(false, |d| d.is_dir()) && out.pathspec_match.is_none() {
// we have patterns that didn't match at all. Try harder.
out.pathspec_match = ctx
.pathspec
.directory_matches_prefix(rela_path.as_bstr(), true)
.then_some(PathspecMatch::Prefix);
}
if matches!(
for_deletion,
Some(
Expand All @@ -275,6 +268,10 @@ pub fn path(
),
);
}
if kind.map_or(false, |d| d.is_recursable_dir()) && out.pathspec_match.is_none() {
// we have patterns that didn't match at all, *yet*. We want to look inside.
out.pathspec_match = Some(PathspecMatch::Prefix);
}
}
return Ok(out
.with_status(entry::Status::Ignored(excluded))
Expand Down
7 changes: 7 additions & 0 deletions gix-dir/tests/fixtures/many.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ git init partial-checkout-non-cone
mkdir d && touch d/file-created-manually
)

git init precious-nested-repository
(cd precious-nested-repository
echo '$precious*/' > .gitignore
git init precious-repo
git add .gitignore && git commit -m "init"
)

git init only-untracked
(cd only-untracked
>a
Expand Down
32 changes: 32 additions & 0 deletions gix-dir/tests/walk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,38 @@ fn untracked_and_ignored_for_deletion_nonmatching_wildcard_spec() -> crate::Resu
);
Ok(())
}
#[test]
fn nested_precious_repo_respects_wildcards() -> crate::Result {
let root = fixture("precious-nested-repository");
for for_deletion in [
Some(ForDeletionMode::FindNonBareRepositoriesInIgnoredDirectories),
Some(ForDeletionMode::FindRepositoriesInIgnoredDirectories),
] {
let (_out, entries) = collect_filtered(
&root,
None,
|keep, ctx| {
walk(
&root,
ctx,
walk::Options {
emit_ignored: Some(CollapseDirectory),
emit_untracked: CollapseDirectory,
emit_pruned: false,
for_deletion,
..options()
},
keep,
)
},
Some("*foo/"),
);
// NOTE: do not use `_out` as `.git` directory contents can change, it's controlled by Git, causing flakiness.

assert_eq!(entries, [], "nothing matches, of course");
}
Ok(())
}

#[test]
fn nested_ignored_dirs_for_deletion_nonmatching_wildcard_spec() -> crate::Result {
Expand Down

0 comments on commit 1a26732

Please sign in to comment.