Skip to content

Commit 42bbebe

Browse files
committed
further improvements to gix clean
- assure it always signals that the dirwalk is 'for deletion', to have additional CWD checks. - add `--match-entries` flag to apply pathspec later, when filtering entries determined by an unfiltered dirwalk.
1 parent c4bfff3 commit 42bbebe

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

gitoxide-core/src/repository/clean.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ pub(crate) mod function {
6666
match skip_hidden_repositories {
6767
Some(FindRepository::NonBare) => Some(FindNonBareRepositoriesInIgnoredDirectories),
6868
Some(FindRepository::All) => Some(FindRepositoriesInIgnoredDirectories),
69-
None => None,
69+
None => Some(Default::default()),
7070
}
7171
} else {
72-
Some(IgnoredDirectoriesCanHideNestedRepositories)
72+
Some(Default::default())
7373
})
7474
.classify_untracked_bare_repositories(matches!(find_untracked_repositories, FindRepository::All))
7575
.emit_untracked(collapse_directories)
@@ -88,7 +88,7 @@ pub(crate) mod function {
8888
let mut pruned_entries = 0;
8989
let mut saw_ignored_directory = false;
9090
let mut saw_untracked_directory = false;
91-
for (entry, dir_status) in entries.into_iter() {
91+
for (mut entry, dir_status) in entries.into_iter() {
9292
if dir_status.is_some() {
9393
if debug {
9494
writeln!(
@@ -106,16 +106,15 @@ pub(crate) mod function {
106106
.map_or(false, |m| m != gix::dir::entry::PathspecMatch::Excluded);
107107
pruned_entries += usize::from(!pathspec_includes_entry);
108108
if !pathspec_includes_entry && debug {
109-
writeln!(err, "DBG: prune '{}' as it is excluded by pathspec", entry.rela_path).ok();
109+
writeln!(err, "DBG: prune '{}'", entry.rela_path).ok();
110110
}
111111
if entry.status.is_pruned() || !pathspec_includes_entry {
112112
continue;
113113
}
114114

115-
let mut disk_kind = entry.disk_kind.expect("present if not pruned");
116115
let keep = match entry.status {
117-
Status::DotGit | Status::Pruned | Status::TrackedExcluded => {
118-
unreachable!("BUG: Pruned are skipped already as their pathspec is always None")
116+
Status::Pruned => {
117+
unreachable!("BUG: assumption that pruned entries have no pathspec match, but probably not")
119118
}
120119
Status::Tracked => {
121120
unreachable!("BUG: tracked aren't emitted")
@@ -130,6 +129,14 @@ pub(crate) mod function {
130129
}
131130
Status::Untracked => true,
132131
};
132+
if entry.disk_kind.is_none() {
133+
entry.disk_kind = workdir
134+
.join(gix::path::from_bstr(entry.rela_path.as_bstr()))
135+
.metadata()
136+
.ok()
137+
.map(|e| e.file_type().into());
138+
}
139+
let mut disk_kind = entry.disk_kind.expect("present if not pruned");
133140
if !keep {
134141
if debug {
135142
writeln!(err, "DBG: prune '{}' as -x or -p is missing", entry.rela_path).ok();
@@ -148,7 +155,7 @@ pub(crate) mod function {
148155

149156
match disk_kind {
150157
Kind::File | Kind::Symlink => {}
151-
Kind::EmptyDirectory | Kind::Directory => {
158+
Kind::Directory => {
152159
if !directories {
153160
skipped_directories += 1;
154161
if debug {
@@ -202,15 +209,15 @@ pub(crate) mod function {
202209
},
203210
maybe = if execute { "removing" } else { "WOULD remove" },
204211
suffix = match disk_kind {
205-
Kind::File | Kind::Symlink | Kind::Directory => {
206-
""
207-
}
208-
Kind::EmptyDirectory => {
212+
Kind::Directory if entry.flags.contains(gix::dir::entry::Flags::EMPTY_DIRECTORY) => {
209213
" empty"
210214
}
211215
Kind::Repository => {
212216
" repository"
213217
}
218+
Kind::File | Kind::Symlink | Kind::Directory => {
219+
""
220+
}
214221
},
215222
)?;
216223

@@ -256,7 +263,7 @@ pub(crate) mod function {
256263
}));
257264
messages.extend((pruned_entries > 0 && has_patterns).then(|| {
258265
format!(
259-
"try to adjust your pathspec to reveal some of the {pruned_entries} pruned {entries}",
266+
"try to adjust your pathspec to reveal some of the {pruned_entries} pruned {entries} - show with --debug",
260267
entries = plural("entry", "entries", pruned_entries)
261268
)
262269
}));

0 commit comments

Comments
 (0)