Merge pull request #5040 from pks-t/pks/ignore-treat-dirpaths-as-dir ignore: treat paths with trailing "/" as directories
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
diff --git a/src/ignore.c b/src/ignore.c
index c6e4da7..5427efa 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -534,7 +534,9 @@ int git_ignore_path_is_ignored(
memset(&path, 0, sizeof(path));
memset(&ignores, 0, sizeof(ignores));
- if (git_repository_is_bare(repo))
+ if (!git__suffixcmp(pathname, "/"))
+ dir_flag = GIT_DIR_FLAG_TRUE;
+ else if (git_repository_is_bare(repo))
dir_flag = GIT_DIR_FLAG_FALSE;
if ((error = git_attr_path__init(&path, pathname, workdir, dir_flag)) < 0 ||
diff --git a/tests/attr/ignore.c b/tests/attr/ignore.c
index 110304a..1bf06fc 100644
--- a/tests/attr/ignore.c
+++ b/tests/attr/ignore.c
@@ -397,3 +397,19 @@ void test_attr_ignore__ignored_subdirfiles_with_negations(void)
assert_is_ignored(true, "dir/sub1/c.test");
}
+void test_attr_ignore__negative_directory_rules_only_match_directories(void)
+{
+ cl_git_rewritefile(
+ "attr/.gitignore",
+ "*\n"
+ "!/**/\n"
+ "!*.keep\n"
+ "!.gitignore\n"
+ );
+
+ assert_is_ignored(true, "src");
+ assert_is_ignored(true, "src/A");
+ assert_is_ignored(false, "src/");
+ assert_is_ignored(false, "src/A.keep");
+ assert_is_ignored(false, ".gitignore");
+}