From f9f42560e2911a5eef9a3d463a63cfd48d54dd07 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Fri, 16 Dec 2016 11:03:17 -0800 Subject: submodules: add helper to determine if a submodule is initialized 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 Signed-off-by: Junio C Hamano --- submodule.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'submodule.c') diff --git a/submodule.c b/submodule.c index ee3198dc24..edffaa186b 100644 --- a/submodule.c +++ b/submodule.c @@ -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' */ -- cgit 1.2.3-korg