* [PATCHv2 1/2] submodule init: fail gracefully with a missing .gitmodules file @ 2016-04-28 20:02 Stefan Beller 2016-04-28 20:02 ` [PATCH 2/2] submodule--helper update-clone: abort gracefully on missing .gitmodules Stefan Beller 2016-04-29 17:06 ` [PATCHv2 1/2] submodule init: fail gracefully with a missing .gitmodules file Junio C Hamano 0 siblings, 2 replies; 3+ messages in thread From: Stefan Beller @ 2016-04-28 20:02 UTC (permalink / raw) To: gitster; +Cc: git, Jens.Lehmann, Stefan Beller 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 `submodule init` was implemented in shell, a missing .gitmodules file would result in an error message No url found for submodule path '%s' in .gitmodules Replicate that error message for now. When the .gitmodules file is missing we can probably fail even earlier for all of the submodules with an improved error message. Signed-off-by: Stefan Beller <sbeller@google.com> --- applies on submodule-init. Thanks, Stefan builtin/submodule--helper.c | 10 +++++++--- t/t7400-submodule-basic.sh | 8 ++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index b6d4f27..ce9d11e 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -314,13 +314,17 @@ static void init_submodule(const char *path, const char *prefix, int quiet) /* Only loads from .gitmodules, no overlay with .git/config */ gitmodules_config(); - sub = submodule_from_path(null_sha1, path); - if (prefix) { strbuf_addf(&sb, "%s%s", prefix, path); displaypath = strbuf_detach(&sb, NULL); } else - displaypath = xstrdup(sub->path); + displaypath = xstrdup(path); + + sub = submodule_from_path(null_sha1, path); + + if (!sub) + die(_("No url found for submodule path '%s' in .gitmodules"), + displaypath); /* * Copy url setting when it is not set yet. diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index f99f674..df6b4da 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -18,6 +18,14 @@ test_expect_success 'setup - initial commit' ' git branch initial ' +test_expect_success 'submodule init 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 + test_must_fail git submodule init 2>actual && + test_i18ngrep "No url found for submodule path" actual +' + test_expect_success 'configuration parsing' ' test_when_finished "rm -f .gitmodules" && cat >.gitmodules <<-\EOF && -- 2.8.0.28.ga4e36c9 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] submodule--helper update-clone: abort gracefully on missing .gitmodules 2016-04-28 20:02 [PATCHv2 1/2] submodule init: fail gracefully with a missing .gitmodules file Stefan Beller @ 2016-04-28 20:02 ` Stefan Beller 2016-04-29 17:06 ` [PATCHv2 1/2] submodule init: fail gracefully with a missing .gitmodules file Junio C Hamano 1 sibling, 0 replies; 3+ messages in thread From: Stefan Beller @ 2016-04-28 20:02 UTC (permalink / raw) To: gitster; +Cc: git, Jens.Lehmann, Stefan Beller 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> --- builtin/submodule--helper.c | 38 +++++++++++++++++++++++++------------- t/t7400-submodule-basic.sh | 8 ++++++++ 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index ce9d11e..5d05393 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -593,6 +593,25 @@ struct submodule_update_clone { SUBMODULE_UPDATE_STRATEGY_INIT, 0, NULL, NULL, NULL, NULL, \ 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 * 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 displaypath = ce->name; + if (!sub) { + next_submodule_warn_missing(suc, out, displaypath); + goto cleanup; + } + if (suc->update.type == SM_UPDATE_NONE || (suc->update.type == SM_UPDATE_UNSPECIFIED && 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); git_config_get_string(sb.buf, &url); if (!url) { - /* - * 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'); - } + next_submodule_warn_missing(suc, out, displaypath); goto cleanup; } diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index df6b4da..814ee63 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -26,6 +26,14 @@ test_expect_success 'submodule init aborts on missing .gitmodules file' ' 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_when_finished "rm -f .gitmodules" && cat >.gitmodules <<-\EOF && -- 2.8.0.28.ga4e36c9 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCHv2 1/2] submodule init: fail gracefully with a missing .gitmodules file 2016-04-28 20:02 [PATCHv2 1/2] submodule init: fail gracefully with a missing .gitmodules file Stefan Beller 2016-04-28 20:02 ` [PATCH 2/2] submodule--helper update-clone: abort gracefully on missing .gitmodules Stefan Beller @ 2016-04-29 17:06 ` Junio C Hamano 1 sibling, 0 replies; 3+ messages in thread From: Junio C Hamano @ 2016-04-29 17:06 UTC (permalink / raw) To: Stefan Beller; +Cc: git, Jens.Lehmann Stefan Beller <sbeller@google.com> writes: > 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 `submodule init` was implemented in shell, > a missing .gitmodules file would result in an error message > > No url found for submodule path '%s' in .gitmodules > > Replicate that error message for now. Good to start from a faithful conversion. Thanks for adding a test, too. Will queue. ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-04-29 17:07 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-04-28 20:02 [PATCHv2 1/2] submodule init: fail gracefully with a missing .gitmodules file Stefan Beller 2016-04-28 20:02 ` [PATCH 2/2] submodule--helper update-clone: abort gracefully on missing .gitmodules Stefan Beller 2016-04-29 17:06 ` [PATCHv2 1/2] submodule init: fail gracefully with a missing .gitmodules file Junio C Hamano
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).