This is the continuation of f2d48994dc1 (submodule.c: submodule_move_head works with broken submodules, 2017-04-18), which tones down the case of "broken submodule" in case of a missing git directory of the submodule to be only a warning. Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx> --- submodule.c | 16 ++++++++++++++++ t/t2013-checkout-submodule.sh | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/submodule.c b/submodule.c index 50cbf5f13ed..689439a3d0c 100644 --- a/submodule.c +++ b/submodule.c @@ -1641,6 +1641,22 @@ int submodule_move_head(const char *path, } else { char *gitdir = xstrfmt("%s/modules/%s", get_git_common_dir(), sub->name); + + if (!is_git_directory(gitdir)) { + /* + * It is safe to assume we could just clone + * the submodule here, as we passed the + * is_submodule_active test above (i.e. the + * user is interested in this submodule. + * + * However as this code path is exercised + * for operations that typically do not involve + * network operations, let's not do that for now. + */ + warning(_("Submodule '%s' missing"), path); + free(gitdir); + return 0; + } connect_work_tree_and_git_dir(path, gitdir, 0); free(gitdir); diff --git a/t/t2013-checkout-submodule.sh b/t/t2013-checkout-submodule.sh index c69640fc341..82ef4576b91 100755 --- a/t/t2013-checkout-submodule.sh +++ b/t/t2013-checkout-submodule.sh @@ -81,7 +81,7 @@ test_expect_success 'setup superproject with historic submodule' ' test_must_be_empty super1/.gitmodules ' -test_expect_failure 'checkout old state with deleted submodule' ' +test_expect_success 'checkout old state with deleted submodule' ' test_when_finished "rm -rf super1 sub1 super1_clone" && git clone --recurse-submodules super1 super1_clone && git -C super1_clone checkout --recurse-submodules historic_state -- 2.18.0