check-ignore: fix mix of directories and other file types
In check_ignore(), the first pathspec item determines the dtype for any subsequent ones. That means that a pathspec matching a regular file can prevent following pathspecs from matching directories, which makes no sense. Fix that by determining the dtype for each pathspec separately, by passing the value DT_UNKNOWN to last_exclude_matching() each time. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Feb 10, 2018 at 13:38 UTC
d60771e93046e9e11183c6ff1fcafd334f8c0453
2 files changed
+22
-1
builtin/check-ignore.c
+2
-1
@@ -72,7 +72,7 @@ static int check_ignore(struct dir_struct *dir,
72
{
73
const char *full_path;
74
char *seen;
75
- int num_ignored = 0, dtype = DT_UNKNOWN, i;
75
+ int num_ignored = 0, i;
76
struct exclude *exclude;
77
struct pathspec pathspec;
78
@@ -104,6 +104,7 @@ static int check_ignore(struct dir_struct *dir,
104
full_path = pathspec.items[i].match;
105
exclude = NULL;
106
if (!seen[i]) {
107
+ int dtype = DT_UNKNOWN;
108
exclude = last_exclude_matching(dir, &the_index,
109
full_path, &dtype);
110
}
t/t0008-ignores.sh
+20
@@ -775,6 +775,26 @@ test_expect_success PIPE 'streaming support for --stdin' '
775
echo "$response" | grep "^:: two"
776
'
777
778
+test_expect_success 'existing file and directory' '
779
+ test_when_finished "rm one" &&
780
+ test_when_finished "rmdir top-level-dir" &&
781
+ >one &&
782
+ mkdir top-level-dir &&
783
+ git check-ignore one top-level-dir >actual &&
784
+ grep one actual &&
785
+ grep top-level-dir actual
786
+'
787
+
788
+test_expect_success 'existing directory and file' '
789
+ test_when_finished "rm one" &&
790
+ test_when_finished "rmdir top-level-dir" &&
791
+ >one &&
792
+ mkdir top-level-dir &&
793
+ git check-ignore top-level-dir one >actual &&
794
+ grep one actual &&
795
+ grep top-level-dir actual
796
+'
797
+
798
############################################################################
799
#
800
# test whitespace handling