submodules: add helper to determine if a submodule is initialized
authorBrandon Williams <bmwill@google.com>
Fri, 16 Dec 2016 19:03:17 +0000 (11:03 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 Dec 2016 19:47:33 +0000 (11:47 -0800)
Add the `is_submodule_initialized()` helper function to submodules.c.
`is_submodule_initialized()` performs a check to determine if the
submodule at the given path has been initialized.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
submodule.c
submodule.h
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'
  */
index c4af5059813f598356a2862218a4c2cf95013eb4..6ec5f2f207c7a0f209b8f1c537dc78fed27eedda 100644 (file)
@@ -37,6 +37,7 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
                const char *path);
 int submodule_config(const char *var, const char *value, void *cb);
 void gitmodules_config(void);
+extern int is_submodule_initialized(const char *path);
 extern int is_submodule_populated(const char *path);
 int parse_submodule_update_strategy(const char *value,
                struct submodule_update_strategy *dst);