Skip to content

Commit c29187a

Browse files
committed
Push the NATIVE_CRLF Makefile variable to C and added a test for native.
Commit 95f31e9 correctly points out that the NATIVE_CRLF setting is incorrectly set on Mingw git. However, the Makefile variable is not propagated to the C preprocessor and results in no change. This patch pushes the definition to the C code and adds a test to validate that when core.eol as native is crlf, we actually normalize text files to this line ending convention when core.autocrlf is false. Signed-off-by: Pat Thoyts <[email protected]>
1 parent 498e5f6 commit c29187a

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,9 @@ ifdef NO_REGEX
14791479
COMPAT_CFLAGS += -Icompat/regex
14801480
COMPAT_OBJS += compat/regex/regex.o
14811481
endif
1482+
ifdef NATIVE_CRLF
1483+
BASIC_CFLAGS += -DNATIVE_CRLF
1484+
endif
14821485

14831486
ifdef USE_NED_ALLOCATOR
14841487
COMPAT_CFLAGS += -Icompat/nedmalloc

t/t0026-eol-config.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ has_cr() {
88
tr '\015' Q <"$1" | grep Q >/dev/null
99
}
1010

11+
# core.eol crlf and core.autocrlf input are not permitted.
12+
# this lets us check for the core.eol native being crlf.
13+
set_native_eol_prereq() {
14+
rm -rf eol && mkdir eol &&
15+
( cd eol &&
16+
git init --quiet &&
17+
git config core.autocrlf input &&
18+
git config core.eol native &&
19+
git var core.eol 2> /dev/null
20+
) ||
21+
test_set_prereq NATIVE_EOL_IS_CRLF
22+
}
23+
set_native_eol_prereq
24+
1125
test_expect_success setup '
1226
1327
git config core.autocrlf false &&
@@ -80,4 +94,22 @@ test_expect_success 'autocrlf=true overrides unset eol' '
8094
test -z "$onediff" -a -z "$twodiff"
8195
'
8296

97+
test_expect_success NATIVE_EOL_IS_CRLF 'eol native is crlf' '
98+
99+
rm -rf native_eol && mkdir native_eol &&
100+
( cd native_eol &&
101+
printf "*.txt text\n" > .gitattributes
102+
printf "one\r\ntwo\r\nthree\r\n" > filedos.txt
103+
printf "one\ntwo\nthree\n" > fileunix.txt
104+
git init &&
105+
git config core.autocrlf false &&
106+
git config core.eol native &&
107+
git add filedos.txt fileunix.txt &&
108+
git commit -m "first" &&
109+
rm file*.txt &&
110+
git reset --hard HEAD &&
111+
has_cr filedos.txt && has_cr fileunix.txt
112+
)
113+
'
114+
83115
test_done

0 commit comments

Comments
 (0)