@@ -303,27 +303,45 @@ fn collect_selected_files(
303303 }
304304 DependencyScope :: Direct | DependencyScope :: TwoHops => {
305305 let maybe_target_rel = target. strip_prefix ( source_root) . ok ( ) ;
306- if maybe_target_rel. is_none ( ) {
307- notes. push (
308- "target is outside --source-root; dependency scope fell back to target only"
309- . to_string ( ) ,
310- ) ;
311- } else if let Ok ( report) = assail:: analyze ( source_root) {
312- let target_rel = maybe_target_rel
313- . expect ( "checked is_some" )
314- . to_string_lossy ( )
315- . to_string ( ) ;
316- let depth = if scope == DependencyScope :: Direct {
317- 1
306+ if let Some ( target_rel_path) = maybe_target_rel {
307+ if let Ok ( report) = assail:: analyze ( source_root) {
308+ let target_rel = target_rel_path
309+ . to_string_lossy ( )
310+ . to_string ( ) ;
311+ let depth = if scope == DependencyScope :: Direct {
312+ 1
313+ } else {
314+ 2
315+ } ;
316+ let rel_nodes =
317+ related_nodes_from_graph ( & target_rel, & report. dependency_graph . edges , depth) ;
318+ if rel_nodes. len ( ) <= 1 {
319+ notes. push (
320+ "no direct dependency neighbors found; falling back to same directory"
321+ . to_string ( ) ,
322+ ) ;
323+ if let Some ( parent) = target. parent ( ) {
324+ for entry in fs:: read_dir ( parent)
325+ . with_context ( || format ! ( "reading directory {}" , parent. display( ) ) ) ?
326+ {
327+ let entry = entry?;
328+ let path = entry. path ( ) ;
329+ if path. is_file ( ) {
330+ selected. insert ( path) ;
331+ }
332+ }
333+ }
334+ } else {
335+ for rel in rel_nodes {
336+ let abs = source_root. join ( & rel) ;
337+ if abs. is_file ( ) {
338+ selected. insert ( abs) ;
339+ }
340+ }
341+ }
318342 } else {
319- 2
320- } ;
321- let rel_nodes =
322- related_nodes_from_graph ( & target_rel, & report. dependency_graph . edges , depth) ;
323- if rel_nodes. len ( ) <= 1 {
324343 notes. push (
325- "no direct dependency neighbors found; falling back to same directory"
326- . to_string ( ) ,
344+ "assail dependency analysis failed; fell back to same directory" . to_string ( ) ,
327345 ) ;
328346 if let Some ( parent) = target. parent ( ) {
329347 for entry in fs:: read_dir ( parent)
@@ -336,29 +354,12 @@ fn collect_selected_files(
336354 }
337355 }
338356 }
339- } else {
340- for rel in rel_nodes {
341- let abs = source_root. join ( & rel) ;
342- if abs. is_file ( ) {
343- selected. insert ( abs) ;
344- }
345- }
346357 }
347358 } else {
348359 notes. push (
349- "assail dependency analysis failed; fell back to same directory" . to_string ( ) ,
360+ "target is outside --source-root; dependency scope fell back to target only"
361+ . to_string ( ) ,
350362 ) ;
351- if let Some ( parent) = target. parent ( ) {
352- for entry in fs:: read_dir ( parent)
353- . with_context ( || format ! ( "reading directory {}" , parent. display( ) ) ) ?
354- {
355- let entry = entry?;
356- let path = entry. path ( ) ;
357- if path. is_file ( ) {
358- selected. insert ( path) ;
359- }
360- }
361- }
362363 }
363364 }
364365 }
0 commit comments