Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 68690fd

Browse files
pcloudsgitster
authored andcommitted
match_pathspec: match pathspec "foo/" against directory "foo"
Currently we do support matching pathspec "foo/" against directory "foo". That is because match_pathspec() has no way to tell "foo" is a directory and matching "foo/" against _file_ "foo" is wrong. The callers can now tell match_pathspec if "foo" is a directory, we could make an exception for this case. Code is not executed though because no callers pass the flag yet. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 42b0874 commit 68690fd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

dir.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ int within_depth(const char *name, int namelen,
196196
}
197197

198198
#define DO_MATCH_EXCLUDE 1
199+
#define DO_MATCH_DIRECTORY 2
199200

200201
/*
201202
* Does 'match' match the given name?
@@ -259,7 +260,11 @@ static int match_pathspec_item(const struct pathspec_item *item, int prefix,
259260

260261
if (match[matchlen-1] == '/' || name[matchlen] == '/')
261262
return MATCHED_RECURSIVELY;
262-
}
263+
} else if ((flags & DO_MATCH_DIRECTORY) &&
264+
match[matchlen - 1] == '/' &&
265+
namelen == matchlen - 1 &&
266+
!ps_strncmp(item, match, name, namelen))
267+
return MATCHED_EXACTLY;
263268

264269
if (item->nowildcard_len < item->len &&
265270
!git_fnmatch(item, match, name,

0 commit comments

Comments
 (0)