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
6 changes: 6 additions & 0 deletions gix-dir/src/walk/readdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,11 @@ impl Mark {
return None;
}

let collapsed_property = state.on_hold[self.start_index..]
.iter()
.all(|entry| entry.property == Some(entry::Property::EmptyDirectory))
.then_some(entry::Property::EmptyDirectory);

// Pathspecs affect the collapse of the next level, hence find the highest-value one.
let dir_pathspec_match = state.on_hold[self.start_index..]
.iter()
Expand Down Expand Up @@ -396,6 +401,7 @@ impl Mark {
Cow::Borrowed(dir_rela_path),
classify::Outcome {
status: dir_status,
property: dir_info.property.or(collapsed_property),
pathspec_match: dir_pathspec_match,
..dir_info
},
Expand Down
2 changes: 1 addition & 1 deletion gix-dir/tests/dir/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ fn complex_empty() -> crate::Result {
&[
entry("dirs-and-files", Untracked, Directory),
entry("empty-toplevel", Untracked, Directory).with_property(EmptyDirectory),
entry("only-dirs", Untracked, Directory),
entry("only-dirs", Untracked, Directory).with_property(EmptyDirectory),
],
"empty directories collapse just fine"
);
Expand Down
9 changes: 9 additions & 0 deletions gix/tests/fixtures/make_status_repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,12 @@ git init -q submodule-assume-unchanged-symlink
rm -Rf sub
ln -s ../module sub
)

git init -q nested-empty-tree
(cd nested-empty-tree
touch tracked
git add tracked
git commit -q -m init

mkdir -p empty/nested
)
19 changes: 19 additions & 0 deletions gix/tests/gix/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,25 @@ mod index_worktree {
Ok(())
}

#[test]
fn nested_empty_directories_are_ignored() -> crate::Result {
let repo = repo("nested-empty-tree")?;
let mut status = repo
.status(gix::progress::Discard)?
.index_worktree_options_mut(|opts| {
opts.sorting =
Some(gix::status::plumbing::index_as_worktree_with_renames::Sorting::ByPathCaseSensitive);
})
.into_index_worktree_iter(None)?;
let items: Vec<_> = status.by_ref().filter_map(Result::ok).collect();
assert_eq!(
items,
[],
"directories that only contain empty subdirectories should not be reported as untracked"
);
Ok(())
}

#[test]
fn untracked_files_collapse_by_default() -> crate::Result {
let repo = repo("untracked-only")?;
Expand Down
Loading