diff options
author | Vicent Marti <vicent@github.com> | 2014-04-16 10:51:25 +0200 |
---|---|---|
committer | Vicent Marti <vicent@github.com> | 2014-04-16 10:51:25 +0200 |
commit | 37ab5ecc107118d5fa541cb42cc203649e549fd8 (patch) | |
tree | 5908575b2522b553cad65adf69a78a9267170c2c /src | |
parent | 0f7aa47dbd16a9111e5dd054014d2f61b9b21211 (diff) | |
parent | a9528b8fdd627e11b9dee099a10fa7697380b3e7 (diff) | |
download | libgit2-37ab5ecc107118d5fa541cb42cc203649e549fd8.tar.gz |
Merge pull request #2269 from libgit2/rb/fix-leading-slash-ignores
Fix core.excludesfile named .gitignore
Diffstat (limited to 'src')
-rw-r--r-- | src/attr_file.c | 18 | ||||
-rw-r--r-- | src/ignore.c | 12 |
2 files changed, 12 insertions, 18 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 */ 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; } |