Skip to contentSkip to conversation

check-ignore: Add option to ignore index contents

PATCH Superseded Dave Williams 2 participants 2 messages Jun 15, 2016 Documentation

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 check-ignore: Add option to ignore index contents

I have updated the original version of this patch to encompass the feedback comments obtained. Updates include:
1) Rename option to --no-index for consistency with other commands
2) Improved Documentation text
3) Extension to test scripts to include this option

Regarding test scripts I have scoped coverage to ensure correct behaviour with the new option in all standard cases but without duplicating every single corner case.

The original patch is at $gmane/233381.

check-ignore currently shows how .gitignore rules would treat untracked paths. Tracked paths do not generate useful output. This prevents debugging of why a path became tracked unexpectedly unless that path is first removed from the index with git rm --cached <path>.

This option (-i, --no-index) simply by-passes the check for the path being in the index and hence allows tracked paths to be checked too.

Whilst this behaviour deviates from the characteristics of git add and git status its use case is unlikely to cause any user confusion.

Test scripts are augmented to check this option against the standard ignores to ensure correct behaviour.

---
 Documentation/git-check-ignore.txt |  7 ++++
 builtin/check-ignore.c             | 14 ++++---
 t/t0008-ignores.sh                 | 77 +++++++++++++++++++++++++++++++++-----
 3 files changed, 83 insertions(+), 15 deletions(-)
Documentation/git-check-ignore.txt +7 -0
index d2df487..96c591f 100644
@@ -45,6 +45,13 @@ OPTIONS
 	not be possible to distinguish between paths which match a
 	pattern and those which don't.
 
+-i, --no-index::
+	Don't look in the index when undertaking the checks. This can
+	be used to debug why a path became tracked by e.g. `git add .`
+	and was not ignored by the rules as expected by the user or when
+	developing patterns including negation to match a path previously
+	added with `git add -f`.
+
 OUTPUT
 ------
 
builtin/check-ignore.c +9 -5
index 4a8fc70..2b0c8a6 100644
@@ -5,7 +5,7 @@
 #include "pathspec.h"
 #include "parse-options.h"
 
-static int quiet, verbose, stdin_paths, show_non_matching;
+static int quiet, verbose, stdin_paths, show_non_matching, no_index;
 static const char * const check_ignore_usage[] = {
 "git check-ignore [options] pathname...",
 "git check-ignore [options] --stdin < <list-of-paths>",
@@ -24,6 +24,8 @@ static const struct option check_ignore_options[] = {
 		    N_("input paths are terminated by a null character")),
 	OPT_BOOLEAN('n', "non-matching", &show_non_matching,
 		    N_("show non-matching input paths")),
+	OPT_BOOLEAN('i', "no-index", &no_index,
+		    N_("ignore index when checking")),
 	OPT_END()
 };
 
@@ -67,7 +69,7 @@ static int check_ignore(struct dir_struct *dir,
 			const char *prefix, const char **pathspec)
 {
 	const char *path, *full_path;
-	char *seen;
+	char *seen = NULL;
 	int num_ignored = 0, dtype = DT_UNKNOWN, i;
 	struct exclude *exclude;
 
@@ -82,7 +84,9 @@ static int check_ignore(struct dir_struct *dir,
 	 * should not be ignored, in order to be consistent with
 	 * 'git status', 'git add' etc.
 	 */
-	seen = find_pathspecs_matching_against_index(pathspec);
+	if (!no_index) {
+		seen = find_pathspecs_matching_against_index(pathspec);
+	}
 	for (i = 0; pathspec[i]; i++) {
 		path = pathspec[i];
 		full_path = prefix_path(prefix, prefix
@@ -90,7 +94,7 @@ static int check_ignore(struct dir_struct *dir,
 		full_path = check_path_for_gitlink(full_path);
 		die_if_path_beyond_symlink(full_path, prefix);
 		exclude = NULL;
-		if (!seen[i]) {
+		if (no_index || !seen[i]) {
 			exclude = last_exclude_matching(dir, full_path, &dtype);
 		}
 		if (!quiet && (exclude || show_non_matching))
@@ -157,7 +161,7 @@ int cmd_check_ignore(int argc, const char **argv, const char *prefix)
 		die(_("--non-matching is only valid with --verbose"));
 
 	/* read_cache() is only necessary so we can watch out for submodules. */
-	if (read_cache() < 0)
+	if (!no_index && read_cache() < 0)
 		die(_("index file corrupt"));
 
 	memset(&dir, 0, sizeof(dir));
t/t0008-ignores.sh +67 -10

166 lines not on this page · raw message

Signature · 1 line
1.8.4.rc3
#1 lore raw
Quoted 11 lines · Dave Williams

I have updated the original version of this patch to encompass the feedback comments obtained. Updates include:
1) Rename option to --no-index for consistency with other commands
2) Improved Documentation text
3) Extension to test scripts to include this option

Regarding test scripts I have scoped coverage to ensure correct behaviour with the new option in all standard cases but without duplicating every single corner case.

The original patch is at $gmane/233381.

This commentary, which is not intended as part of the commit message, normally goes below the '---' line after your sign-off just before the diffstat. When the project maintainer applies a patch with git-am, such commentary is stripped out automatically, otherwise he has to strip it manually. (Alternately, you could use a -->8-- line to separate the above commentary from the commit message.)

One more minor issue below...

Quoted 21 lines

check-ignore currently shows how .gitignore rules would treat untracked paths. Tracked paths do not generate useful output. This prevents debugging of why a path became tracked unexpectedly unless that path is first removed from the index with git rm --cached <path>.

This option (-i, --no-index) simply by-passes the check for the path being in the index and hence allows tracked paths to be checked too.

Whilst this behaviour deviates from the characteristics of git add and git status its use case is unlikely to cause any user confusion.

Test scripts are augmented to check this option against the standard ignores to ensure correct behaviour.

---

t/t0008-ignores.sh +0 -0
index c29342d..0ad0534 100755

t/t0008-ignores.sh test_check_ignore () { · line 91

Quoted 5 lines
t/t0008-ignores.sh +2 -0
@@ -87,6 +87,9 @@ test_check_ignore () {
 # check-ignore --verbose output is the same as normal output except
 # for the extra first column.
 #
+# A parameter is used to determine if the tests are run with the
+# normal case (using the index), or with the -i or --no_index option.

s/--no_index/--no-index/

Quoted 4 lines
t/t0008-ignores.sh +1 -0
+#
 # Arguments:
 #   - (optional) prereqs for this test, e.g. 'SYMLINKS'
 #   - test name