Unverified Commit 17d6cd45 by Edward Thomson Committed by GitHub

Merge pull request #5210 from buddyspike/master

ignore: correct handling of nested rules overriding wild card unignore
parents 4d3392dd a7b4b639
......@@ -444,7 +444,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;
......@@ -458,8 +458,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;
}
......
......@@ -1290,3 +1290,47 @@ void test_ignore_status__leading_spaces_are_significant(void)
assert_is_ignored(" # not a comment");
assert_is_ignored("d.test");
}
void test_ignore_status__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