summaryrefslogtreecommitdiff
path: root/builtin/check-ignore.c
diff options
context:
space:
mode:
authorDave Williams <dave@opensourcesolutions.co.uk>2013-09-05 16:08:01 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-09-12 22:40:29 (GMT)
commit8231fa6ae1ef92be73bec5cf0a533a4d8b71d536 (patch)
treed3d67a885c9da97fbf313a14a728fe7e3367816b /builtin/check-ignore.c
parent57e4c1783f056ce2d50a732c0fccff2a1fe99563 (diff)
downloadgit-8231fa6ae1ef92be73bec5cf0a533a4d8b71d536.zip
git-8231fa6ae1ef92be73bec5cf0a533a4d8b71d536.tar.gz
git-8231fa6ae1ef92be73bec5cf0a533a4d8b71d536.tar.bz2
check-ignore: Add option to ignore index contents
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>`. The option --no-index tells the command to bypass 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. Signed-off-by: Dave Williams <dave@opensourcesolutions.co.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/check-ignore.c')
-rw-r--r--builtin/check-ignore.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
index 25aa2a5..8b3c2e3 100644
--- a/builtin/check-ignore.c
+++ b/builtin/check-ignore.c
@@ -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_("terminate input and output records by a NUL character")),
OPT_BOOL('n', "non-matching", &show_non_matching,
N_("show non-matching input paths")),
+ OPT_BOOL(0, "no-index", &no_index,
+ N_("ignore index when checking")),
OPT_END()
};
@@ -157,7 +159,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));