All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Carl Smedstad via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Carl Smedstad <carl.smedstad@protonmail.com>,
	Carl Smedstad <carl.smedstad@protonmail.com>
Subject: [PATCH] check-ignore: --non-matching without --verbose
Date: Mon, 23 May 2022 12:54:25 +0000	[thread overview]
Message-ID: <pull.1236.git.1653310466062.gitgitgadget@gmail.com> (raw)

From: Carl Smedstad <carl.smedstad@protonmail.com>

Allow --non-matching to be specified without the --verbose flag to make
git only list files that are not matching any pattern. The behaviour
when specifying both --non-matching and --verbose is unchanged.

The motivation for this is to use the underutilized invocation of
--non-matching without --verbose to create a shorthand for what could be
achieved by:

    find . |
      git check-ignore --verbose --non-matching |
      grep $'^::\t' |
      sed -e 's/.*\t//'

Signed-off-by: Carl Smedstad <carl.smedstad@protonmail.com>
---
    check-ignore: --non-matching without --verbose
    
    Allow --non-matching to be specified without the --verbose flag to make
    git only list files that are not matching any pattern. The behaviour
    when specifying both --non-matching and --verbose is unchanged.
    
    The motivation for this is to use the underutilized invocation of
    --non-matching without --verbose to create a shorthand for what could be
    achieved by:
    
    find . |
      git check-ignore --verbose --non-matching |
      grep $'^::\t' |
      sed -e 's/.*\t//'
    
    
    Signed-off-by: Carl Smedstad carl.smedstad@protonmail.com

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1236%2Fcarlsmedstad%2Fcheck-ignore-non-matching-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1236/carlsmedstad/check-ignore-non-matching-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1236

 Documentation/git-check-ignore.txt |  6 ++----
 builtin/check-ignore.c             | 15 +++++++++++----
 t/t0008-ignores.sh                 | 17 +++++++++++++++--
 3 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/Documentation/git-check-ignore.txt b/Documentation/git-check-ignore.txt
index 2892799e32f..69d12fd22e1 100644
--- a/Documentation/git-check-ignore.txt
+++ b/Documentation/git-check-ignore.txt
@@ -50,10 +50,8 @@ 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.
+	Only show given paths which don't match any pattern. If `--verbose` is
+	enabled, show both paths that match a pattern and those which don't.
 
 --no-index::
 	Don't look in the index when undertaking the checks. This can
diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
index 21912569650..10e8bba1057 100644
--- a/builtin/check-ignore.c
+++ b/builtin/check-ignore.c
@@ -113,8 +113,17 @@ static int check_ignore(struct dir_struct *dir,
 			    pattern->flags & PATTERN_FLAG_NEGATIVE)
 				pattern = NULL;
 		}
-		if (!quiet && (pattern || show_non_matching))
-			output_pattern(pathspec.items[i].original, pattern);
+		if (!quiet) {
+			if (verbose) {
+				if (show_non_matching || pattern)
+					output_pattern(pathspec.items[i].original, pattern);
+			} else {
+				if (show_non_matching && !pattern)
+					output_pattern(pathspec.items[i].original, pattern);
+				if (!show_non_matching && pattern)
+					output_pattern(pathspec.items[i].original, pattern);
+			}
+		}
 		if (pattern)
 			num_ignored++;
 	}
@@ -175,8 +184,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)
diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh
index 5575dade8ee..2ea178797bc 100755
--- a/t/t0008-ignores.sh
+++ b/t/t0008-ignores.sh
@@ -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'

base-commit: f9b95943b68b6b8ca5a6072f50a08411c6449b55
-- 
gitgitgadget

             reply	other threads:[~2022-05-23 12:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-23 12:54 Carl Smedstad via GitGitGadget [this message]
2022-05-23 18:14 ` [PATCH] check-ignore: --non-matching without --verbose Junio C Hamano
2022-05-24 13:03   ` Carl Smedstad
2022-05-24 19:18     ` Junio C Hamano
2022-05-24 19:26       ` Ævar Arnfjörð Bjarmason
2022-05-23 20:44 ` Derrick Stolee
2022-05-24 13:06   ` Carl Smedstad
2022-05-24 13:01 ` [PATCH v2] " Carl Smedstad via GitGitGadget
2022-05-24 17:45 ` [PATCH] " Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.1236.git.1653310466062.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=carl.smedstad@protonmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.