git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: BUG: git-check-ignore documentation doesn't come close to describing what it really does

From
Elijah Newren <newren@gmail.com>
Date
Jul 13, 2022, 00:17 UTC
Message-ID
<CABPp-BG5qjp9Rx+=CCeLMiOH2Bqpa3kmBWRWdu7fTtPM-H=3kA@mail.gmail.com>
In-Reply-To
<CAC4O8c9izkV5vbnE6MH8-RwnxRbUONxJxYZO+hb1J0ewuDtX+w@mail.gmail.com>
Hi,
Thanks for the report.
On Tue, Jul 12, 2022 at 4:34 PM Britton Kerin <britton.kerin@gmail.com> wrote:
Show 8 quoted lines
>
> It begins:
>
>        For each pathname given via the command-line or from a file via
> --stdin, check whether
>        the file is excluded by .gitignore (or other input files to the
> exclude mechanism) and output
>        the path if it is excluded.

I suspect we're having an aliasing problem that you're not recognizing. "ignored" and "excluded" are used interchangeably, note that patterns from the $GIT_DIR/info/exclude files and patterns from the file pointed to by core.excludesFile are also lumped together with the patterns from all the .gitignore files (see the gitignore manual page). Further, the internal code refers to them all as "excludes" not as "ignores".

(And then we adopted the same syntax for sparse checkouts, except we used it to mark things that should be included, and we referred everyone to the documentation about "excludes" to learn the format for what to "include". Ugh.)

>
> In fact it just reports matches from .gitignore etc:

Yes, it outputs the paths that are excluded, as the documentation said. Perhaps there's a way to reword it to make this clearer? I don't think we can get rid of the alias given the fact that $GIT_DIR/info/exclude and core.excludesFile are hard-coded and must be kept for backward compatibility. But suggestions to improve the wording would be great.

Maybe it'd be as simple as replacing "is excluded" with "matches an ignore/exclude rule"?

Show 18 quoted lines
>      $ cat .gitignore
>      *.o
>      !*.dont_ignore
>      $ ls
>      bar.o.dont_ignore  foo.o
>      $ git check-ignore -v -n *
>      .gitignore:2:!*.dont_ignore bar.o.dont_ignore
>      .gitignore:1:*.o foo.o
>      $ # Even more confusing without -v -n:
>      $ git check-ignore *
>      bar.o.dont_ignore
>      foo.o
>
> The EXIT STATUS section is even more wrong:
>
>      EXIT STATUS
>             0
>                 One or more of the provided paths is ignored.

"is ignored", meaning "matches an ignore/exclude rule". Perhaps we should update the docs with that textual change?

>             1
>                 None of the provided paths are ignored.
and replace "are ignored" with the same phrase here?
Show 9 quoted lines
>
>             128
>                 A fatal error was encountered.
>
> but:
>
>      $ if git check-ignore foo.o.dont_ignore; then echo exited true;
> else echo exited false; fi
>      foo.o.dont_ignore
So the filename matched one of the rules, causing the filename to be printed.
>      exited true

and it returned a 0 exit status, since one of the provided paths was ignored, as documented.

>      $
>
> IMO the behavior of git-check-ignore is the correct and useful
> behavior
I'm with you here.
> and the documentation should simply be fixed
Yes, I agree it's easy to misinterpret.  Would my suggested changes help?
> to reflect the
> fact that it just lists matching entries rather than wrongly claiming
> that it returns the overall result of the ignore calculation.

I think I understood where the problems were in the documentation that could lead to misinterpretations in the other two cases you mentioned earlier in your email, but I don't understand this one. Even the first sentence you quoted included the phrase that it could "output the path", so I'm not sure where you think it claims that it'd return the overall result of the ignore calculation. Could you point out what in the document led you to believe it was claiming this? Maybe I could suggest wording improvements for it as well. Or maybe you have some.

Previous: Britton KerinNext: Junio C Hamano
Message 2 of 5 in “BUG: git-check-ignore documentation doesn't come close to describing what it really does”
  1. Britton KerinJul 12, 2022
  2. Elijah NewrenJul 13, 2022
  3. Junio C HamanoJul 13, 2022
  4. Britton Leo KerinJul 18, 2022
  5. Junio C HamanoJul 19, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.