submodule init: fail gracefully with a missing .gitmodules file
[gitweb.git] / builtin / submodule--helper.c
index b6d4f27648c8c7f1c4d01e1c5060675e13d8cca2..ce9d11e8d367176a6f846d0a004f22a1c8b74d93 100644 (file)
@@ -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.