submodule deinit: require '--all' instead of '.' for all submodules
The discussion in [1] pointed out that '.' is a faulty suggestion as there is a corner case where it fails: > "submodule deinit ." may have "worked" in the sense that you would > have at least one path in your tree and avoided this "nothing > matches" most of the time. It would have still failed with the > exactly same error if run in an empty repository, i.e. > > $ E=/var/tmp/x/empty && rm -fr "$E" && mkdir -p "$E" && cd "$E" > $ git init > $ rungit v2.6.6 submodule deinit . > error: pathspec '.' did not match any file(s) known to git. > Did you forget to 'git add'? > $ >file && git add file > $ rungit v2.6.6 submodule deinit . > $ echo $? > 0 So instead of a pathspec add the '--all' option to deinit all submodules and add a test to check for the corner case of an empty repository. The code only needs to learn about the '--all' option and doesn't require further changes as `git submodule--helper list "$@"` will list all submodules when "$@" is empty. [1] http://news.gmane.org/gmane.comp.version-control.git/289535 Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Stefan Beller <sbeller@google.com> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
90f7b16b3a
commit
f6a5279977
@ -11,6 +11,10 @@ subcommands of git submodule.
|
||||
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'submodule deinit works on empty repository' '
|
||||
git submodule deinit --all
|
||||
'
|
||||
|
||||
test_expect_success 'setup - initial commit' '
|
||||
>t &&
|
||||
git add t &&
|
||||
@ -858,7 +862,8 @@ test_expect_success 'submodule deinit works on repository without submodules' '
|
||||
>file &&
|
||||
git add file &&
|
||||
git commit -m "repo should not be empty"
|
||||
git submodule deinit .
|
||||
git submodule deinit . &&
|
||||
git submodule deinit --all
|
||||
)
|
||||
'
|
||||
|
||||
@ -900,6 +905,19 @@ test_expect_success 'submodule deinit . deinits all initialized submodules' '
|
||||
rmdir init example2
|
||||
'
|
||||
|
||||
test_expect_success 'submodule deinit --all deinits all initialized submodules' '
|
||||
git submodule update --init &&
|
||||
git config submodule.example.foo bar &&
|
||||
git config submodule.example2.frotz nitfol &&
|
||||
test_must_fail git submodule deinit &&
|
||||
git submodule deinit --all >actual &&
|
||||
test -z "$(git config --get-regexp "submodule\.example\.")" &&
|
||||
test -z "$(git config --get-regexp "submodule\.example2\.")" &&
|
||||
test_i18ngrep "Cleared directory .init" actual &&
|
||||
test_i18ngrep "Cleared directory .example2" actual &&
|
||||
rmdir init example2
|
||||
'
|
||||
|
||||
test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' '
|
||||
git submodule update --init &&
|
||||
rm -rf init example2/* example2/.git &&
|
||||
@ -966,6 +984,10 @@ test_expect_success 'submodule deinit is silent when used on an uninitialized su
|
||||
test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
|
||||
test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
|
||||
test_i18ngrep "Cleared directory .init" actual &&
|
||||
git submodule deinit --all >actual &&
|
||||
test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
|
||||
test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
|
||||
test_i18ngrep "Cleared directory .init" actual &&
|
||||
rmdir init example2
|
||||
'
|
||||
|
||||
|
Reference in New Issue
Block a user