@@ -20,6 +20,12 @@ impl Repository {
2020 /// lookup. Note that items will only count as tracked if they have the [`gix_index::entry::Flags::UPTODATE`]
2121 /// flag set.
2222 ///
23+ /// Note that dirwalks for the purpose of deletion will be initialized with the worktrees of this repository
24+ /// if they fall into the working directory of this repository as well to mark them as `tracked`. That way
25+ /// it's hard to accidentally flag them for deletion.
26+ /// This is intentionally not the case when deletion is not intended so they look like
27+ /// untracked repositories instead.
28+ ///
2329 /// See [`gix_dir::walk::delegate::Collect`] for a delegate that collects all seen entries.
2430 pub fn dirwalk (
2531 & self ,
@@ -48,6 +54,27 @@ impl Repository {
4854 crate :: path:: realpath_opts ( self . git_dir ( ) , self . current_dir ( ) , crate :: path:: realpath:: MAX_SYMLINKS ) ?;
4955 let fs_caps = self . filesystem_options ( ) ?;
5056 let accelerate_lookup = fs_caps. ignore_case . then ( || index. prepare_icase_backing ( ) ) ;
57+ let mut opts = gix_dir:: walk:: Options :: from ( options) ;
58+ let worktree_relative_worktree_dirs_storage;
59+ if let Some ( workdir) = self . work_dir ( ) . filter ( |_| opts. for_deletion . is_some ( ) ) {
60+ let linked_worktrees = self . worktrees ( ) ?;
61+ if !linked_worktrees. is_empty ( ) {
62+ let real_workdir = gix_path:: realpath_opts (
63+ workdir,
64+ self . options . current_dir_or_empty ( ) ,
65+ gix_path:: realpath:: MAX_SYMLINKS ,
66+ ) ?;
67+ worktree_relative_worktree_dirs_storage = linked_worktrees
68+ . into_iter ( )
69+ . filter_map ( |proxy| proxy. base ( ) . ok ( ) )
70+ . filter_map ( |base| base. strip_prefix ( & real_workdir) . map ( ToOwned :: to_owned) . ok ( ) )
71+ . map ( |rela_path| {
72+ gix_path:: to_unix_separators_on_windows ( gix_path:: into_bstr ( rela_path) ) . into_owned ( )
73+ } )
74+ . collect ( ) ;
75+ opts. worktree_relative_worktree_dirs = Some ( & worktree_relative_worktree_dirs_storage) ;
76+ }
77+ }
5178 let ( outcome, traversal_root) = gix_dir:: walk (
5279 workdir,
5380 gix_dir:: walk:: Context {
@@ -71,7 +98,7 @@ impl Repository {
7198 objects : & self . objects ,
7299 explicit_traversal_root : ( !options. empty_patterns_match_prefix ) . then_some ( workdir) ,
73100 } ,
74- options . into ( ) ,
101+ opts ,
75102 delegate,
76103 ) ?;
77104
0 commit comments