submodule--helper update-clone: abort gracefully on missing .gitmodules
When there is no .gitmodules file availabe to initialize a submodule from, `submodule_from_path` just returns NULL. We need to check for that and abort gracefully. When `git submodule update` was implemented in shell, this error out with the warning Submodule path '%s' not initialized Maybe you want to use 'update --init'? Replicate that behavior for now instead of crashing. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
d92028a575
commit
08fdbdb153
@ -593,6 +593,25 @@ struct submodule_update_clone {
|
|||||||
SUBMODULE_UPDATE_STRATEGY_INIT, 0, NULL, NULL, NULL, NULL, \
|
SUBMODULE_UPDATE_STRATEGY_INIT, 0, NULL, NULL, NULL, NULL, \
|
||||||
STRING_LIST_INIT_DUP, 0}
|
STRING_LIST_INIT_DUP, 0}
|
||||||
|
|
||||||
|
|
||||||
|
static void next_submodule_warn_missing(struct submodule_update_clone *suc,
|
||||||
|
struct strbuf *out, const char *displaypath)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Only mention uninitialized submodules when their
|
||||||
|
* paths have been specified.
|
||||||
|
*/
|
||||||
|
if (suc->warn_if_uninitialized) {
|
||||||
|
strbuf_addf(out,
|
||||||
|
_("Submodule path '%s' not initialized"),
|
||||||
|
displaypath);
|
||||||
|
strbuf_addch(out, '\n');
|
||||||
|
strbuf_addstr(out,
|
||||||
|
_("Maybe you want to use 'update --init'?"));
|
||||||
|
strbuf_addch(out, '\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine whether 'ce' needs to be cloned. If so, prepare the 'child' to
|
* Determine whether 'ce' needs to be cloned. If so, prepare the 'child' to
|
||||||
* run the clone. Returns 1 if 'ce' needs to be cloned, 0 otherwise.
|
* run the clone. Returns 1 if 'ce' needs to be cloned, 0 otherwise.
|
||||||
@ -627,6 +646,11 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
|
|||||||
else
|
else
|
||||||
displaypath = ce->name;
|
displaypath = ce->name;
|
||||||
|
|
||||||
|
if (!sub) {
|
||||||
|
next_submodule_warn_missing(suc, out, displaypath);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
if (suc->update.type == SM_UPDATE_NONE
|
if (suc->update.type == SM_UPDATE_NONE
|
||||||
|| (suc->update.type == SM_UPDATE_UNSPECIFIED
|
|| (suc->update.type == SM_UPDATE_UNSPECIFIED
|
||||||
&& sub->update_strategy.type == SM_UPDATE_NONE)) {
|
&& sub->update_strategy.type == SM_UPDATE_NONE)) {
|
||||||
@ -644,19 +668,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
|
|||||||
strbuf_addf(&sb, "submodule.%s.url", sub->name);
|
strbuf_addf(&sb, "submodule.%s.url", sub->name);
|
||||||
git_config_get_string(sb.buf, &url);
|
git_config_get_string(sb.buf, &url);
|
||||||
if (!url) {
|
if (!url) {
|
||||||
/*
|
next_submodule_warn_missing(suc, out, displaypath);
|
||||||
* Only mention uninitialized submodules when their
|
|
||||||
* path have been specified
|
|
||||||
*/
|
|
||||||
if (suc->warn_if_uninitialized) {
|
|
||||||
strbuf_addf(out,
|
|
||||||
_("Submodule path '%s' not initialized"),
|
|
||||||
displaypath);
|
|
||||||
strbuf_addch(out, '\n');
|
|
||||||
strbuf_addstr(out,
|
|
||||||
_("Maybe you want to use 'update --init'?"));
|
|
||||||
strbuf_addch(out, '\n');
|
|
||||||
}
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,14 @@ test_expect_success 'submodule init aborts on missing .gitmodules file' '
|
|||||||
test_i18ngrep "No url found for submodule path" actual
|
test_i18ngrep "No url found for submodule path" actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'submodule update aborts on missing .gitmodules file' '
|
||||||
|
test_when_finished "git update-index --remove sub" &&
|
||||||
|
git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
|
||||||
|
# missing the .gitmodules file here
|
||||||
|
git submodule update sub 2>actual &&
|
||||||
|
test_i18ngrep "Submodule path .sub. not initialized" actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'configuration parsing' '
|
test_expect_success 'configuration parsing' '
|
||||||
test_when_finished "rm -f .gitmodules" &&
|
test_when_finished "rm -f .gitmodules" &&
|
||||||
cat >.gitmodules <<-\EOF &&
|
cat >.gitmodules <<-\EOF &&
|
||||||
|
Reference in New Issue
Block a user