756
)
757
'
758
759
+test_expect_success 'set up a second submodule' '
760
+ git submodule add ./init2 example2 &&
761
+ git commit -m "submodule example2 added"
762
+'
763
+
764
+test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' '
765
+ git config submodule.example.foo bar &&
766
+ git config submodule.example2.frotz nitfol &&
767
+ git submodule deinit init &&
768
+ test -z "$(git config --get-regexp "submodule\.example\.")" &&
769
+ test -n "$(git config --get-regexp "submodule\.example2\.")" &&
770
+ test -f example2/.git &&
771
+ rmdir init
772
+'
773
+
774
+test_expect_success 'submodule deinit . deinits all initialized submodules' '
775
+ git submodule update --init &&
776
+ git config submodule.example.foo bar &&
777
+ git config submodule.example2.frotz nitfol &&
778
+ test_must_fail git submodule deinit &&
779
+ git submodule deinit . &&
780
+ test -z "$(git config --get-regexp "submodule\.example\.")" &&
781
+ test -z "$(git config --get-regexp "submodule\.example2\.")" &&
782
+ rmdir init example2
783
+'
784
+
785
+test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' '
786
+ git submodule update --init &&
787
+ rm -rf init example2/* example2/.git &&
788
+ git submodule deinit init example2 &&
789
+ test -z "$(git config --get-regexp "submodule\.example\.")" &&
790
+ test -z "$(git config --get-regexp "submodule\.example2\.")" &&
791
+ rmdir init
792
+'
793
+
794
+test_expect_success 'submodule deinit fails when the submodule contains modifications unless forced' '
795
+ git submodule update --init &&
796
+ echo X >>init/s &&
797
+ test_must_fail git submodule deinit init &&
798
+ test -n "$(git config --get-regexp "submodule\.example\.")" &&
799
+ test -f example2/.git &&
800
+ git submodule deinit -f init &&
801
+ test -z "$(git config --get-regexp "submodule\.example\.")" &&
802
+ rmdir init
803
+'
804
+
805
+test_expect_success 'submodule deinit fails when the submodule contains untracked files unless forced' '
806
+ git submodule update --init &&
807
+ echo X >>init/untracked &&
808
+ test_must_fail git submodule deinit init &&
809
+ test -n "$(git config --get-regexp "submodule\.example\.")" &&
810
+ test -f example2/.git &&
811
+ git submodule deinit -f init &&
812
+ test -z "$(git config --get-regexp "submodule\.example\.")" &&
813
+ rmdir init
814
+'
815
+
816
+test_expect_success 'submodule deinit fails when the submodule HEAD does not match unless forced' '
817
+ git submodule update --init &&
818
+ (
819
+ cd init &&
820
+ git checkout HEAD^
821
+ ) &&
822
+ test_must_fail git submodule deinit init &&
823
+ test -n "$(git config --get-regexp "submodule\.example\.")" &&
824
+ test -f example2/.git &&
825
+ git submodule deinit -f init &&
826
+ test -z "$(git config --get-regexp "submodule\.example\.")" &&
827
+ rmdir init
828
+'
829
+
830
+test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' '
831
+ git submodule update --init &&
832
+ git submodule deinit init >actual &&
833
+ test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
834
+ git submodule deinit init >actual &&
835
+ test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
836
+ git submodule deinit . >actual &&
837
+ test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
838
+ test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual &&
839
+ git submodule deinit . >actual &&
840
+ test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
841
+ test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
842
+ rmdir init example2
843
+'
844
+
845
+test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' '
846
+ git submodule update --init &&
847
+ (
848
+ cd init &&
849
+ rm .git &&
850
+ cp -R ../.git/modules/example .git &&
851
+ GIT_WORK_TREE=. git config --unset core.worktree
852
+ ) &&
853
+ test_must_fail git submodule deinit init &&
854
+ test_must_fail git submodule deinit -f init &&
855
+ test -d init/.git &&
856
+ test -n "$(git config --get-regexp "submodule\.example\.")"
857
+'
858
+
859
test_done