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.
This commit is contained in:
Edward Thomson 2015-05-12 16:02:18 -04:00
parent 30e629a073
commit 9465bedb09

View File

@ -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);
}