Commit 9465bedb097078355ea4131a839d15f242cd4652

Edward Thomson 2015-05-12T16:02:18

attr: don't mangle file path during attr matching When determining whether some file matches an attr pattern, do not try to truncate the path to pass to fnmatch. When there is no containing directory for an item (eg, from a .gitignore in the root) this will cause us to truncate our path, which means that we cannot do meaningful comparisons on it and we may have false positives when trying to determine whether a given file is actually a file or a folder (as we have lost the path's base information.) This mangling was to allow fnmatch to compare a directory on disk to the name of a directory, but it is unnecessary as our fnmatch accepts FNM_LEADING_DIR.

diff --git a/src/attr_file.c b/src/attr_file.c
index a7cc591..5ec5b44 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -401,10 +401,9 @@ bool git_attr_fnmatch__match(
 			path->basename == path->path)
 			return false;
 
-		/* for ignore checks, use container of current item for check */
-		path->basename[-1] = '\0';
 		flags |= FNM_LEADING_DIR;
 
+		/* for ignore checks, use container of current item for check */
 		if (match->containing_dir)
 			matchpath = path->basename;
 		else
@@ -419,7 +418,7 @@ bool git_attr_fnmatch__match(
 			return false;
 
 		matchval = p_fnmatch(match->pattern, matchpath, flags);
-		path->basename[-1] = '/';
+
 		return (matchval != FNM_NOMATCH);
 	}