Commit c02a0e46eb0ec68a4069edf34a537cf319be51b6

Mike McQuaid 2015-04-17T18:27:28

attr_file: fix subdirectory attr case. Closes #2966.

diff --git a/src/attr_file.c b/src/attr_file.c
index 8997946..eed3966 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -394,6 +394,7 @@ bool git_attr_fnmatch__match(
 
 	if ((match->flags & GIT_ATTR_FNMATCH_DIRECTORY) && !path->is_dir) {
 		int matchval;
+		char *matchpath;
 
 		/* for attribute checks or root ignore checks, fail match */
 		if (!(match->flags & GIT_ATTR_FNMATCH_IGNORE) ||
@@ -403,7 +404,13 @@ bool git_attr_fnmatch__match(
 		/* for ignore checks, use container of current item for check */
 		path->basename[-1] = '\0';
 		flags |= FNM_LEADING_DIR;
-		matchval = p_fnmatch(match->pattern, path->path, flags);
+
+		if (match->containing_dir)
+			matchpath = path->basename;
+		else
+			matchpath = path->path;
+
+		matchval = p_fnmatch(match->pattern, matchpath, flags);
 		path->basename[-1] = '/';
 		return (matchval != FNM_NOMATCH);
 	}