summaryrefslogtreecommitdiff
path: root/src/ignore.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/ignore.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/ignore.c')
-rw-r--r--src/ignore.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/ignore.c b/src/ignore.c
index aef3e39b4..5cf4fca5c 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -14,8 +14,7 @@ static int parse_ignore_file(
{
int error = 0;
git_attr_fnmatch *match = NULL;
- const char *scan = NULL;
- char *context = NULL;
+ const char *scan = NULL, *context = NULL;
int ignore_case = false;
/* Prefer to have the caller pass in a git_ignores as the parsedata
@@ -25,10 +24,10 @@ static int parse_ignore_file(
else if (git_repository__cvar(&ignore_case, repo, GIT_CVAR_IGNORECASE) < 0)
return error;
- if (ignores->key && git__suffixcmp(ignores->key, "/" GIT_IGNORE_FILE) == 0) {
+ if (ignores->key &&
+ git_path_root(ignores->key + 2) < 0 &&
+ git__suffixcmp(ignores->key, "/" GIT_IGNORE_FILE) == 0)
context = ignores->key + 2;
- context[strlen(context) - strlen(GIT_IGNORE_FILE)] = '\0';
- }
scan = buffer;
@@ -64,9 +63,6 @@ static int parse_ignore_file(
}
git__free(match);
- /* restore file path used for context */
- if (context)
- context[strlen(context)] = '.'; /* first char of GIT_IGNORE_FILE */
return error;
}