summaryrefslogtreecommitdiff
path: root/src/attr_file.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-04-14 15:59:48 -0700
committerRussell Belfer <rb@github.com>2014-04-14 15:59:48 -0700
commita9528b8fdd627e11b9dee099a10fa7697380b3e7 (patch)
treee7a54e8f5694d6cb37223e480bdab7e5bb104a65 /src/attr_file.c
parent289e31cd24f80fa8ed77e40eeb9295964256cb6a (diff)
downloadlibgit2-a9528b8fdd627e11b9dee099a10fa7697380b3e7.tar.gz
Fix core.excludesfile named .gitignorerb/fix-leading-slash-ignores
Ignore rules with slashes in them are matched using FNM_PATHNAME and use the path to the .gitignore file from the root of the repository along with the path fragment (including slashes) in the ignore file itself. Unfortunately, the relative path to the .gitignore file was being applied to the global core.excludesfile if that was also named ".gitignore". This fixes that with more precise matching and includes test for ignore rules with leading slashes (which were the primary example of this being broken in the real world). This also backports an improvement to the file context logic from the threadsafe-iterators branch where we don't rely on mutating the key of the attribute file name to generate the context path.
Diffstat (limited to 'src/attr_file.c')
-rw-r--r--src/attr_file.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/attr_file.c b/src/attr_file.c
index 4eb732436..ea92336f7 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -61,8 +61,7 @@ int git_attr_file__parse_buffer(
git_repository *repo, void *parsedata, const char *buffer, git_attr_file *attrs)
{
int error = 0;
- const char *scan = NULL;
- char *context = NULL;
+ const char *scan = NULL, *context = NULL;
git_attr_rule *rule = NULL;
GIT_UNUSED(parsedata);
@@ -72,10 +71,10 @@ int git_attr_file__parse_buffer(
scan = buffer;
/* if subdir file path, convert context for file paths */
- if (attrs->key && git__suffixcmp(attrs->key, "/" GIT_ATTR_FILE) == 0) {
+ if (attrs->key &&
+ git_path_root(attrs->key + 2) < 0 &&
+ git__suffixcmp(attrs->key, "/" GIT_ATTR_FILE) == 0)
context = attrs->key + 2;
- context[strlen(context) - strlen(GIT_ATTR_FILE)] = '\0';
- }
while (!error && *scan) {
/* allocate rule if needed */
@@ -115,10 +114,6 @@ int git_attr_file__parse_buffer(
git_attr_rule__free(rule);
- /* restore file path used for context */
- if (context)
- context[strlen(context)] = '.'; /* first char of GIT_ATTR_FILE */
-
return error;
}
@@ -414,7 +409,10 @@ int git_attr_fnmatch__parse(
if ((spec->flags & GIT_ATTR_FNMATCH_FULLPATH) != 0 &&
source != NULL && git_path_root(pattern) < 0)
{
- size_t sourcelen = strlen(source);
+ /* use context path minus the trailing filename */
+ char *slash = strrchr(source, '/');
+ size_t sourcelen = slash ? slash - source + 1 : 0;
+
/* given an unrooted fullpath match from a file inside a repo,
* prefix the pattern with the relative directory of the source file
*/