Skip to content

Commit d60771e

Browse files
rscharfegitster
authored andcommitted
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>
1 parent fc849d8 commit d60771e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

builtin/check-ignore.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static int check_ignore(struct dir_struct *dir,
7272
{
7373
const char *full_path;
7474
char *seen;
75-
int num_ignored = 0, dtype = DT_UNKNOWN, i;
75+
int num_ignored = 0, i;
7676
struct exclude *exclude;
7777
struct pathspec pathspec;
7878

@@ -104,6 +104,7 @@ static int check_ignore(struct dir_struct *dir,
104104
full_path = pathspec.items[i].match;
105105
exclude = NULL;
106106
if (!seen[i]) {
107+
int dtype = DT_UNKNOWN;
107108
exclude = last_exclude_matching(dir, &the_index,
108109
full_path, &dtype);
109110
}

t/t0008-ignores.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,26 @@ test_expect_success PIPE 'streaming support for --stdin' '
775775
echo "$response" | grep "^:: two"
776776
'
777777

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+
778798
############################################################################
779799
#
780800
# test whitespace handling

0 commit comments

Comments
 (0)