Skip to content

Commit 5688c28

Browse files
bmwillgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e9a379c commit 5688c28

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

submodule.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,21 @@ void gitmodules_config(void)
198198
}
199199
}
200200

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+
201216
int parse_submodule_update_strategy(const char *value,
202217
struct submodule_update_strategy *dst)
203218
{

submodule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
3737
const char *path);
3838
int submodule_config(const char *var, const char *value, void *cb);
3939
void gitmodules_config(void);
40+
extern int is_submodule_populated(const char *path);
4041
int parse_submodule_update_strategy(const char *value,
4142
struct submodule_update_strategy *dst);
4243
const char *submodule_strategy_to_string(const struct submodule_update_strategy *s);

0 commit comments

Comments
 (0)