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 <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed Dec 16, 2016 at 11:03 UTC f9f42560e2911a5eef9a3d463a63cfd48d54dd07
2 files changed +24
submodule.c
+23
@@ -198,6 +198,29 @@ void gitmodules_config(void)
198 }
199 }
200
201 +/*
202 + * Determine if a submodule has been initialized at a given 'path'
203 + */
204 +int is_submodule_initialized(const char *path)
205 +{
206 + int ret = 0;
207 + const struct submodule *module = NULL;
208 +
209 + module = submodule_from_path(null_sha1, path);
210 +
211 + if (module) {
212 + char *key = xstrfmt("submodule.%s.url", module->name);
213 + char *value = NULL;
214 +
215 + ret = !git_config_get_string(key, &value);
216 +
217 + free(value);
218 + free(key);
219 + }
220 +
221 + return ret;
222 +}
223 +
224 /*
225 * Determine if a submodule has been populated at a given 'path'
226 */
submodule.h
+1
@@ -37,6 +37,7 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
37 const char *path);
38 int submodule_config(const char *var, const char *value, void *cb);
39 void gitmodules_config(void);
40 +extern int is_submodule_initialized(const char *path);
41 extern int is_submodule_populated(const char *path);
42 int parse_submodule_update_strategy(const char *value,
43 struct submodule_update_strategy *dst);