Skip to content

Commit ed49584

Browse files
derrickstoleegitster
authored andcommitted
dir: fix pattern matching on dirs
Within match_pathname(), one successful matching category happens when the pattern is equal to its non-wildcard prefix. At this point, we have checked that the input 'pathname' matches the pattern up to the prefix length, and then we subtraced that length from both 'patternlen' and 'namelen'. In the case of a directory match, this prefix match should be sufficient. However, the success condition only cared about _exact_ equality here. Instead, we should allow any path that agrees on this prefix in the case of PATTERN_FLAG_MUSTBEDIR. This case was not tested before because of the way unpack_trees() would match a parent directory before visiting the contained paths. This approach is changing, so we must change this comparison. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f652672 commit ed49584

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ int match_pathname(const char *pathname, int pathlen,
12941294
* then our prefix match is all we need; we
12951295
* do not need to call fnmatch at all.
12961296
*/
1297-
if (!patternlen && !namelen)
1297+
if (!patternlen && (!namelen || (flags & PATTERN_FLAG_MUSTBEDIR)))
12981298
return 1;
12991299
}
13001300

0 commit comments

Comments
 (0)