@@ -50,10 +50,9 @@ linkgit:gitignore[5].
with a NUL character instead of a linefeed character.
-n, --non-matching::
- Show given paths which don't match any pattern. This only
- makes sense when `--verbose` is enabled, otherwise it would
- not be possible to distinguish between paths which match a
- pattern and those which don't.
+ If `--verbose` is enabled, list both matching and non-matching
+ paths (non-matching paths along with the indicator `::`). Without
+ `--verbose`, list only the paths that do not match any pattern.
--no-index::
Don't look in the index when undertaking the checks. This can
@@ -113,8 +113,15 @@ static int check_ignore(struct dir_struct *dir,
pattern->flags & PATTERN_FLAG_NEGATIVE)
pattern = NULL;
}
- if (!quiet && (pattern || show_non_matching))
+
+ /* If --non-matching, then show if verbose or the pattern is missing. */
+ if (!quiet && show_non_matching && (verbose || !pattern))
+ output_pattern(pathspec.items[i].original, pattern);
+
+ /* If not --non-matching, then show if the pattern exists. */
+ if (!quiet && !show_non_matching && pattern)
output_pattern(pathspec.items[i].original, pattern);
+
if (pattern)
num_ignored++;
}
@@ -175,8 +182,6 @@ int cmd_check_ignore(int argc, const char **argv, const char *prefix)
if (verbose)
die(_("cannot have both --quiet and --verbose"));
}
- if (show_non_matching && !verbose)
- die(_("--non-matching is only valid with --verbose"));
/* read_cache() is only necessary so we can watch out for submodules. */
if (!no_index && read_cache() < 0)
@@ -90,7 +90,8 @@ test_check_ignore () {
# 1. with -q / --quiet
# 2. with default verbosity
# 3. with -v / --verbose
-# 4. with -v / --verbose, *and* -n / --non-matching
+# 4. with -n / --non-matching
+# 5. with -v / --verbose, *and* -n / --non-matching
#
# expecting success each time. Takes advantage of the fact that
# check-ignore --verbose output is the same as normal output except
@@ -102,7 +103,7 @@ test_check_ignore () {
# Arguments:
# - (optional) prereqs for this test, e.g. 'SYMLINKS'
# - test name
-# - output to expect from the fourth verbosity mode (the output
+# - output to expect from the fifth verbosity mode (the output
# from the other verbosity modes is automatically inferred
# from this value)
# - code to run (should invoke test_check_ignore)
@@ -124,6 +125,7 @@ test_expect_success_multiple () {
expect_verbose=$( echo "$expect_all" | grep -v '^:: ' )
expect=$( echo "$expect_verbose" | sed -e 's/.* //' )
+ expect_non_matching=$( echo "$expect_all" | grep '^:: ' | sed -e 's/.* //')
test_expect_success $prereq "$testname${no_index_opt:+ with $no_index_opt}" '
expect "$expect" &&
@@ -144,6 +146,17 @@ test_expect_success_multiple () {
quiet_opt=
fi
+ for non_matching_opt in '-n' '--non-matching'
+ do
+ test_code="
+ expect '$expect_non_matching' &&
+ $code
+ "
+ opts="${no_index_opt:+$no_index_opt }$non_matching_opt"
+ test_expect_success $prereq "$testname${opts:+ with $opts}" "$test_code"
+ done
+ non_matching_opt=
+
for verbose_opt in '-v' '--verbose'
do
for non_matching_opt in '' '-n' '--non-matching'