Skip to content

Commit

Permalink
fix: assure that worktree-roots are never considered ignored (#1458).
Browse files Browse the repository at this point in the history
If they were, they would more easily be deleted by tooling like `gix clean`.
  • Loading branch information
Byron committed Jul 23, 2024
1 parent 1ebd6c7 commit 1e92d1e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 2 additions & 0 deletions gix-dir/src/walk/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ pub fn path(
.map(|platform| platform.excluded_kind())
})
.map_err(Error::ExcludesAccess)?
.filter(|_| filename_start_idx > 0)
{
out.status = entry::Status::Ignored(excluded);
}
Expand Down Expand Up @@ -256,6 +257,7 @@ pub fn path(
if let Some(excluded) = ctx
.excludes
.as_mut()
.filter(|_| !rela_path.is_empty())
.map_or(Ok(None), |stack| {
stack
.at_entry(rela_path.as_bstr(), is_dir, ctx.objects)
Expand Down
24 changes: 13 additions & 11 deletions gix-dir/tests/walk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4285,15 +4285,21 @@ fn top_level_slash_with_negations() -> crate::Result {
assert_eq!(
out,
walk::Outcome {
read_dir_calls: 0,
read_dir_calls: 2,
returned_entries: entries.len(),
seen_entries: 1,
seen_entries: 5,
}
);
assert_eq!(
entries,
&[entry("", Ignored(Expendable), Directory)],
"This is wrong - the root can never be listed"
&[
entry_nokind(".git", Pruned).with_property(DotGit).with_match(Always),
entry(".github/workflow.yml", Tracked, File),
entry(".gitignore", Tracked, File),
entry("file", Untracked, File),
entry("readme.md", Tracked, File),
],
"the top-level is never considered ignored"
);

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

0 comments on commit 1e92d1e

Please sign in to comment.