@@ -20,6 +20,12 @@ impl Repository {
20
20
/// lookup. Note that items will only count as tracked if they have the [`gix_index::entry::Flags::UPTODATE`]
21
21
/// flag set.
22
22
///
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
+ ///
23
29
/// See [`gix_dir::walk::delegate::Collect`] for a delegate that collects all seen entries.
24
30
pub fn dirwalk (
25
31
& self ,
@@ -48,6 +54,27 @@ impl Repository {
48
54
crate :: path:: realpath_opts ( self . git_dir ( ) , self . current_dir ( ) , crate :: path:: realpath:: MAX_SYMLINKS ) ?;
49
55
let fs_caps = self . filesystem_options ( ) ?;
50
56
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
+ }
51
78
let ( outcome, traversal_root) = gix_dir:: walk (
52
79
workdir,
53
80
gix_dir:: walk:: Context {
@@ -71,7 +98,7 @@ impl Repository {
71
98
objects : & self . objects ,
72
99
explicit_traversal_root : ( !options. empty_patterns_match_prefix ) . then_some ( workdir) ,
73
100
} ,
74
- options . into ( ) ,
101
+ opts ,
75
102
delegate,
76
103
) ?;
77
104
0 commit comments