submodule deinit: clarify work tree removal message

The output of "git submodule deinit sub" of a populated submodule prints rm 'sub' as the first line unless used with the -f option. The "rm 'sub'" line is exactly the same output the user gets when using "git rm sub" (because that command is used with the --dry-run option under the hood to determine if the submodule is clean), which can easily lead to the false impression that the submodule would be permanently removed. Also users might be confused that the "rm 'submodule'" line won't show up when the -f option is used, as the test is skipped in this case. Silence the "rm 'submodule'" output by using the --quiet option for "git rm" and always print Cleared directory 'submodule' instead as the first output line. This line is printed as long as the directory exists, no matter if empty or not. Also extend the tests in t7400 to make sure the "Cleared directory" line is printed correctly. Reported-by: Phil Hord <phil.hord@gmail.com> Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jens Lehmann committed Apr 1, 2013 at 21:02 UTC 7b294bf4948931a915cee2d5a692235e9b9c0e27
2 files changed +20 -7
git-submodule.sh
+4 -2
@@ -570,10 +570,12 @@ cmd_deinit()
570
571 if test -z "$force"
572 then
573 - git rm -n "$sm_path" ||
573 + git rm -qn "$sm_path" ||
574 die "$(eval_gettext "Submodule work tree '\$sm_path' contains local modifications; use '-f' to discard them")"
575 fi
576 - rm -rf "$sm_path" || say "$(eval_gettext "Could not remove submodule work tree '\$sm_path'")"
576 + rm -rf "$sm_path" &&
577 + say "$(eval_gettext "Cleared directory '\$sm_path'")" ||
578 + say "$(eval_gettext "Could not remove submodule work tree '\$sm_path'")"
579 fi
580
581 mkdir "$sm_path" || say "$(eval_gettext "Could not create empty submodule directory '\$sm_path'")"
t/t7400-submodule-basic.sh
+16 -5
@@ -776,18 +776,22 @@ test_expect_success 'submodule deinit . deinits all initialized submodules' '
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 . &&
779 + git submodule deinit . >actual &&
780 test -z "$(git config --get-regexp "submodule\.example\.")" &&
781 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
782 + test_i18ngrep "Cleared directory .init" actual &&
783 + test_i18ngrep "Cleared directory .example2" actual &&
784 rmdir init example2
785 '
786
787 test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' '
788 git submodule update --init &&
789 rm -rf init example2/* example2/.git &&
788 - git submodule deinit init example2 &&
790 + git submodule deinit init example2 >actual &&
791 test -z "$(git config --get-regexp "submodule\.example\.")" &&
792 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
793 + test_i18ngrep ! "Cleared directory .init" actual &&
794 + test_i18ngrep "Cleared directory .example2" actual &&
795 rmdir init
796 '
797
@@ -797,8 +801,9 @@ test_expect_success 'submodule deinit fails when the submodule contains modifica
801 test_must_fail git submodule deinit init &&
802 test -n "$(git config --get-regexp "submodule\.example\.")" &&
803 test -f example2/.git &&
800 - git submodule deinit -f init &&
804 + git submodule deinit -f init >actual &&
805 test -z "$(git config --get-regexp "submodule\.example\.")" &&
806 + test_i18ngrep "Cleared directory .init" actual &&
807 rmdir init
808 '
809
@@ -808,8 +813,9 @@ test_expect_success 'submodule deinit fails when the submodule contains untracke
813 test_must_fail git submodule deinit init &&
814 test -n "$(git config --get-regexp "submodule\.example\.")" &&
815 test -f example2/.git &&
811 - git submodule deinit -f init &&
816 + git submodule deinit -f init >actual &&
817 test -z "$(git config --get-regexp "submodule\.example\.")" &&
818 + test_i18ngrep "Cleared directory .init" actual &&
819 rmdir init
820 '
821
@@ -822,8 +828,9 @@ test_expect_success 'submodule deinit fails when the submodule HEAD does not mat
828 test_must_fail git submodule deinit init &&
829 test -n "$(git config --get-regexp "submodule\.example\.")" &&
830 test -f example2/.git &&
825 - git submodule deinit -f init &&
831 + git submodule deinit -f init >actual &&
832 test -z "$(git config --get-regexp "submodule\.example\.")" &&
833 + test_i18ngrep "Cleared directory .init" actual &&
834 rmdir init
835 '
836
@@ -831,14 +838,18 @@ test_expect_success 'submodule deinit is silent when used on an uninitialized su
838 git submodule update --init &&
839 git submodule deinit init >actual &&
840 test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
841 + test_i18ngrep "Cleared directory .init" actual &&
842 git submodule deinit init >actual &&
843 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
844 + test_i18ngrep "Cleared directory .init" actual &&
845 git submodule deinit . >actual &&
846 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
847 test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual &&
848 + test_i18ngrep "Cleared directory .init" actual &&
849 git submodule deinit . >actual &&
850 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
851 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
852 + test_i18ngrep "Cleared directory .init" actual &&
853 rmdir init example2
854 '
855