Skip to content

Commit 7b294bf

Browse files
jlehmanngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jens Lehmann <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cf41982 commit 7b294bf

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

git-submodule.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,10 +570,12 @@ cmd_deinit()
570570

571571
if test -z "$force"
572572
then
573-
git rm -n "$sm_path" ||
573+
git rm -qn "$sm_path" ||
574574
die "$(eval_gettext "Submodule work tree '\$sm_path' contains local modifications; use '-f' to discard them")"
575575
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'")"
577579
fi
578580

579581
mkdir "$sm_path" || say "$(eval_gettext "Could not create empty submodule directory '\$sm_path'")"

t/t7400-submodule-basic.sh

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -776,18 +776,22 @@ test_expect_success 'submodule deinit . deinits all initialized submodules' '
776776
git config submodule.example.foo bar &&
777777
git config submodule.example2.frotz nitfol &&
778778
test_must_fail git submodule deinit &&
779-
git submodule deinit . &&
779+
git submodule deinit . >actual &&
780780
test -z "$(git config --get-regexp "submodule\.example\.")" &&
781781
test -z "$(git config --get-regexp "submodule\.example2\.")" &&
782+
test_i18ngrep "Cleared directory .init" actual &&
783+
test_i18ngrep "Cleared directory .example2" actual &&
782784
rmdir init example2
783785
'
784786

785787
test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' '
786788
git submodule update --init &&
787789
rm -rf init example2/* example2/.git &&
788-
git submodule deinit init example2 &&
790+
git submodule deinit init example2 >actual &&
789791
test -z "$(git config --get-regexp "submodule\.example\.")" &&
790792
test -z "$(git config --get-regexp "submodule\.example2\.")" &&
793+
test_i18ngrep ! "Cleared directory .init" actual &&
794+
test_i18ngrep "Cleared directory .example2" actual &&
791795
rmdir init
792796
'
793797

@@ -797,8 +801,9 @@ test_expect_success 'submodule deinit fails when the submodule contains modifica
797801
test_must_fail git submodule deinit init &&
798802
test -n "$(git config --get-regexp "submodule\.example\.")" &&
799803
test -f example2/.git &&
800-
git submodule deinit -f init &&
804+
git submodule deinit -f init >actual &&
801805
test -z "$(git config --get-regexp "submodule\.example\.")" &&
806+
test_i18ngrep "Cleared directory .init" actual &&
802807
rmdir init
803808
'
804809

@@ -808,8 +813,9 @@ test_expect_success 'submodule deinit fails when the submodule contains untracke
808813
test_must_fail git submodule deinit init &&
809814
test -n "$(git config --get-regexp "submodule\.example\.")" &&
810815
test -f example2/.git &&
811-
git submodule deinit -f init &&
816+
git submodule deinit -f init >actual &&
812817
test -z "$(git config --get-regexp "submodule\.example\.")" &&
818+
test_i18ngrep "Cleared directory .init" actual &&
813819
rmdir init
814820
'
815821

@@ -822,23 +828,28 @@ test_expect_success 'submodule deinit fails when the submodule HEAD does not mat
822828
test_must_fail git submodule deinit init &&
823829
test -n "$(git config --get-regexp "submodule\.example\.")" &&
824830
test -f example2/.git &&
825-
git submodule deinit -f init &&
831+
git submodule deinit -f init >actual &&
826832
test -z "$(git config --get-regexp "submodule\.example\.")" &&
833+
test_i18ngrep "Cleared directory .init" actual &&
827834
rmdir init
828835
'
829836

830837
test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' '
831838
git submodule update --init &&
832839
git submodule deinit init >actual &&
833840
test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
841+
test_i18ngrep "Cleared directory .init" actual &&
834842
git submodule deinit init >actual &&
835843
test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
844+
test_i18ngrep "Cleared directory .init" actual &&
836845
git submodule deinit . >actual &&
837846
test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
838847
test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual &&
848+
test_i18ngrep "Cleared directory .init" actual &&
839849
git submodule deinit . >actual &&
840850
test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
841851
test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
852+
test_i18ngrep "Cleared directory .init" actual &&
842853
rmdir init example2
843854
'
844855

0 commit comments

Comments
 (0)