Skip to content

Commit 16a4bf1

Browse files
committed
Merge branch 'en/check-ignore' into maint
"git check-ignore" did not work when the given path is explicitly marked as not ignored with a negative entry in the .gitignore file. * en/check-ignore: check-ignore: fix documentation and implementation to match
2 parents 3246495 + 7ec8125 commit 16a4bf1

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

Documentation/git-check-ignore.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,15 @@ OPTIONS
3030
valid with a single pathname.
3131

3232
-v, --verbose::
33-
Also output details about the matching pattern (if any)
34-
for each given pathname. For precedence rules within and
35-
between exclude sources, see linkgit:gitignore[5].
33+
Instead of printing the paths that are excluded, for each path
34+
that matches an exclude pattern, print the exclude pattern
35+
together with the path. (Matching an exclude pattern usually
36+
means the path is excluded, but if the pattern begins with '!'
37+
then it is a negated pattern and matching it means the path is
38+
NOT excluded.)
39+
+
40+
For precedence rules within and between exclude sources, see
41+
linkgit:gitignore[5].
3642

3743
--stdin::
3844
Read pathnames from the standard input, one per line,

builtin/check-ignore.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ static int check_ignore(struct dir_struct *dir,
108108
int dtype = DT_UNKNOWN;
109109
pattern = last_matching_pattern(dir, &the_index,
110110
full_path, &dtype);
111+
if (!verbose && pattern &&
112+
pattern->flags & PATTERN_FLAG_NEGATIVE)
113+
pattern = NULL;
111114
}
112115
if (!quiet && (pattern || show_non_matching))
113116
output_pattern(pathspec.items[i].original, pattern);

t/t0008-ignores.sh

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,24 @@ test_expect_success 'local ignore inside a sub-directory with --verbose' '
424424
)
425425
'
426426

427-
test_expect_success_multi 'nested include' \
428-
'a/b/.gitignore:8:!on* a/b/one' '
429-
test_check_ignore "a/b/one"
427+
test_expect_success 'nested include of negated pattern' '
428+
expect "" &&
429+
test_check_ignore "a/b/one" 1
430+
'
431+
432+
test_expect_success 'nested include of negated pattern with -q' '
433+
expect "" &&
434+
test_check_ignore "-q a/b/one" 1
435+
'
436+
437+
test_expect_success 'nested include of negated pattern with -v' '
438+
expect "a/b/.gitignore:8:!on* a/b/one" &&
439+
test_check_ignore "-v a/b/one" 0
440+
'
441+
442+
test_expect_success 'nested include of negated pattern with -v -n' '
443+
expect "a/b/.gitignore:8:!on* a/b/one" &&
444+
test_check_ignore "-v -n a/b/one" 0
430445
'
431446

432447
############################################################################
@@ -460,7 +475,6 @@ test_expect_success 'cd to ignored sub-directory' '
460475
expect_from_stdin <<-\EOF &&
461476
foo
462477
twoooo
463-
../one
464478
seven
465479
../../one
466480
EOF
@@ -543,7 +557,6 @@ test_expect_success 'global ignore' '
543557
globalthree
544558
a/globalthree
545559
a/per-repo
546-
globaltwo
547560
EOF
548561
test_check_ignore "globalone per-repo globalthree a/globalthree a/per-repo not-ignored globaltwo"
549562
'
@@ -586,17 +599,7 @@ EOF
586599
cat <<-\EOF >expected-default
587600
one
588601
a/one
589-
a/b/on
590-
a/b/one
591-
a/b/one one
592-
a/b/one two
593-
"a/b/one\"three"
594-
a/b/two
595602
a/b/twooo
596-
globaltwo
597-
a/globaltwo
598-
a/b/globaltwo
599-
b/globaltwo
600603
EOF
601604
cat <<-EOF >expected-verbose
602605
.gitignore:1:one one
@@ -696,8 +699,12 @@ cat <<-EOF >expected-all
696699
$global_excludes:2:!globaltwo ../b/globaltwo
697700
:: c/not-ignored
698701
EOF
702+
cat <<-EOF >expected-default
703+
../one
704+
one
705+
b/twooo
706+
EOF
699707
grep -v '^:: ' expected-all >expected-verbose
700-
sed -e 's/.* //' expected-verbose >expected-default
701708

702709
broken_c_unquote stdin >stdin0
703710

0 commit comments

Comments
 (0)