]> git.proxmox.com Git - libgit2.git/commitdiff
allow (ignore) bare slash in gitignore
authorEdward Thomson <ethomson@microsoft.com>
Wed, 29 May 2013 21:03:30 +0000 (16:03 -0500)
committerEdward Thomson <ethomson@microsoft.com>
Wed, 29 May 2013 21:26:25 +0000 (16:26 -0500)
src/attr_file.c
src/pool.c
tests-clar/attr/ignore.c
tests-clar/core/pool.c

index 85cd87624b3044d83c0f053416d8071c06ffc309..d059cfec757f00475131d28fba1bf063ce4bd564 100644 (file)
@@ -397,7 +397,8 @@ int git_attr_fnmatch__parse(
 
        *base = scan;
 
-       spec->length = scan - pattern;
+       if ((spec->length = scan - pattern) == 0)
+               return GIT_ENOTFOUND;
 
        if (pattern[spec->length - 1] == '/') {
                spec->length--;
index b3cd49665e0ebd6ca55bcbf3c0eb2cb6576042ef..d484769e910b64e4dc768f736637211ccc8b8f2a 100644 (file)
@@ -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));
 
+       if (n + 1 == 0) {
+               giterr_set_oom();
+               return NULL;
+       }
+
        if ((ptr = git_pool_malloc(pool, (uint32_t)(n + 1))) != NULL) {
                memcpy(ptr, str, n);
                *(((char *)ptr) + n) = '\0';
index 8df0eb9de0e82629a92b7a88ba85f2ff01466aa7..0f945ebf666fb089bdddf76c10da6f2187ccc7f6 100644 (file)
@@ -34,6 +34,27 @@ void test_attr_ignore__honor_temporary_rules(void)
        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)
 {
        cl_git_rewritefile("attr/.git/info/exclude", "/NewFolder\n/NewFolder/NewFolder");
index c42bb6da0ad244e10590511803e417004444116e..3073c4a45c96c31ec3b55d02e84e1009828f1732 100644 (file)
@@ -133,3 +133,13 @@ void test_core_pool__free_list(void)
 
        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);
+}
+