Skip to content

Commit

Permalink
remove CR/LF from .gitignore
Browse files Browse the repository at this point in the history
For everyone cursed by dos/windows line endings (aka CRLF):

The code reading the .gitignore files (excludes and excludes per
directory) leaves \r in the patterns, which causes fnmatch to fail for
no obvious reason. Just remove a "\r" preceding a "\n"
unconditionally.

Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Alex Riesen authored and Junio C Hamano committed Nov 3, 2005
1 parent 13d1cc3 commit d317e43
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ls-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static int add_excludes_from_file_1(const char *fname,
for (i = 0; i < size; i++) {
if (buf[i] == '\n') {
if (entry != buf + i && entry[0] != '#') {
buf[i] = 0;
buf[i - (i && buf[i-1] == '\r')] = 0;
add_exclude(entry, base, baselen, which);
}
entry = buf + i + 1;
Expand Down
12 changes: 12 additions & 0 deletions t/t3001-ls-files-others-exclude.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,16 @@ test_expect_success \
>output &&
diff -u expect output'

# Test \r\n (MSDOS-like systems)
echo -ne '*.1\r\n/*.3\r\n!*.6\r\n' >.gitignore

test_expect_success \
'git-ls-files --others with \r\n line endings.' \
'git-ls-files --others \
--exclude=\*.6 \
--exclude-per-directory=.gitignore \
--exclude-from=.git/ignore \
>output &&
diff -u expect output'

test_done

0 comments on commit d317e43

Please sign in to comment.