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

Re: Non-blob .gitmodules and .gitattributes

From
Jeff King <peff@peff.net>
Date
Jun 18, 2024, 23:33 UTC
Message-ID
<20240618233303.GA188880@coredump.intra.peff.net>
In-Reply-To
<xmqqa5jiypmm.fsf@gitster.g>
On Tue, Jun 18, 2024 at 01:14:57PM -0700, Junio C Hamano wrote:
Show 17 quoted lines
> Alexey Pelykh <alexey.pelykh@gmail.com> writes:
> 
> >> But I'd also suspect that other non-POSIX platforms would see the error
> >> at open(), and _would_ actually produce an error message. I seem to
> >> recall running into this before with Windows, maybe?
> >
> > Is there an easy way to verify "what on Windows" part? I'd be happy to
> > help, yet I'm not sure I got it right what to look for.
> 
> Create a .gitmodules and .gitattributes directory, "git add" it, and
> perform various operations that want to read them, probably.  Even a
> simple "git diff" should try to consult the attribute system (e.g.
> because it wants to know if a path needs use custom function header
> regexp pattern).  As Peff said, on Linux and probably on macOS, we
> will silently ignore such .gitattributes and that is what we want.
> On Windows we may see "cannot open" error reported and visible to
> the users.

I don't think you even need to "git add" it. Just making it in the working tree is enough for us to look at it. You probably do need an actual change in a tracked file for "git diff" to bother looking up attributes (an alternative is just "git show" on an existing commit).

Interestingly, a directory .gitmodules _does_ complain:
  $ git status
  warning: unable to access '/home/peff/tmp/.gitmodules': Is a directory
  On branch main
  nothing to commit, working tree clean

That's because it uses fopen(), rather than open(). And we have a wrapper that complains about directories there, triggered by the FREAD_READS_DIRECTORIES knob in the Makefile. It's set for Linux, but not for Windows (which is why I suspect Windows might just complain by itself). We don't see that for ".gitattributes" or ".gitignore" because those use a raw open() syscall, and Linux is happy to allow it. Arguably that's a bug, as the intent of that knob is that we'd notice and avoid trying to read from directories.

So even putting fsck warnings aside, I think it's mostly luck that having .git* files as directories doesn't produce noisy warnings during normal use.

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 17 in “Non-blob .gitmodules and .gitattributes”
  1. Alexey PelykhJun 14, 2024
  2. Junio C HamanoJun 14, 2024
  3. Alexey PelykhJun 14, 2024
  4. Jeff KingJun 18, 2024
  5. Alexey PelykhJun 18, 2024
  6. Junio C HamanoJun 18, 2024
  7. Jeff KingJun 18, 2024
  8. 0/4 .git{ignore,attributes} directories?Junio C Hamano, Jun 18, 2024
  9. 1/4 .gitignore: introduce GITIGNORE_FILE CPP macroJunio C Hamano, Jun 18, 2024
  10. 2/4 attr: notice and report read failure of .gitattributes filesJunio C Hamano, Jun 18, 2024
  11. Eric SunshineJun 19, 2024
  12. Junio C HamanoJun 19, 2024
  13. Eric SunshineJun 19, 2024
  14. Jeff KingJun 19, 2024
  15. Junio C HamanoJun 20, 2024
  16. 4/4 submodule: ignore .gitmodules that is not a regular fileJunio C Hamano, Jun 18, 2024
  17. 3/4 exclude: notice and report read failure of .gitignore filesJunio C Hamano, Jun 18, 2024

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.