]> git.ipfire.org Git - thirdparty/git.git/commitdiff
submodules: add helper to determine if a submodule is populated
authorBrandon Williams <bmwill@google.com>
Fri, 16 Dec 2016 19:03:16 +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_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>
submodule.c
submodule.h

index c85ba50110606a72776fc7a95a2c6be3875b1751..ee3198dc245a31ca47f143a6016b978b251c2ed7 100644 (file)
@@ -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)
 {
index d9e197a948fdab44b7a5df4161a5df9c3a2938ff..c4af5059813f598356a2862218a4c2cf95013eb4 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_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);