submodules: add helper to determine if a submodule is initialized
[gitweb.git] / submodule.c
index ee3198dc245a31ca47f143a6016b978b251c2ed7..edffaa186bb4087b874aa5d1c8c93f24dfe7b3ce 100644 (file)
@@ -198,6 +198,29 @@ void gitmodules_config(void)
        }
 }
 
+/*
+ * Determine if a submodule has been initialized at a given 'path'
+ */
+int is_submodule_initialized(const char *path)
+{
+       int ret = 0;
+       const struct submodule *module = NULL;
+
+       module = submodule_from_path(null_sha1, path);
+
+       if (module) {
+               char *key = xstrfmt("submodule.%s.url", module->name);
+               char *value = NULL;
+
+               ret = !git_config_get_string(key, &value);
+
+               free(value);
+               free(key);
+       }
+
+       return ret;
+}
+
 /*
  * Determine if a submodule has been populated at a given 'path'
  */