{"thread":{"id":"34803","subject":"[PATCH] check-ignore: Add option to ignore index contents","startedAt":"2013-08-29T22:46:52Z","lastAt":"2013-08-30T06:51:34Z","messageCount":6,"participants":["Dave Williams","Adam Spiers","Duy Nguyen","Junio C Hamano","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"226282","messageId":"20130829224652.GA13621@opensourcesolutions.co.uk","threadId":"34803","inReplyTo":null,"subject":"[PATCH] check-ignore: Add option to ignore index contents","fromName":"Dave Williams","fromEmail":"dave@opensourcesolutions.co.uk","sentAt":"2013-08-29T22:46:52Z","receivedAt":"2013-08-29T22:46:52Z","isPatch":true,"sender":{"key":"dave@opensourcesolutions.co.uk","avatar":"https://avatars.githubusercontent.com/u/2284929?v=4"},"body":"check-ignore currently shows how .gitignore rules would treat untracked\npaths. Tracked paths do not generate useful output.  This prevents\ndebugging of why a path became tracked unexpectedly unless that path is\nfirst removed from the index with git rm --cached <path>\n\nThis option (-i, --ignore-index) simply by-passes the check for the path\nbeing in the index and hence allows tracked path to be checked too.\n\nWhilst this behaviour deviates from the characteristics of git add and\ngit status its use case is unlikely to cause any user confusion.\n\nSigned-off-by: Dave Williams <dave@opensourcesolutions.co.uk>\n---\n Documentation/git-check-ignore.txt |  6 ++++++\n builtin/check-ignore.c             | 10 +++++++---\n 2 files changed, 13 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-check-ignore.txt b/Documentation/git-check-ignore.txt\nindex d2df487..bb878ff 100644\n--- a/Documentation/git-check-ignore.txt\n+++ b/Documentation/git-check-ignore.txt\n@@ -45,6 +45,12 @@ OPTIONS\n \tnot be possible to distinguish between paths which match a\n \tpattern and those which don't.\n \n+-i, --ignore-index::\n+\tDon't look in the index when undertaking the checks. This means\n+\tthe results deviate from those seen by git add and git status\n+\tbut is useful when understanding why a path became tracked by\n+\te.g. git add . and was not ignored as expected by the rules.\n+\n OUTPUT\n ------\n \ndiff --git a/builtin/check-ignore.c b/builtin/check-ignore.c\nindex 4a8fc70..c8f6ae1 100644\n--- a/builtin/check-ignore.c\n+++ b/builtin/check-ignore.c\n@@ -5,7 +5,7 @@\n #include \"pathspec.h\"\n #include \"parse-options.h\"\n \n-static int quiet, verbose, stdin_paths, show_non_matching;\n+static int quiet, verbose, stdin_paths, show_non_matching, ignore_index;\n static const char * const check_ignore_usage[] = {\n \"git check-ignore [options] pathname...\",\n \"git check-ignore [options] --stdin < <list-of-paths>\",\n@@ -24,6 +24,8 @@ static const struct option check_ignore_options[] = {\n \t\t    N_(\"input paths are terminated by a null character\")),\n \tOPT_BOOLEAN('n', \"non-matching\", &show_non_matching,\n \t\t    N_(\"show non-matching input paths\")),\n+\tOPT_BOOLEAN('i', \"ignore-index\", &ignore_index,\n+\t\t    N_(\"ignore index when checking\")),\n \tOPT_END()\n };\n \n@@ -82,7 +84,9 @@ static int check_ignore(struct dir_struct *dir,\n \t * should not be ignored, in order to be consistent with\n \t * 'git status', 'git add' etc.\n \t */\n-\tseen = find_pathspecs_matching_against_index(pathspec);\n+\tif (!ignore_index) {\n+\t\tseen = find_pathspecs_matching_against_index(pathspec);\n+\t}\n \tfor (i = 0; pathspec[i]; i++) {\n \t\tpath = pathspec[i];\n \t\tfull_path = prefix_path(prefix, prefix\n@@ -90,7 +94,7 @@ static int check_ignore(struct dir_struct *dir,\n \t\tfull_path = check_path_for_gitlink(full_path);\n \t\tdie_if_path_beyond_symlink(full_path, prefix);\n \t\texclude = NULL;\n-\t\tif (!seen[i]) {\n+\t\tif (ignore_index || !seen[i]) {\n \t\t\texclude = last_exclude_matching(dir, full_path, &dtype);\n \t\t}\n \t\tif (!quiet && (exclude || show_non_matching))\n-- \n1.8.4.rc3\n"},{"id":"226283","messageId":"20130830001054.GA3691@pacific.linksys.moosehall","threadId":"34803","inReplyTo":"20130829224652.GA13621@opensourcesolutions.co.uk","subject":"Re: [PATCH] check-ignore: Add option to ignore index contents","fromName":"Adam Spiers","fromEmail":"git@adamspiers.org","sentAt":"2013-08-30T00:10:54Z","receivedAt":"2013-08-30T00:10:54Z","isPatch":true,"sender":{"key":"git@adamspiers.org","avatar":"https://avatars.githubusercontent.com/u/100738?v=4"},"body":"On Thu, Aug 29, 2013 at 11:46:52PM +0100, Dave Williams wrote:\n> check-ignore currently shows how .gitignore rules would treat untracked\n> paths. Tracked paths do not generate useful output.  This prevents\n> debugging of why a path became tracked unexpectedly unless that path is\n> first removed from the index with git rm --cached <path>\n> \n> This option (-i, --ignore-index) simply by-passes the check for the path\n> being in the index and hence allows tracked path to be checked too.\n> \n> Whilst this behaviour deviates from the characteristics of git add and\n> git status its use case is unlikely to cause any user confusion.\n> \n> Signed-off-by: Dave Williams <dave@opensourcesolutions.co.uk>\n\n[snipped]\n\nSounds like a great idea to me, and the code changes look reasonable;\nhowever you forgot to add corresponding tests :-)  Please can you\nexpand the patch to include them?\n\nBut I'm in favour in principle - thanks a lot for working on this!\n"},{"id":"226284","messageId":"CACsJy8COEwA0hSf4yiTETqA6UBRhcCviayrhnynw23bTC-3foQ@mail.gmail.com","threadId":"34803","inReplyTo":"20130829224652.GA13621@opensourcesolutions.co.uk","subject":"Re: [PATCH] check-ignore: Add option to ignore index contents","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2013-08-30T00:51:26Z","receivedAt":"2013-08-30T00:51:26Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Fri, Aug 30, 2013 at 5:46 AM, Dave Williams\n<dave@opensourcesolutions.co.uk> wrote:\n> check-ignore currently shows how .gitignore rules would treat untracked\n> paths. Tracked paths do not generate useful output.  This prevents\n> debugging of why a path became tracked unexpectedly unless that path is\n> first removed from the index with git rm --cached <path>\n>\n> This option (-i, --ignore-index) simply by-passes the check for the path\n> being in the index and hence allows tracked path to be checked too.\n\nMaybe --no-index, already used by git-diff and git-grep.\n\n> Whilst this behaviour deviates from the characteristics of git add and\n> git status its use case is unlikely to cause any user confusion.\n-- \nDuy\n"},{"id":"226285","messageId":"7vob8gj8qv.fsf@alter.siamese.dyndns.org","threadId":"34803","inReplyTo":"20130829224652.GA13621@opensourcesolutions.co.uk","subject":"Re: [PATCH] check-ignore: Add option to ignore index contents","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-08-30T00:57:28Z","receivedAt":"2013-08-30T00:57:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Dave Williams <dave@opensourcesolutions.co.uk> writes:\n\n> check-ignore currently shows how .gitignore rules would treat untracked\n> paths. Tracked paths do not generate useful output.  This prevents\n> debugging of why a path became tracked unexpectedly unless that path is\n> first removed from the index with git rm --cached <path>\n>\n> This option (-i, --ignore-index) simply by-passes the check for the path\n> being in the index and hence allows tracked path to be checked too.\n>\n> Whilst this behaviour deviates from the characteristics of git add and\n> git status its use case is unlikely to cause any user confusion.\n>\n> Signed-off-by: Dave Williams <dave@opensourcesolutions.co.uk>\n> ---\n>  Documentation/git-check-ignore.txt |  6 ++++++\n>  builtin/check-ignore.c             | 10 +++++++---\n>  2 files changed, 13 insertions(+), 3 deletions(-)\n>\n> diff --git a/Documentation/git-check-ignore.txt b/Documentation/git-check-ignore.txt\n> index d2df487..bb878ff 100644\n> --- a/Documentation/git-check-ignore.txt\n> +++ b/Documentation/git-check-ignore.txt\n> @@ -45,6 +45,12 @@ OPTIONS\n>  \tnot be possible to distinguish between paths which match a\n>  \tpattern and those which don't.\n>  \n> +-i, --ignore-index::\n> +\tDon't look in the index when undertaking the checks. This means\n> +\tthe results deviate from those seen by git add and git status\n> +\tbut is useful when understanding why a path became tracked by\n> +\te.g. git add . and was not ignored as expected by the rules.\n\nPlease think twice after you write \"This means\", \"What this means\nis\", etc. to see if you can get rid of sentence before that, which\nneeded such clarification.  If the sentence can stand on its own,\nand what follows \"This means\" is also useful information, then it is\na sign that \"What this means is\" is better rephrased as \"Note that\".\n\nAlso, I think `git add .` should be quoted to make it clear where\nthe sample command begins and ends.  Using a pair of `` would be the\nmost appropriate here.\n\n>  OUTPUT\n>  ------\n>  \n> diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c\n> index 4a8fc70..c8f6ae1 100644\n> --- a/builtin/check-ignore.c\n> +++ b/builtin/check-ignore.c\n> @@ -5,7 +5,7 @@\n>  #include \"pathspec.h\"\n>  #include \"parse-options.h\"\n>  \n> -static int quiet, verbose, stdin_paths, show_non_matching;\n> +static int quiet, verbose, stdin_paths, show_non_matching, ignore_index;\n>  static const char * const check_ignore_usage[] = {\n>  \"git check-ignore [options] pathname...\",\n>  \"git check-ignore [options] --stdin < <list-of-paths>\",\n> @@ -24,6 +24,8 @@ static const struct option check_ignore_options[] = {\n>  \t\t    N_(\"input paths are terminated by a null character\")),\n>  \tOPT_BOOLEAN('n', \"non-matching\", &show_non_matching,\n>  \t\t    N_(\"show non-matching input paths\")),\n> +\tOPT_BOOLEAN('i', \"ignore-index\", &ignore_index,\n> +\t\t    N_(\"ignore index when checking\")),\n>  \tOPT_END()\n>  };\n>  \n> @@ -82,7 +84,9 @@ static int check_ignore(struct dir_struct *dir,\n>  \t * should not be ignored, in order to be consistent with\n>  \t * 'git status', 'git add' etc.\n>  \t */\n> -\tseen = find_pathspecs_matching_against_index(pathspec);\n> +\tif (!ignore_index) {\n> +\t\tseen = find_pathspecs_matching_against_index(pathspec);\n> +\t}\n>  \tfor (i = 0; pathspec[i]; i++) {\n>  \t\tpath = pathspec[i];\n>  \t\tfull_path = prefix_path(prefix, prefix\n> @@ -90,7 +94,7 @@ static int check_ignore(struct dir_struct *dir,\n>  \t\tfull_path = check_path_for_gitlink(full_path);\n>  \t\tdie_if_path_beyond_symlink(full_path, prefix);\n>  \t\texclude = NULL;\n> -\t\tif (!seen[i]) {\n> +\t\tif (ignore_index || !seen[i]) {\n>  \t\t\texclude = last_exclude_matching(dir, full_path, &dtype);\n>  \t\t}\n>  \t\tif (!quiet && (exclude || show_non_matching))\n\nHmph, if ignoring what is in the index is what the new feature wants\nto do, why does it even need to touch check_ignore() function at all\nand add a global variable ignore_index to keep track of that state?\n\nIsn't it sufficient to skip the call to read_cache() when that\noption is given?\n\nYou would need to add tests for this, too.\n\nThanks.\n"},{"id":"226288","messageId":"xmqqmwnz24ua.fsf@gitster.dls.corp.google.com","threadId":"34803","inReplyTo":"CACsJy8COEwA0hSf4yiTETqA6UBRhcCviayrhnynw23bTC-3foQ@mail.gmail.com","subject":"Re: [PATCH] check-ignore: Add option to ignore index contents","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-08-30T04:13:49Z","receivedAt":"2013-08-30T04:13:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Duy Nguyen <pclouds@gmail.com> writes:\n\n> On Fri, Aug 30, 2013 at 5:46 AM, Dave Williams\n> <dave@opensourcesolutions.co.uk> wrote:\n>> check-ignore currently shows how .gitignore rules would treat untracked\n>> paths. Tracked paths do not generate useful output.  This prevents\n>> debugging of why a path became tracked unexpectedly unless that path is\n>> first removed from the index with git rm --cached <path>\n>>\n>> This option (-i, --ignore-index) simply by-passes the check for the path\n>> being in the index and hence allows tracked path to be checked too.\n>\n> Maybe --no-index, already used by git-diff and git-grep.\n\nI am somewhat ashamed that I didn't think of it myself when I saw\nthe patch, but I agree that would be a good change for consistency.\n\n\n>\n>> Whilst this behaviour deviates from the characteristics of git add and\n>> git status its use case is unlikely to cause any user confusion.\n"},{"id":"226326","messageId":"522040F6.5060602@viscovery.net","threadId":"34803","inReplyTo":"20130829224652.GA13621@opensourcesolutions.co.uk","subject":"Re: [PATCH] check-ignore: Add option to ignore index contents","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2013-08-30T06:51:34Z","receivedAt":"2013-08-30T06:51:34Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 8/30/2013 0:46, schrieb Dave Williams:\n> +-i, --ignore-index::\n> +\tDon't look in the index when undertaking the checks. This means\n> +\tthe results deviate from those seen by git add and git status\n> +\tbut is useful when understanding why a path became tracked by\n> +\te.g. git add . and was not ignored as expected by the rules.\n\nDid you mean to say \"was not ignored as expected by the user\"? Because the\n\"the rules\" cannot \"expect\" something, they only \"are applied\".\n\n-- Hannes\n"}]}