diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index ed764c9f0e5f76bbf8da7297315a4c29c0636271..5295b727d4609fa33a08c31b2d051ce3f98244fb 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -37,9 +37,9 @@ static int module_list_compute(int argc, const char **argv, for (i = 0; i < active_nr; i++) { const struct cache_entry *ce = active_cache[i]; - if (!S_ISGITLINK(ce->ce_mode) || - !match_pathspec(pathspec, ce->name, ce_namelen(ce), - 0, ps_matched, 1)) + if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), + 0, ps_matched, 1) || + !S_ISGITLINK(ce->ce_mode)) continue; ALLOC_GROW(list->entries, list->nr + 1, list->alloc); diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index be82a75e542a7b7d8dab259da4e64dd265019dd1..e1abd1923033617540c915af4372ba42936326d0 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -849,6 +849,19 @@ test_expect_success 'set up a second submodule' ' git commit -m "submodule example2 added" ' +test_expect_success 'submodule deinit works on repository without submodules' ' + test_when_finished "rm -rf newdirectory" && + mkdir newdirectory && + ( + cd newdirectory && + git init && + >file && + git add file && + git commit -m "repo should not be empty" + git submodule deinit . + ) +' + test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' ' git config submodule.example.foo bar && git config submodule.example2.frotz nitfol &&