From 5688c28d81e9103a234efeedcb0568c2c4dd0bfb Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Fri, 16 Dec 2016 11:03:16 -0800 Subject: 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 Signed-off-by: Junio C Hamano --- submodule.c | 15 +++++++++++++++ submodule.h | 1 + 2 files changed, 16 insertions(+) diff --git a/submodule.c b/submodule.c index c85ba50110..ee3198dc24 100644 --- a/submodule.c +++ b/submodule.c @@ -198,6 +198,21 @@ void gitmodules_config(void) } } +/* + * Determine if a submodule has been populated at a given 'path' + */ +int is_submodule_populated(const char *path) +{ + int ret = 0; + char *gitdir = xstrfmt("%s/.git", path); + + if (resolve_gitdir(gitdir)) + ret = 1; + + free(gitdir); + return ret; +} + int parse_submodule_update_strategy(const char *value, struct submodule_update_strategy *dst) { diff --git a/submodule.h b/submodule.h index d9e197a948..c4af505981 100644 --- a/submodule.h +++ b/submodule.h @@ -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_populated(const char *path); int parse_submodule_update_strategy(const char *value, struct submodule_update_strategy *dst); const char *submodule_strategy_to_string(const struct submodule_update_strategy *s); -- cgit v1.2.3