Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions gix-dir/src/walk/readdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,11 @@ impl Mark {
filter_dir_pathspec(dir_info.pathspec_match)
});

// If every collapsed entry is itself an empty directory, the collapsed directory has no files
// to track. Keep the `EmptyDirectory` property so callers that skip empty directories by
// default (such as `gix status`) behave like Git, which treats a tree of only empty
// directories as clean. See https://github.com/GitoxideLabs/gitoxide/issues/2490.
// If every untracked collapsed entry is itself an empty directory, the collapsed directory has
// no files to track: ignored entries beside them don't change that. Keep the `EmptyDirectory`
// property so callers that skip empty directories by default (such as `gix status`) behave like
// Git, which treats a tree of only empty directories and ignored files as clean.
// See https://github.com/GitoxideLabs/gitoxide/issues/2490.
//
// Restricted to untracked collapses in non-deletion walks: deletion has its own handling of
// empty directories, and an explicitly requested *ignored* directory must stay observable even
Expand All @@ -409,6 +410,7 @@ impl Mark {
&& matches!(dir_status, entry::Status::Untracked)
&& state.on_hold[self.start_index..]
.iter()
.filter(|entry| entry.status == entry::Status::Untracked)
.all(|entry| entry.property == Some(entry::Property::EmptyDirectory)))
Comment on lines +413 to 414

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep requested ignored entries observable

When ignored output is enabled while untracked entries are collapsed (the normal gix status --ignored combination), a directory like file-and-empty has an ignored file plus an untracked EmptyDirectory; this filter removes the file from the check, marks the parent empty, drains both children with the default emit_collapsed = None, and emit_entry() suppresses the parent because empty-directory emission is off. The CLI help says --ignored will “show ignored files and directories” (src/plumbing/options/mod.rs:593-595), but this case now yields no entry, so preserve the ignored side whenever it was requested.

Useful? React with 👍 / 👎.

.then_some(entry::Property::EmptyDirectory);

Expand Down
47 changes: 47 additions & 0 deletions gix-dir/tests/dir/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,53 @@ fn complex_empty() -> TestResult {
Ok(())
}

#[test]
fn ignored_entries_dont_make_a_collapsed_directory_of_empty_ones_untracked() -> TestResult {
let root = fixture("ignored-and-empty");
let (_, entries) = collect(&root, None, |keep, ctx| {
walk(
&root,
ctx,
walk::Options {
emit_empty_directories: false,
emit_untracked: CollapseDirectory,
..options()
},
keep,
)
});
assert_eq!(
entries,
&[entry("with-file", Untracked, Directory)],
"directories holding only ignored entries and empty directories have no untracked file, \
and are skipped like a tree of only empty directories, as Git does"
);

let (_, entries) = collect(&root, None, |keep, ctx| {
walk(
&root,
ctx,
walk::Options {
emit_empty_directories: true,
emit_untracked: CollapseDirectory,
..options()
},
keep,
)
});
assert_eq!(
entries,
&[
entry("dir-and-empty", Untracked, Directory).with_property(EmptyDirectory),
entry("file-and-empty", Untracked, Directory).with_property(EmptyDirectory),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Update the empty-directory contract

The newly added file-and-empty case deliberately returns Property::EmptyDirectory even though the fixture creates file-and-empty/a.o; however, the public enum docs still define this property as an empty directory (gix-dir/src/entry.rs:10-11), and the option docs say no nested directory may contain a file (gix-dir/src/walk/mod.rs:182-185, mirrored at gix/src/dirwalk/options.rs:130-132). Consumers asking to emit empty directories now receive metadata that contradicts the contract, so model “no reportable untracked content” separately or update these directly related public docs with the new ignored-file semantics.

AGENTS.md reference: AGENTS.md:L263-L263

Useful? React with 👍 / 👎.

entry("nested", Untracked, Directory).with_property(EmptyDirectory),
entry("with-file", Untracked, Directory),
],
"they collapse as empty directories, and the one with an untracked file as before"
);
Ok(())
}

#[test]
fn ignored_with_prefix_pathspec_collapses_just_like_untracked() -> TestResult {
let root = fixture("untracked-and-ignored-for-collapse");
Expand Down
11 changes: 11 additions & 0 deletions gix-dir/tests/fixtures/many.sh
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,17 @@ mkdir empty-and-untracked-dir
)


git init ignored-and-empty
(cd ignored-and-empty
echo "*.o" >> .gitignore
echo "userdata/" >> .gitignore
git add .gitignore && git commit -m "init"

mkdir -p file-and-empty/empty dir-and-empty/userdata nested/ws/userdata nested/ws/shared/empty with-file/empty
touch file-and-empty/a.o dir-and-empty/userdata/state nested/ws/userdata/state with-file/a.o with-file/b
mkdir dir-and-empty/empty
)

mkdir complex-empty
(cd complex-empty
mkdir empty-toplevel
Expand Down
Loading