threads / discuss / 16580

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

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

## tl;dr

2 messages between Dec 3, 2008 and Dec 3, 2008.

replies: 1people: 2as markdown or json

Aaron Harnly· Dec 3, 2008, 15:46 UTC · lore
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

Michael J Gruber· Dec 3, 2008, 17:42 UTC · re: Aaron Harnly · lore

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

Aaron Harnly venit, vidit, dixit 03.12.2008 16:46:
Show 46 quoted lines
> 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?
5. spank Apple

← back to recent threads