attr: regression tests for ignore matching Ensure that when examining a .gitignore in a subdirectory, we do not erroneously apply the paths contained therein to the root of the repository. (Fixed in c02a0e4).
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
diff --git a/tests/attr/ignore.c b/tests/attr/ignore.c
index aa5b870..1f40800 100644
--- a/tests/attr/ignore.c
+++ b/tests/attr/ignore.c
@@ -191,3 +191,35 @@ void test_attr_ignore__expand_tilde_to_homedir(void)
assert_is_ignored(false, "example.global_with_tilde");
}
+
+/* Ensure that the .gitignore in the subdirectory only affects
+ * items in the subdirectory. */
+void test_attr_ignore__gitignore_in_subdir(void)
+{
+ cl_git_rmfile("attr/.gitignore");
+
+ cl_must_pass(p_mkdir("attr/dir1", 0777));
+ cl_must_pass(p_mkdir("attr/dir1/dir2", 0777));
+ cl_must_pass(p_mkdir("attr/dir1/dir2/dir3", 0777));
+
+ cl_git_mkfile("attr/dir1/dir2/dir3/.gitignore", "dir1/\ndir1/subdir/");
+
+ assert_is_ignored(false, "dir1/file");
+ assert_is_ignored(false, "dir1/dir2/file");
+ assert_is_ignored(false, "dir1/dir2/dir3/file");
+ assert_is_ignored(false, "dir1/dir2/dir3/dir1");
+ assert_is_ignored(true, "dir1/dir2/dir3/dir1/file");
+ assert_is_ignored(true, "dir1/dir2/dir3/dir1/subdir/foo");
+
+ if (cl_repo_get_bool(g_repo, "core.ignorecase")) {
+ cl_git_mkfile("attr/dir1/dir2/dir3/.gitignore", "DiR1/\nDiR1/subdir/\n");
+
+ assert_is_ignored(false, "dir1/file");
+ assert_is_ignored(false, "dir1/dir2/file");
+ assert_is_ignored(false, "dir1/dir2/dir3/file");
+ assert_is_ignored(false, "dir1/dir2/dir3/dir1");
+ assert_is_ignored(true, "dir1/dir2/dir3/dir1/file");
+ assert_is_ignored(true, "dir1/dir2/dir3/dir1/subdir/foo");
+ }
+}
+