Fix rejection of parent dir of negated ignores

While scanning through a directory hierarchy, this prevents a
positive ignore match on a parent directory from blocking the scan
of a directory when a negative match rule exists for files inside
the directory.
This commit is contained in:
Russell Belfer 2014-08-08 14:51:36 -07:00
parent 35f186b6ca
commit f25bc0b2e6
2 changed files with 20 additions and 0 deletions

View File

@ -378,6 +378,18 @@ bool git_attr_fnmatch__match(
return (matchval != FNM_NOMATCH);
}
/* if path is a directory prefix of a negated pattern, then match */
if ((match->flags & GIT_ATTR_FNMATCH_NEGATIVE) && path->is_dir) {
size_t pathlen = strlen(path->path);
bool prefixed = (pathlen <= match->length) &&
((match->flags & GIT_ATTR_FNMATCH_ICASE) ?
!strncasecmp(match->pattern, path->path, pathlen) :
!strncmp(match->pattern, path->path, pathlen));
if (prefixed && git_path_at_end_of_segment(&match->pattern[pathlen]))
return true;
}
return (p_fnmatch(match->pattern, filename, flags) != FNM_NOMATCH);
}

View File

@ -128,6 +128,14 @@ GIT_INLINE(int) git_path_is_relative(const char *p)
return (p[0] == '.' && (p[1] == '/' || (p[1] == '.' && p[2] == '/')));
}
/**
* Check if string is at end of path segment (i.e. looking at '/' or '\0')
*/
GIT_INLINE(int) git_path_at_end_of_segment(const char *p)
{
return !*p || *p == '/';
}
extern int git__percent_decode(git_buf *decoded_out, const char *input);
/**