submodules: add helper to determine if a submodule is populated

Add the `is_submodule_populated()` helper function to submodules.c. `is_submodule_populated()` performes a check to see if a submodule has been checkout out (and has a valid .git directory/file) at the given path. 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 5688c28d81e9103a234efeedcb0568c2c4dd0bfb
2 files changed +16
submodule.c
+15
@@ -198,6 +198,21 @@ void gitmodules_config(void)
198 }
199 }
200
201 +/*
202 + * Determine if a submodule has been populated at a given 'path'
203 + */
204 +int is_submodule_populated(const char *path)
205 +{
206 + int ret = 0;
207 + char *gitdir = xstrfmt("%s/.git", path);
208 +
209 + if (resolve_gitdir(gitdir))
210 + ret = 1;
211 +
212 + free(gitdir);
213 + return ret;
214 +}
215 +
216 int parse_submodule_update_strategy(const char *value,
217 struct submodule_update_strategy *dst)
218 {
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_populated(const char *path);
41 int parse_submodule_update_strategy(const char *value,
42 struct submodule_update_strategy *dst);
43 const char *submodule_strategy_to_string(const struct submodule_update_strategy *s);