Merge pull request #966 from pwkelley/icasefix Fix a bug where ignorecase wasn't applied to ignores
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
diff --git a/src/ignore.c b/src/ignore.c
index c562f4e..e711be2 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -48,13 +48,14 @@ static int parse_ignore_file(
match->flags = GIT_ATTR_FNMATCH_ALLOWSPACE;
- if (ignore_case)
- match->flags |= GIT_ATTR_FNMATCH_ICASE;
-
if (!(error = git_attr_fnmatch__parse(
match, ignores->pool, context, &scan)))
{
- match->flags = match->flags | GIT_ATTR_FNMATCH_IGNORE;
+ match->flags |= GIT_ATTR_FNMATCH_IGNORE;
+
+ if (ignore_case)
+ match->flags |= GIT_ATTR_FNMATCH_ICASE;
+
scan = git__next_line(scan);
error = git_vector_insert(&ignores->rules, match);
}
diff --git a/tests-clar/status/ignore.c b/tests-clar/status/ignore.c
index 9092d51..d18ba78 100644
--- a/tests-clar/status/ignore.c
+++ b/tests-clar/status/ignore.c
@@ -1,6 +1,7 @@
#include "clar_libgit2.h"
#include "fileops.h"
#include "git2/attr.h"
+#include "ignore.h"
#include "attr.h"
#include "status_helpers.h"
@@ -152,6 +153,26 @@ void test_status_ignore__ignore_pattern_contains_space(void)
cl_assert(flags == GIT_STATUS_WT_NEW);
}
+void test_status_ignore__ignore_pattern_ignorecase(void)
+{
+ unsigned int flags;
+ const mode_t mode = 0777;
+ bool ignore_case;
+ git_index *index;
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+ cl_git_rewritefile("empty_standard_repo/.gitignore", "a.txt\n");
+
+ cl_git_mkfile("empty_standard_repo/A.txt", "Differs in case");
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+ ignore_case = index->ignore_case;
+ git_index_free(index);
+
+ cl_git_pass(git_status_file(&flags, g_repo, "A.txt"));
+ cl_assert(flags == ignore_case ? GIT_STATUS_IGNORED : GIT_STATUS_WT_NEW);
+}
+
void test_status_ignore__adding_internal_ignores(void)
{
int ignored;