For a pathspec like 'foo/bar' comparing against a path named "foo/", namelen will be 4, and match[namelen] will be 'b'. The correct location of the directory separator is namelen-1. The reason the code worked anyway was that the following code immediately checked whether the first matchlen characters matched (which they do) and then bailed and return MATCHED_RECURSIVELY anyway since wildmatch doesn't have the ability to check if "name" can be matched as a directory (or prefix) against the pathspec. Signed-off-by: Elijah Newren <newren@xxxxxxxxx> --- dir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dir.c b/dir.c index 19212129f0..c915a69385 100644 --- a/dir.c +++ b/dir.c @@ -384,7 +384,7 @@ static int match_pathspec_item(const struct pathspec_item *item, int prefix, if (flags & DO_MATCH_SUBMODULE) { /* name is a literal prefix of the pathspec */ if ((namelen < matchlen) && - (match[namelen] == '/') && + (match[namelen-1] == '/') && !ps_strncmp(item, match, name, namelen)) return MATCHED_RECURSIVELY; -- 2.17.0.7.g0b50f94d69