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

Re: .gitattributes override behavior (possible bug, or documentation bug)

From
DHDakota Hawkins <dakota@dakotahawkins.com>
Date
Mar 21, 2018, 03:22 UTC
Message-ID
<CAHnyXxRsqR3A0FpHJwnfOWo29WNx05qWSXfxvmwPv1TUdqm0aQ@mail.gmail.com>
In-Reply-To
<CACsJy8BP+ov0jeHp6QZoi=etPDQX5qEFqEfktyA-U-ffUE92vA@mail.gmail.com>

Thinking about this a little more, I'm now attracted to the idea that its .gitignore that's weird.

As I understand it, .gitignore stops recursion when there's a directory match (`somedir/`) but also explicitly allows nested .gitnore file _as well as_ exclusion (`!*.txt`).

So, in the following (contrived) example, the user doesn't get what they want:
    repo/
    |- .git/
    |- .gitignore               # /ignore-most/
    |- ignore-most/
    |  |- .gitignore            # !*.txt
    |  |- please_ignore.png
    |  |- dont_ignore_me.txt

`repo/ignore-most/dont_ignore_me.txt` is still ignored, despite what seems like the obvious intention of the user.

Maybe a unified "best-practices" would first-and-foremost recommend against matching directories at all (makes sense, git doesn't manage directories). In the above example, changing `/ignore-most/` to `/ignore-most/*` has the "desired" effect.

What do you think?
On Tue, Mar 20, 2018 at 12:28 PM, Duy Nguyen <pclouds@gmail.com> wrote:
Show 58 quoted lines
> On Tue, Mar 20, 2018 at 5:40 AM, Jeff King <peff@peff.net> wrote:
>> On Tue, Mar 20, 2018 at 12:25:27AM -0400, Dakota Hawkins wrote:
>>
>>> > Right. The technical reason is mostly "that is not how it was designed,
>>> > and it would possibly break some corner cases if we switched it now".
>>>
>>> I'm just spitballing here, but do you guys think there's any subset of
>>> the combined .gitignore and .gitattributes matching functionality that
>>> could at least serve as a good "best-practices, going forward"
>>> (because of consistency) for both? I will say every time I do this for
>>> a new repo and have to do something even slightly complicated or
>>> different from what I've done before with .gitattributes/.gitignore
>>> that it takes me a long-ish time to figure it out. It's like I'm
>>> vaguely aware of pitfalls I've encountered in the past in certain
>>> areas but don't remember exactly what they are, so I consult the docs,
>>> which are (in sum) confusing and lead to more time spent
>>> trying/failing/trying/works/fails-later/etc.
>>>
>>> One "this subset of rules will work for both this way" would be
>
> You know, you (Dakota) could implement the new "exclude" attribute in
> .gitattributes and ignore .gitignore files completely. That makes it
> works "for both" ;-) The effort is probably not small though.
>
>>> awesome even if the matching capabilities are technically divergent,
>>> but on the other hand that might paint both into a corner in terms of
>>> functionality.
>>
>> As far as I know, they should be the same with the exception of this
>> recursion, and the negative-pattern thing. But I'm cc-ing Duy, who is
>> the resident expert on ignore and attributes matching (whether he wants
>> to be or not ;) ).
>
> Ha ha ha.
>
>> I wouldn't be surprised if there's something I don't know about.
>
> The only thing from the top of my head is what made me fail to unify
> the implementation of the two. It's basically different order of
> evaluation [1] when your patterns are spread out in multiple files. I
> think it makes gitattr and gitignore behavior different too (but I
> didn't try to verify).
>
> Apart from that, the two should behave the same way besides the
> exceptions you pointed out.
>
> [1] https://public-inbox.org/git/%3CCACsJy8B8kYU7bkD8SiK354z4u=sY3hHbe4JVwNT_1pxod1cqUw@mail.gmail.com%3E/
>
>> So I think the "recommended subset" is basically "everything but these
>> few constructs". We just need to document them. ;)
>>
>> I probably should cc'd Duy on the documentation patch, too:
>>
>>   https://public-inbox.org/git/20180320041454.GA15213@sigill.intra.peff.net/
>>
>> -Peff
> --
> Duy
Previous: Duy NguyenNext: Jeff King
Message 17 of 28 in “.gitattributes override behavior (possible bug, or documentation bug)”
  1. Dakota HawkinsMar 20, 2018
  2. Jeff KingMar 20, 2018
  3. Dakota HawkinsMar 20, 2018
  4. Dakota HawkinsMar 20, 2018
  5. Jeff KingMar 20, 2018
  6. Jeff KingMar 20, 2018
  7. doc/gitattributes: mention non-recursive behaviorJeff King, Mar 20, 2018
  8. Dakota HawkinsMar 20, 2018
  9. Duy NguyenMar 20, 2018
  10. Jeff KingMar 21, 2018
  11. Duy NguyenMar 21, 2018
  12. Jeff KingMar 23, 2018
  13. Dakota HawkinsMar 20, 2018
  14. Jeff KingMar 20, 2018
  15. Dakota HawkinsMar 20, 2018
  16. Duy NguyenMar 20, 2018
  17. Dakota HawkinsMar 21, 2018
  18. Jeff KingMar 21, 2018
  19. Dakota HawkinsMar 21, 2018
  20. Dakota HawkinsMar 21, 2018
  21. Jeff KingMar 21, 2018
  22. Dakota HawkinsMar 21, 2018
  23. Jeff KingMar 21, 2018
  24. Junio C HamanoMar 21, 2018
  25. Duy NguyenMar 21, 2018
  26. Junio C HamanoMar 20, 2018
  27. Dakota HawkinsMar 20, 2018
  28. Jeff KingMar 20, 2018

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.