Commit 2d160ef7 by Edward Thomson

allow (ignore) bare slash in gitignore

parent 17776314
...@@ -397,7 +397,8 @@ int git_attr_fnmatch__parse( ...@@ -397,7 +397,8 @@ int git_attr_fnmatch__parse(
*base = scan; *base = scan;
spec->length = scan - pattern; if ((spec->length = scan - pattern) == 0)
return GIT_ENOTFOUND;
if (pattern[spec->length - 1] == '/') { if (pattern[spec->length - 1] == '/') {
spec->length--; spec->length--;
......
...@@ -194,6 +194,11 @@ char *git_pool_strndup(git_pool *pool, const char *str, size_t n) ...@@ -194,6 +194,11 @@ char *git_pool_strndup(git_pool *pool, const char *str, size_t n)
assert(pool && str && pool->item_size == sizeof(char)); assert(pool && str && pool->item_size == sizeof(char));
if (n + 1 == 0) {
giterr_set_oom();
return NULL;
}
if ((ptr = git_pool_malloc(pool, (uint32_t)(n + 1))) != NULL) { if ((ptr = git_pool_malloc(pool, (uint32_t)(n + 1))) != NULL) {
memcpy(ptr, str, n); memcpy(ptr, str, n);
*(((char *)ptr) + n) = '\0'; *(((char *)ptr) + n) = '\0';
......
...@@ -34,6 +34,27 @@ void test_attr_ignore__honor_temporary_rules(void) ...@@ -34,6 +34,27 @@ void test_attr_ignore__honor_temporary_rules(void)
assert_is_ignored(true, "NewFolder/NewFolder/File.txt"); assert_is_ignored(true, "NewFolder/NewFolder/File.txt");
} }
void test_attr_ignore__allow_root(void)
{
cl_git_rewritefile("attr/.gitignore", "/");
assert_is_ignored(false, "File.txt");
assert_is_ignored(false, "NewFolder");
assert_is_ignored(false, "NewFolder/NewFolder");
assert_is_ignored(false, "NewFolder/NewFolder/File.txt");
}
void test_attr_ignore__ignore_root(void)
{
cl_git_rewritefile("attr/.gitignore", "/\n\n/NewFolder\n/NewFolder/NewFolder");
assert_is_ignored(false, "File.txt");
assert_is_ignored(true, "NewFolder");
assert_is_ignored(true, "NewFolder/NewFolder");
assert_is_ignored(true, "NewFolder/NewFolder/File.txt");
}
void test_attr_ignore__skip_gitignore_directory(void) void test_attr_ignore__skip_gitignore_directory(void)
{ {
cl_git_rewritefile("attr/.git/info/exclude", "/NewFolder\n/NewFolder/NewFolder"); cl_git_rewritefile("attr/.git/info/exclude", "/NewFolder\n/NewFolder/NewFolder");
......
...@@ -133,3 +133,13 @@ void test_core_pool__free_list(void) ...@@ -133,3 +133,13 @@ void test_core_pool__free_list(void)
git_pool_clear(&p); git_pool_clear(&p);
} }
void test_core_pool__strndup_limit(void)
{
git_pool p;
cl_git_pass(git_pool_init(&p, 1, 100));
cl_assert(git_pool_strndup(&p, "foo", -1) == NULL);
git_pool_clear(&p);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment