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>
This commit is contained in:

committed by
Junio C Hamano

parent
2c3b40799f
commit
bdab972153
29
pathspec.c
29
pathspec.c
@ -424,27 +424,6 @@ static void strip_submodule_slash_expensive(struct pathspec_item *item)
|
||||
}
|
||||
}
|
||||
|
||||
static void die_inside_submodule_path(struct pathspec_item *item)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < active_nr; i++) {
|
||||
struct cache_entry *ce = active_cache[i];
|
||||
int ce_len = ce_namelen(ce);
|
||||
|
||||
if (!S_ISGITLINK(ce->ce_mode))
|
||||
continue;
|
||||
|
||||
if (item->len < ce_len ||
|
||||
!(item->match[ce_len] == '/' || item->match[ce_len] == '\0') ||
|
||||
memcmp(ce->name, item->match, ce_len))
|
||||
continue;
|
||||
|
||||
die(_("Pathspec '%s' is in submodule '%.*s'"),
|
||||
item->original, ce_len, ce->name);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform the initialization of a pathspec_item based on a pathspec element.
|
||||
*/
|
||||
@ -547,14 +526,6 @@ static void init_pathspec_item(struct pathspec_item *item, unsigned flags,
|
||||
/* sanity checks, pathspec matchers assume these are sane */
|
||||
if (item->nowildcard_len > item->len ||
|
||||
item->prefix > item->len) {
|
||||
/*
|
||||
* This case can be triggered by the user pointing us to a
|
||||
* pathspec inside a submodule, which is an input error.
|
||||
* Detect that here and complain, but fallback in the
|
||||
* non-submodule case to a BUG, as we have no idea what
|
||||
* would trigger that.
|
||||
*/
|
||||
die_inside_submodule_path(item);
|
||||
die ("BUG: error initializing pathspec_item");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user