Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/libgit2/attr_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ int git_attr_file__parse_buffer(
{
const char *scan = data, *context = NULL;
git_attr_rule *rule = NULL;
int error = 0;
int ignorecase = 0, error = 0;

/* If subdir file path, convert context for file paths */
if (attrs->entry && git_fs_path_root(attrs->entry->path) < 0 &&
Expand Down Expand Up @@ -379,6 +379,13 @@ int git_attr_file__parse_buffer(
continue;
}

if (repo &&
(error = git_repository__configmap_lookup(&ignorecase, repo, GIT_CONFIGMAP_IGNORECASE)) < 0)
goto out;

if (ignorecase)
rule->match.flags |= GIT_ATTR_FNMATCH_ICASE;

if (rule->match.flags & GIT_ATTR_FNMATCH_MACRO) {
/* TODO: warning if macro found in file below repo root */
if (!allow_macros)
Expand Down Expand Up @@ -482,7 +489,7 @@ bool git_attr_fnmatch__match(
*/
if (match->containing_dir) {
if (match->flags & GIT_ATTR_FNMATCH_ICASE) {
if (git__strncasecmp(path->path, match->containing_dir, match->containing_dir_length))
if (git__prefixcmp_icase(path->path, match->containing_dir))
return 0;
} else {
if (git__prefixcmp(path->path, match->containing_dir))
Expand Down
12 changes: 12 additions & 0 deletions tests/libgit2/filter/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ void test_filter_query__filters(void)
cl_assert_equal_i(1, filter_for("id.binident", "ident"));
}

void test_filter_query__filters_ignorecase(void)
{
if (!cl_repo_get_bool(g_repo, "core.ignorecase"))
cl_skip();

cl_assert_equal_i(1, filter_for("TEXT.TXT", "crlf"));
cl_assert_equal_i(0, filter_for("Binary.bin", "crlf"));

cl_assert_equal_i(1, filter_for("id.Ident", "crlf"));
cl_assert_equal_i(1, filter_for("ID.IdEnT", "ident"));
}

void test_filter_query__autocrlf_true_implies_crlf(void)
{
cl_repo_set_bool(g_repo, "core.autocrlf", true);
Expand Down
Loading