@@ -2631,6 +2631,130 @@ fn root_may_not_go_through_dot_git() -> crate::Result {
26312631 Ok ( ( ) )
26322632}
26332633
2634+ #[ test]
2635+ fn root_at_submodule_repository_allows_walk ( ) -> crate :: Result {
2636+ let root = fixture ( "repo-with-submodule" ) ;
2637+ let troot = root. join ( "submodule" ) ;
2638+ let ( ( out, _root) , entries) = try_collect_filtered_opts_collect_with_root (
2639+ & troot,
2640+ None ,
2641+ Some ( & troot) ,
2642+ |keep, ctx| {
2643+ walk (
2644+ & troot,
2645+ ctx,
2646+ walk:: Options {
2647+ emit_tracked : true ,
2648+ emit_untracked : Matching ,
2649+ ..options ( )
2650+ } ,
2651+ keep,
2652+ )
2653+ } ,
2654+ None :: < & str > ,
2655+ Options :: git_dir ( "../.git/modules/submodule" ) ,
2656+ ) ?;
2657+
2658+ assert_eq ! (
2659+ out,
2660+ walk:: Outcome {
2661+ read_dir_calls: 2 ,
2662+ returned_entries: entries. len( ) ,
2663+ seen_entries: 3 ,
2664+ }
2665+ ) ;
2666+
2667+ assert_eq ! (
2668+ entries,
2669+ [ entry( "dir/file" , Tracked , File ) , entry( "untracked" , Untracked , File ) ] ,
2670+ "this is a special case to allow walking submodules specifically, like a normal repository"
2671+ ) ;
2672+ Ok ( ( ) )
2673+ }
2674+
2675+ #[ test]
2676+ fn root_in_submodule_repository_allows_walk ( ) -> crate :: Result {
2677+ let root = fixture ( "repo-with-submodule" ) ;
2678+ let troot = root. join ( "submodule" ) ;
2679+ let ( ( out, _root) , entries) = try_collect_filtered_opts_collect_with_root (
2680+ & troot,
2681+ None ,
2682+ Some ( & troot. join ( "dir" ) ) ,
2683+ |keep, ctx| {
2684+ walk (
2685+ & troot,
2686+ ctx,
2687+ walk:: Options {
2688+ emit_tracked : true ,
2689+ emit_untracked : Matching ,
2690+ ..options ( )
2691+ } ,
2692+ keep,
2693+ )
2694+ } ,
2695+ None :: < & str > ,
2696+ Options :: git_dir ( "../.git/modules/submodule" ) ,
2697+ ) ?;
2698+
2699+ assert_eq ! (
2700+ out,
2701+ walk:: Outcome {
2702+ read_dir_calls: 1 ,
2703+ returned_entries: entries. len( ) ,
2704+ seen_entries: 1 ,
2705+ }
2706+ ) ;
2707+
2708+ assert_eq ! (
2709+ entries,
2710+ [ entry( "dir/file" , Tracked , File ) ] ,
2711+ "it's also working if the traversal root is inside the subdmodule"
2712+ ) ;
2713+ Ok ( ( ) )
2714+ }
2715+
2716+ #[ test]
2717+ fn root_in_submodule_from_superproject_repository_allows_walk ( ) -> crate :: Result {
2718+ let root = fixture ( "repo-with-submodule" ) ;
2719+ let troot = root. join ( "submodule" ) . join ( "dir" ) ;
2720+ let ( ( out, _root) , entries) = try_collect_filtered_opts_collect_with_root (
2721+ & root,
2722+ None ,
2723+ Some ( & troot) ,
2724+ |keep, ctx| {
2725+ walk (
2726+ & troot,
2727+ ctx,
2728+ walk:: Options {
2729+ emit_tracked : true ,
2730+ emit_untracked : Matching ,
2731+ ..options ( )
2732+ } ,
2733+ keep,
2734+ )
2735+ } ,
2736+ None :: < & str > ,
2737+ Default :: default ( ) ,
2738+ ) ?;
2739+
2740+ assert_eq ! (
2741+ out,
2742+ walk:: Outcome {
2743+ read_dir_calls: 1 ,
2744+ returned_entries: entries. len( ) ,
2745+ seen_entries: 1 ,
2746+ }
2747+ ) ;
2748+
2749+ assert_eq ! (
2750+ entries,
2751+ [ entry( "file" , Untracked , File ) ] ,
2752+ "there is no index that has 'file' in it (it's 'dir/file'), hence it's untracked.\
2753+ But the traversal is possible, even though it might not make the most sense."
2754+ ) ;
2755+ Ok ( ( ) )
2756+ }
2757+
26342758#[ test]
26352759fn root_enters_directory_with_dot_git_in_reconfigured_worktree_tracked ( ) -> crate :: Result {
26362760 let root = fixture ( "nonstandard-worktree" ) ;
@@ -2797,7 +2921,8 @@ fn root_may_not_go_through_submodule() -> crate::Result {
27972921 assert_eq ! (
27982922 entries,
27992923 [ entry( "submodule" , Tracked , Repository ) ] ,
2800- "it refuses to start traversal in a submodule, thus it ends in the directory that is the submodule"
2924+ "it refuses to start traversal in a submodule, thus it ends in the directory that is the submodule, \
2925+ if the root is another repository"
28012926 ) ;
28022927 Ok ( ( ) )
28032928}
0 commit comments