Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Beller <sbeller@google.com>2016-04-28 23:02:46 +0300
committerJunio C Hamano <gitster@pobox.com>2016-04-29 20:07:13 +0300
commit08fdbdb153c138f0a2dc85949475fafb20853d96 (patch)
treef3d62ae553d8f4db4c025817eeca99df6886360c /builtin/submodule--helper.c
parentd92028a575dde9c325e23f89c3d2b24f13868c57 (diff)
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>
Diffstat (limited to 'builtin/submodule--helper.c')
-rw-r--r--builtin/submodule--helper.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index ce9d11e8d3..5d05393e7b 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;
}