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

Buggy (or undocumented) handling of terminal \r in .gitignore patterns

From
AHAaron Harnly <git@lists.harnly.net>
Date
Dec 3, 2008, 15:46 UTC
Message-ID
<loom.20081203T152511-351@post.gmane.org>
This is with git 1.5.6.3 on Ubuntu and Mac OS X.
Overview: .gitignore patterns ending in \r do not work as expected, apparently
because the terminal \r is assumed to be part of the newline.

Steps to Reproduce: (NB ^M is the control-M sequence, not a literal caret-M)

1. Create an empty repository.
2. Create a file named Icon\r (aka Icon^M).
3. Add the following pattern to the .gitignore:
Icon^M
Expected behavior:
The file is ignored.
Actual behavior:
The file is not ignored.
Discussion:

It appears that the parsing of .gitignore files tries to be graceful in allowing the file to have CRLF endings, or indeed mixed LF / CRLF endings.

This is well and good, but poses a bit of a problem for ignoring files whose name ends in \r. In particular, Mac OS X's icon files are named Icon\r. Yes, this is sick and annoying on the part of Apple.

I understand the rationale for this behavior, but it probably should be documented somewhere. In the meantime, a workaround that does allow the ignoring of these files is the pattern:

Icon^M^M

where again, the terminal \r seems to be ignored as part of the newline, but the penultimate \r gets picked up as part of the pattern.

Any thoughts on whether:
1. this behavior should be left as it is
2. there is actually documentation somewhere that I didn't see
3. terminal \r in an otherwise all-LF file should be assumed to be part of the
pattern
4. some other alternative?

cheers, ~aaron

Next: Michael J Gruber
Message 1 of 2 in “Buggy (or undocumented) handling of terminal \r in .gitignore patterns”
  1. Aaron HarnlyDec 3, 2008
  2. Michael J GruberDec 3, 2008

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.