diff options
author | Brandon Williams <bmwill@google.com> | 2017-05-09 22:17:59 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-05-10 08:47:39 +0300 |
commit | bdab972153a73815e04e9699406433e409ed28ab (patch) | |
tree | 0f6210c3fbab3473680f3459cf69d498e0ea6319 /submodule.c | |
parent | 2c3b40799fcdb9d2dedc90134e4f3841af08bbe7 (diff) |
submodule: add die_in_unpopulated_submodule function
Currently 'git add' is the only command which dies when launched from an
unpopulated submodule (the place-holder directory for a submodule which
hasn't been checked out). This is triggered implicitly by passing the
PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE flag to 'parse_pathspec()'.
Instead make this desire more explicit by creating a function
'die_in_unpopulated_submodule()' which dies if the provided 'prefix' has
a leading path component which matches a submodule in the the index.
Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'submodule.c')
-rw-r--r-- | submodule.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/submodule.c b/submodule.c index d3299e29c0..885663c421 100644 --- a/submodule.c +++ b/submodule.c @@ -282,6 +282,36 @@ int is_submodule_populated_gently(const char *path, int *return_error_code) return ret; } +/* + * Dies if the provided 'prefix' corresponds to an unpopulated submodule + */ +void die_in_unpopulated_submodule(const struct index_state *istate, + const char *prefix) +{ + int i, prefixlen; + + if (!prefix) + return; + + prefixlen = strlen(prefix); + + for (i = 0; i < istate->cache_nr; i++) { + struct cache_entry *ce = istate->cache[i]; + int ce_len = ce_namelen(ce); + + if (!S_ISGITLINK(ce->ce_mode)) + continue; + if (prefixlen <= ce_len) + continue; + if (strncmp(ce->name, prefix, ce_len)) + continue; + if (prefix[ce_len] != '/') + continue; + + die(_("in unpopulated submodule '%s'"), ce->name); + } +} + int parse_submodule_update_strategy(const char *value, struct submodule_update_strategy *dst) { |