Commit 99b89a9c by buddyspike Committed by Patrick Steinhardt

ignore: correct handling of nested rules overriding wild card unignore

problem:
filesystem_iterator loads .gitignore files in top-down order.
subsequently, ignore module evaluates them in the order they are loaded.
this creates a problem if we have unignored a rule (using a wild card)
in a sub dir and ignored it again in a level further below (see the test
included in this patch).

solution:
process ignores in reverse order.

closes #4963
parent 5e5a9cce
......@@ -453,7 +453,7 @@ static bool ignore_lookup_in_rules(
int git_ignore__lookup(
int *out, git_ignores *ignores, const char *pathname, git_dir_flag dir_flag)
{
unsigned int i;
size_t i;
git_attr_file *file;
git_attr_path path;
......@@ -467,8 +467,11 @@ int git_ignore__lookup(
if (ignore_lookup_in_rules(out, ignores->ign_internal, &path))
goto cleanup;
/* next process files in the path */
git_vector_foreach(&ignores->ign_path, i, file) {
/* next process files in the path.
* this process has to process ignores in reverse order
* to ensure correct prioritization of rules
*/
git_vector_rforeach(&ignores->ign_path, i, file) {
if (ignore_lookup_in_rules(out, file, &path))
goto cleanup;
}
......
......@@ -1213,3 +1213,47 @@ void test_status_ignore__unignored_subdirs(void)
assert_is_ignored("dir/a.test");
refute_is_ignored("dir/subdir/a.test");
}
void test_status_ignore__override_nested_wildcard_unignore(void)
{
git_repository *repo = cl_git_sandbox_init("empty_standard_repo");
git_status_list *statuslist;
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
const git_status_entry *status;
cl_git_pass(git_futils_mkdir_r("empty_standard_repo/dir", 0777));
cl_git_pass(git_futils_mkdir_r("empty_standard_repo/dir/subdir", 0777));
cl_git_mkfile("empty_standard_repo/.gitignore", "a.test\n");
cl_git_mkfile("empty_standard_repo/dir/.gitignore", "!*.test\n");
cl_git_mkfile("empty_standard_repo/dir/subdir/.gitignore", "a.test\n");
cl_git_mkfile("empty_standard_repo/dir/a.test", "pong");
cl_git_mkfile("empty_standard_repo/dir/subdir/a.test", "pong");
opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
cl_git_pass(git_status_list_new(&statuslist, repo, &opts));
cl_assert_equal_sz(4, git_status_list_entrycount(statuslist));
status = git_status_byindex(statuslist, 0);
cl_assert(status != NULL);
cl_assert_equal_s(".gitignore", status->index_to_workdir->old_file.path);
cl_assert_equal_i(GIT_STATUS_WT_NEW, status->status);
status = git_status_byindex(statuslist, 1);
cl_assert(status != NULL);
cl_assert_equal_s("dir/.gitignore", status->index_to_workdir->old_file.path);
cl_assert_equal_i(GIT_STATUS_WT_NEW, status->status);
status = git_status_byindex(statuslist, 2);
cl_assert(status != NULL);
cl_assert_equal_s("dir/a.test", status->index_to_workdir->old_file.path);
cl_assert_equal_i(GIT_STATUS_WT_NEW, status->status);
status = git_status_byindex(statuslist, 3);
cl_assert(status != NULL);
cl_assert_equal_s("dir/subdir/.gitignore", status->index_to_workdir->old_file.path);
cl_assert_equal_i(GIT_STATUS_WT_NEW, status->status);
git_status_list_free(statuslist);
}
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