@@ -722,4 +722,121 @@ test_expect_success 'fetch new submodule commit intermittently referenced by sup
722
722
)
723
723
'
724
724
725
+ add_commit_push () {
726
+ dir=" $1 " &&
727
+ msg=" $2 " &&
728
+ shift 2 &&
729
+ git -C " $dir " add " $@ " &&
730
+ git -C " $dir " commit -a -m " $msg " &&
731
+ git -C " $dir " push
732
+ }
733
+
734
+ compare_refs_in_dir () {
735
+ fail= &&
736
+ if test " x$1 " = ' x!'
737
+ then
738
+ fail=' !' &&
739
+ shift
740
+ fi &&
741
+ git -C " $1 " rev-parse --verify " $2 " > expect &&
742
+ git -C " $3 " rev-parse --verify " $4 " > actual &&
743
+ eval $fail test_cmp expect actual
744
+ }
745
+
746
+
747
+ test_expect_success ' setup nested submodule fetch test' '
748
+ # does not depend on any previous test setups
749
+
750
+ for repo in outer middle inner
751
+ do
752
+ git init --bare $repo &&
753
+ git clone $repo ${repo}_content &&
754
+ echo "$repo" >"${repo}_content/file" &&
755
+ add_commit_push ${repo}_content "initial" file ||
756
+ return 1
757
+ done &&
758
+
759
+ git clone outer A &&
760
+ git -C A submodule add "$pwd/middle" &&
761
+ git -C A/middle/ submodule add "$pwd/inner" &&
762
+ add_commit_push A/middle/ "adding inner sub" .gitmodules inner &&
763
+ add_commit_push A/ "adding middle sub" .gitmodules middle &&
764
+
765
+ git clone outer B &&
766
+ git -C B/ submodule update --init middle &&
767
+
768
+ compare_refs_in_dir A HEAD B HEAD &&
769
+ compare_refs_in_dir A/middle HEAD B/middle HEAD &&
770
+ test_path_is_file B/file &&
771
+ test_path_is_file B/middle/file &&
772
+ test_path_is_missing B/middle/inner/file &&
773
+
774
+ echo "change on inner repo of A" >"A/middle/inner/file" &&
775
+ add_commit_push A/middle/inner "change on inner" file &&
776
+ add_commit_push A/middle "change on inner" inner &&
777
+ add_commit_push A "change on inner" middle
778
+ '
779
+
780
+ test_expect_success ' fetching a superproject containing an uninitialized sub/sub project' '
781
+ # depends on previous test for setup
782
+
783
+ git -C B/ fetch &&
784
+ compare_refs_in_dir A origin/HEAD B origin/HEAD
785
+ '
786
+
787
+ fetch_with_recursion_abort () {
788
+ # In a regression the following git call will run into infinite recursion.
789
+ # To handle that, we connect the sed command to the git call by a pipe
790
+ # so that sed can kill the infinite recursion when detected.
791
+ # The recursion creates git output like:
792
+ # Fetching submodule sub
793
+ # Fetching submodule sub/sub <-- [1]
794
+ # Fetching submodule sub/sub/sub
795
+ # ...
796
+ # [1] sed will stop reading and cause git to eventually stop and die
797
+
798
+ git -C " $1 " fetch --recurse-submodules 2>&1 |
799
+ sed " /Fetching submodule $2 [^$]/q" > out &&
800
+ ! grep " Fetching submodule $2 [^$]" out
801
+ }
802
+
803
+ test_expect_success ' setup recursive fetch with uninit submodule' '
804
+ # does not depend on any previous test setups
805
+
806
+ test_create_repo super &&
807
+ test_commit -C super initial &&
808
+ test_create_repo sub &&
809
+ test_commit -C sub initial &&
810
+ git -C sub rev-parse HEAD >expect &&
811
+
812
+ git -C super submodule add ../sub &&
813
+ git -C super commit -m "add sub" &&
814
+
815
+ git clone super superclone &&
816
+ git -C superclone submodule status >out &&
817
+ sed -e "s/^-//" -e "s/ sub.*$//" out >actual &&
818
+ test_cmp expect actual
819
+ '
820
+
821
+ test_expect_success ' recursive fetch with uninit submodule' '
822
+ # depends on previous test for setup
823
+
824
+ fetch_with_recursion_abort superclone sub &&
825
+ git -C superclone submodule status >out &&
826
+ sed -e "s/^-//" -e "s/ sub$//" out >actual &&
827
+ test_cmp expect actual
828
+ '
829
+
830
+ test_expect_success ' recursive fetch after deinit a submodule' '
831
+ # depends on previous test for setup
832
+
833
+ git -C superclone submodule update --init sub &&
834
+ git -C superclone submodule deinit -f sub &&
835
+
836
+ fetch_with_recursion_abort superclone sub &&
837
+ git -C superclone submodule status >out &&
838
+ sed -e "s/^-//" -e "s/ sub$//" out >actual &&
839
+ test_cmp expect actual
840
+ '
841
+
725
842
test_done
0 commit comments