Skip to content

Commit f9f4256

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

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

submodule.c

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

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+
201224
/*
202225
* Determine if a submodule has been populated at a given 'path'
203226
*/

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_initialized(const char *path);
4041
extern int is_submodule_populated(const char *path);
4142
int parse_submodule_update_strategy(const char *value,
4243
struct submodule_update_strategy *dst);

0 commit comments

Comments
 (0)