submodule: fix regression for deinit without submodules
authorStefan Beller <sbeller@google.com>
Tue, 22 Mar 2016 23:42:14 +0000 (16:42 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Mar 2016 02:26:43 +0000 (19:26 -0700)
commit84ba959bbdf083ff7036619fa08152e46b9473a5
tree1f5cf7ed52e60e0af127ecbd13d74aac7748a2d3
parent2b56bb7a87ab429c225f6325f2870cbeac0d19f9
submodule: fix regression for deinit without submodules

Per Cederqvist wrote:
> It used to be possible to run
>
>    git submodule deinit -f .
>
> to remove any submodules, no matter how many submodules you had.  That
> is no longer possible in projects that don't have any submodules at
> all.  The command will fail with:
>
>     error: pathspec '.' did not match any file(s) known to git.

This regression was introduced in 74703a1e4dfc (submodule: rewrite
`module_list` shell function in C, 2015-09-02), as we changed the
order of checking in new module listing to first check whether it is
a gitlin before feeding it to match_pathspec().  It used to be that
a pathspec that does not match any path were diagnosed as an error,
but the new code complains for a pathspec that does not match any
submodule path.

Arguably the new behaviour may give us a better diagnosis, but that
is inconsistent with the suggestion "deinit" gives, and also this
was an unintended accident.  The new behaviour hopefully can be
redesigned and implemented better in future releases, but for now,
switch these two checks to restore the same behavior as before.  In
an empty repository, giving the pathspec '.' will still get the same
"did not match" error, but that is the same bug we had before 1.7.0.

Reported-by: Per Cederqvist <cederp@opera.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/submodule--helper.c
t/t7400-submodule-basic.sh