{"thread":{"id":"38169","subject":"[PATCH] git-check-ignore.txt: Clarify exit codes","startedAt":"2014-12-11T18:42:35Z","lastAt":"2014-12-11T23:40:53Z","messageCount":5,"participants":["Florian Hassanen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"253573","messageId":"1418323355-23935-1-git-send-email-florian.hassanen@gmail.com","threadId":"38169","inReplyTo":null,"subject":"[PATCH] git-check-ignore.txt: Clarify exit codes","fromName":"Florian Hassanen","fromEmail":"florian.hassanen@gmail.com","sentAt":"2014-12-11T18:42:35Z","receivedAt":"2014-12-11T18:42:35Z","isPatch":true,"sender":{"key":"florian.hassanen@gmail.com","avatar":"https://gravatar.com/avatar/3984009f92f39dffc49bca68183e34e4d122a1aefef646237841f620feca515a?d=mp&s=160"},"body":"check-ignore disregards whether a path is matched by a\npositive or negative pattern. Thus for a file that is _not_\nignored, but is captured by negative pattern in .gitignore,\nthe exit code is 0. The docs suggested otherwise.\n\nClarify docs to explain that only the match matters, not\nwhether the path is actually ignored or not.\n\nSigned-off-by: Florian Hassanen <florian.hassanen@gmail.com>\n---\nToday when working with the check-ignore command, I misunderstood\nthe docs into thinking, that I could use check-ignore's exit code\nto determine, whether a file is ignored or not - but this is not\nhow the exit code works :(\nHere is a suggestion, on how to update the docs to describe the \nexit code's behavior more clearly.\n\n Documentation/git-check-ignore.txt | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-check-ignore.txt b/Documentation/git-check-ignore.txt\nindex ee2e091..bdd8b7c 100644\n--- a/Documentation/git-check-ignore.txt\n+++ b/Documentation/git-check-ignore.txt\n@@ -97,10 +97,11 @@ EXIT STATUS\n -----------\n \n 0::\n-\tOne or more of the provided paths is ignored.\n+\tAt least one of the provided paths matches some (possibly negative)\n+\tpattern.\n \n 1::\n-\tNone of the provided paths are ignored.\n+\tNone of the provided paths match any pattern.\n \n 128::\n \tA fatal error was encountered.\n-- \n2.1.3\n"},{"id":"253589","messageId":"xmqqiohhdc5j.fsf@gitster.dls.corp.google.com","threadId":"38169","inReplyTo":"1418323355-23935-1-git-send-email-florian.hassanen@gmail.com","subject":"Re: [PATCH] git-check-ignore.txt: Clarify exit codes","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-12-11T23:01:12Z","receivedAt":"2014-12-11T23:01:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Florian Hassanen <florian.hassanen@gmail.com> writes:\n\n> check-ignore disregards whether a path is matched by a\n> positive or negative pattern. Thus for a file that is _not_\n> ignored, but is captured by negative pattern in .gitignore,\n> the exit code is 0. The docs suggested otherwise.\n\nI am not sure that is the actual behaviour of the command.  Given\nthis .gitignore file:\n\n    $ cat .gitignore; echo END\n    !vendor.o\n    *.o\n    END\n\nwhich is designed to allow binary-only blob \"vendor.o\" supplied by\nthe vendor to be tracked, but to ignore all the other usual build\nartifacts, you see this:\n\n    $ for o in a.o vendor.o; do git check-ignore $o >/dev/null; echo $?; done\n    0\n    1\n\nPuzzled...\n\n>\n> Clarify docs to explain that only the match matters, not\n> whether the path is actually ignored or not.\n>\n> Signed-off-by: Florian Hassanen <florian.hassanen@gmail.com>\n> ---\n> Today when working with the check-ignore command, I misunderstood\n> the docs into thinking, that I could use check-ignore's exit code\n> to determine, whether a file is ignored or not - but this is not\n> how the exit code works :(\n> Here is a suggestion, on how to update the docs to describe the \n> exit code's behavior more clearly.\n>\n>  Documentation/git-check-ignore.txt | 5 +++--\n>  1 file changed, 3 insertions(+), 2 deletions(-)\n>\n> diff --git a/Documentation/git-check-ignore.txt b/Documentation/git-check-ignore.txt\n> index ee2e091..bdd8b7c 100644\n> --- a/Documentation/git-check-ignore.txt\n> +++ b/Documentation/git-check-ignore.txt\n> @@ -97,10 +97,11 @@ EXIT STATUS\n>  -----------\n>  \n>  0::\n> -\tOne or more of the provided paths is ignored.\n> +\tAt least one of the provided paths matches some (possibly negative)\n> +\tpattern.\n>  \n>  1::\n> -\tNone of the provided paths are ignored.\n> +\tNone of the provided paths match any pattern.\n>  \n>  128::\n>  \tA fatal error was encountered.\n"},{"id":"253591","messageId":"CAMAJHBYVMy-tc_aCjyeN7=VMG=k7gjWh9evL6bcJLzYfQcf6yg@mail.gmail.com","threadId":"38169","inReplyTo":"xmqqiohhdc5j.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH] git-check-ignore.txt: Clarify exit codes","fromName":"Florian Hassanen","fromEmail":"florian.hassanen@gmail.com","sentAt":"2014-12-11T23:16:32Z","receivedAt":"2014-12-11T23:16:32Z","isPatch":true,"sender":{"key":"florian.hassanen@gmail.com","avatar":"https://gravatar.com/avatar/3984009f92f39dffc49bca68183e34e4d122a1aefef646237841f620feca515a?d=mp&s=160"},"body":">> check-ignore disregards whether a path is matched by a\n>> positive or negative pattern. Thus for a file that is _not_\n>> ignored, but is captured by negative pattern in .gitignore,\n>> the exit code is 0. The docs suggested otherwise.\n>\n> I am not sure that is the actual behaviour of the command.  Given\n> this .gitignore file:\n>\n>     $ cat .gitignore; echo END\n>     !vendor.o\n>     *.o\n>     END\n>\n> which is designed to allow binary-only blob \"vendor.o\" supplied by\n> the vendor to be tracked, but to ignore all the other usual build\n> artifacts, you see this:\n>\n>     $ for o in a.o vendor.o; do git check-ignore $o >/dev/null; echo $?; done\n>     0\n>     1\n>\n> Puzzled...\n\nMaybe your global ignore file gets in the way?\n\non both of my machines (cygwin + git 2.1.1, linux + git @master) I have:\n\n  $ cat > .gitignore << EOF\n  !vendor.o\n  *.o\n  EOF\n\n  for o in a.o vendor.o; do git check-ignore $o >/dev/null; echo $?; done\n  0\n  0\n\nwhich corresponds to how I understand the command so far :)\n\nis one of a.o and vendor.o already in your index?\nthere is a --no-index as well (which enables yet another different behavior)\n"},{"id":"253592","messageId":"xmqqa92tdb80.fsf@gitster.dls.corp.google.com","threadId":"38169","inReplyTo":"CAMAJHBYVMy-tc_aCjyeN7=VMG=k7gjWh9evL6bcJLzYfQcf6yg@mail.gmail.com","subject":"Re: [PATCH] git-check-ignore.txt: Clarify exit codes","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-12-11T23:21:19Z","receivedAt":"2014-12-11T23:21:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Florian Hassanen <florian.hassanen@gmail.com> writes:\n\n> Maybe your global ignore file gets in the way?\n\nNo, as I do not have one.\n\n> is one of a.o and vendor.o already in your index?\n\nBingo.  I did \"git add .\" to see if the .gitignore file is doing the\nright thing before running that demonstration.\n\nIt smells like you spotted a bug in the behaviour, not a bug in the\ndocumentation, at least to me.\n"},{"id":"253594","messageId":"CAMAJHBZpLY_Rwdpuw6hruJwST_tgY1S02ZPt=ueKPXOXHREHxQ@mail.gmail.com","threadId":"38169","inReplyTo":"xmqqa92tdb80.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH] git-check-ignore.txt: Clarify exit codes","fromName":"Florian Hassanen","fromEmail":"florian.hassanen@gmail.com","sentAt":"2014-12-11T23:40:53Z","receivedAt":"2014-12-11T23:40:53Z","isPatch":true,"sender":{"key":"florian.hassanen@gmail.com","avatar":"https://gravatar.com/avatar/3984009f92f39dffc49bca68183e34e4d122a1aefef646237841f620feca515a?d=mp&s=160"},"body":"> It smells like you spotted a bug in the behaviour, not a bug in the\n> documentation, at least to me.\n\nAt first I thought so as well :-)\nI even prepared a patch, just to find out, that existing tests specifically\ntest for this \"unintuitive\" behavior.\n\nThen I read the docs in more detail and found this:\n\n  If the pattern contained a ! prefix or / suffix, it will be\npreserved in the output.\n\nSo it seems there is indeed the intent to output patterns, even if\nthey are negated/negative.\n\nAnother problem I see with providing \"correct\" behavior is this:\n\nIf I do a test for a non existant file, it cannot be decided whether I\nmean a file or a directory.\n\ne.g.\n\nhaving a gitignore with a single line\n\n  dir/\n\nwhich only ignores die _directory_ dir, but not the _file_ dir\n\nthe exit code for\n\n  $ git check-ignore dir\n\ncould either be 0 or 1, depending on whether a _file_ named \"dir\" or a\n_directory_\nnamed \"dir\" was meant.\n\nI assume that the command is meant to get the applying entry of the gitignore\nand then its up to the consumer to provide additional logic to determine whether\nthe path is actually ignored or not.\n\nI am not sure what the correct behavior should be. And whether some\ncode already depends\non this command.\n\nMy personal preference, would be a behavior like\n\n$ # regardless whether dir exists or not\n$ git check-ignore dir # a file is meant\n$ git check-ignore dir/ # a directory is mean\n\nand the exit code should only depend on whether the file is actually\nignored or not\n- and not if there is an arbitrary matching pattern in gitignore\n\nPS: btw, the previously discussed gitignore file should have read\n(note the order)\ncat > .gitignore << EOF\n*.o\n!vendor.o\nEOF\n\nbecause always the last matching entry applies\n(so exceptions must come last) - but the exit codes are still the same\n\nOn Fri, Dec 12, 2014 at 12:21 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Florian Hassanen <florian.hassanen@gmail.com> writes:\n>\n>> Maybe your global ignore file gets in the way?\n>\n> No, as I do not have one.\n>\n>> is one of a.o and vendor.o already in your index?\n>\n> Bingo.  I did \"git add .\" to see if the .gitignore file is doing the\n> right thing before running that demonstration.\n>\n> It smells like you spotted a bug in the behaviour, not a bug in the\n> documentation, at least to me.\n>\n"}]}