diff --git a/gix-dir/src/walk/readdir.rs b/gix-dir/src/walk/readdir.rs index fefcc14aef3..3b48ea9c6e3 100644 --- a/gix-dir/src/walk/readdir.rs +++ b/gix-dir/src/walk/readdir.rs @@ -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 @@ -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))) .then_some(entry::Property::EmptyDirectory); diff --git a/gix-dir/tests/dir/walk.rs b/gix-dir/tests/dir/walk.rs index 2241bb52b46..82f1f9859eb 100644 --- a/gix-dir/tests/dir/walk.rs +++ b/gix-dir/tests/dir/walk.rs @@ -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), + 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"); diff --git a/gix-dir/tests/fixtures/many.sh b/gix-dir/tests/fixtures/many.sh index adfd1fff21b..69ee9d5f1ae 100755 --- a/gix-dir/tests/fixtures/many.sh +++ b/gix-dir/tests/fixtures/many.sh @@ -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