2010-05-19 20:43:09 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='CRLF conversion'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
has_cr() {
|
|
|
|
tr '\015' Q <"$1" | grep Q >/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
|
|
|
|
git config core.autocrlf false &&
|
|
|
|
|
2014-06-29 06:34:22 +00:00
|
|
|
for w in Hello world how are you; do echo $w; done >LFonly &&
|
|
|
|
for w in I am very very fine thank you; do echo ${w}Q; done | q_to_cr >CRLFonly &&
|
|
|
|
for w in Oh here is a QNUL byte how alarming; do echo ${w}; done | q_to_nul >LFwithNUL &&
|
2010-05-19 20:43:09 +00:00
|
|
|
git add . &&
|
|
|
|
|
|
|
|
git commit -m initial &&
|
|
|
|
|
2014-06-29 06:34:22 +00:00
|
|
|
LFonly=$(git rev-parse HEAD:LFonly) &&
|
|
|
|
CRLFonly=$(git rev-parse HEAD:CRLFonly) &&
|
|
|
|
LFwithNUL=$(git rev-parse HEAD:LFwithNUL) &&
|
2010-05-19 20:43:09 +00:00
|
|
|
|
|
|
|
echo happy.
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'default settings cause no changes' '
|
|
|
|
|
2014-06-29 06:34:22 +00:00
|
|
|
rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
|
2010-05-19 20:43:09 +00:00
|
|
|
git read-tree --reset -u HEAD &&
|
|
|
|
|
2014-06-29 06:34:22 +00:00
|
|
|
! has_cr LFonly &&
|
|
|
|
has_cr CRLFonly &&
|
|
|
|
LFonlydiff=$(git diff LFonly) &&
|
|
|
|
CRLFonlydiff=$(git diff CRLFonly) &&
|
|
|
|
LFwithNULdiff=$(git diff LFwithNUL) &&
|
|
|
|
test -z "$LFonlydiff" -a -z "$CRLFonlydiff" -a -z "$LFwithNULdiff"
|
2010-05-19 20:43:09 +00:00
|
|
|
'
|
|
|
|
|
2010-05-19 20:43:10 +00:00
|
|
|
test_expect_success 'crlf=true causes a CRLF file to be normalized' '
|
2010-05-19 20:43:09 +00:00
|
|
|
|
2010-05-19 20:43:11 +00:00
|
|
|
# Backwards compatibility check
|
2014-06-29 06:34:22 +00:00
|
|
|
rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
|
|
|
|
echo "CRLFonly crlf" > .gitattributes &&
|
2010-05-19 20:43:09 +00:00
|
|
|
git read-tree --reset -u HEAD &&
|
|
|
|
|
|
|
|
# Note, "normalized" means that git will normalize it if added
|
2014-06-29 06:34:22 +00:00
|
|
|
has_cr CRLFonly &&
|
|
|
|
CRLFonlydiff=$(git diff CRLFonly) &&
|
|
|
|
test -n "$CRLFonlydiff"
|
2010-05-19 20:43:09 +00:00
|
|
|
'
|
|
|
|
|
2010-05-19 20:43:11 +00:00
|
|
|
test_expect_success 'text=true causes a CRLF file to be normalized' '
|
|
|
|
|
2014-06-29 06:34:22 +00:00
|
|
|
rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
|
|
|
|
echo "CRLFonly text" > .gitattributes &&
|
2010-05-19 20:43:11 +00:00
|
|
|
git read-tree --reset -u HEAD &&
|
|
|
|
|
|
|
|
# Note, "normalized" means that git will normalize it if added
|
2014-06-29 06:34:22 +00:00
|
|
|
has_cr CRLFonly &&
|
|
|
|
CRLFonlydiff=$(git diff CRLFonly) &&
|
|
|
|
test -n "$CRLFonlydiff"
|
2010-05-19 20:43:11 +00:00
|
|
|
'
|
|
|
|
|
2010-05-19 20:43:10 +00:00
|
|
|
test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=false' '
|
2010-05-19 20:43:09 +00:00
|
|
|
|
2014-06-29 06:34:22 +00:00
|
|
|
rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
|
2010-05-19 20:43:09 +00:00
|
|
|
git config core.autocrlf false &&
|
2014-06-29 06:34:22 +00:00
|
|
|
echo "LFonly eol=crlf" > .gitattributes &&
|
2010-05-19 20:43:09 +00:00
|
|
|
git read-tree --reset -u HEAD &&
|
|
|
|
|
2014-06-29 06:34:22 +00:00
|
|
|
has_cr LFonly &&
|
|
|
|
LFonlydiff=$(git diff LFonly) &&
|
|
|
|
test -z "$LFonlydiff"
|
2010-05-19 20:43:09 +00:00
|
|
|
'
|
|
|
|
|
2010-05-19 20:43:10 +00:00
|
|
|
test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=input' '
|
2010-05-19 20:43:09 +00:00
|
|
|
|
2014-06-29 06:34:22 +00:00
|
|
|
rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
|
2010-05-19 20:43:09 +00:00
|
|
|
git config core.autocrlf input &&
|
2014-06-29 06:34:22 +00:00
|
|
|
echo "LFonly eol=crlf" > .gitattributes &&
|
2010-05-19 20:43:09 +00:00
|
|
|
git read-tree --reset -u HEAD &&
|
|
|
|
|
2014-06-29 06:34:22 +00:00
|
|
|
has_cr LFonly &&
|
|
|
|
LFonlydiff=$(git diff LFonly) &&
|
|
|
|
test -z "$LFonlydiff"
|
2010-05-19 20:43:09 +00:00
|
|
|
'
|
|
|
|
|
2010-05-19 20:43:10 +00:00
|
|
|
test_expect_success 'eol=lf gives a normalized file LFs with autocrlf=true' '
|
2010-05-19 20:43:09 +00:00
|
|
|
|
2014-06-29 06:34:22 +00:00
|
|
|
rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
|
2010-05-19 20:43:09 +00:00
|
|
|
git config core.autocrlf true &&
|
2014-06-29 06:34:22 +00:00
|
|
|
echo "LFonly eol=lf" > .gitattributes &&
|
2010-05-19 20:43:09 +00:00
|
|
|
git read-tree --reset -u HEAD &&
|
|
|
|
|
2014-06-29 06:34:22 +00:00
|
|
|
! has_cr LFonly &&
|
|
|
|
LFonlydiff=$(git diff LFonly) &&
|
|
|
|
test -z "$LFonlydiff"
|
2010-05-19 20:43:09 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'autocrlf=true does not normalize CRLF files' '
|
|
|
|
|
2014-06-29 06:34:22 +00:00
|
|
|
rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
|
2010-05-19 20:43:09 +00:00
|
|
|
git config core.autocrlf true &&
|
|
|
|
git read-tree --reset -u HEAD &&
|
|
|
|
|
2014-06-29 06:34:22 +00:00
|
|
|
has_cr LFonly &&
|
|
|
|
has_cr CRLFonly &&
|
|
|
|
LFonlydiff=$(git diff LFonly) &&
|
|
|
|
CRLFonlydiff=$(git diff CRLFonly) &&
|
|
|
|
LFwithNULdiff=$(git diff LFwithNUL) &&
|
|
|
|
test -z "$LFonlydiff" -a -z "$CRLFonlydiff" -a -z "$LFwithNULdiff"
|
2010-05-19 20:43:09 +00:00
|
|
|
'
|
|
|
|
|
2016-06-28 08:01:13 +00:00
|
|
|
test_expect_success 'text=auto, autocrlf=true does not normalize CRLF files' '
|
2010-05-19 20:43:09 +00:00
|
|
|
|
2014-06-29 06:34:22 +00:00
|
|
|
rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
|
2010-05-19 20:43:09 +00:00
|
|
|
git config core.autocrlf true &&
|
2010-05-19 20:43:11 +00:00
|
|
|
echo "* text=auto" > .gitattributes &&
|
2010-05-19 20:43:09 +00:00
|
|
|
git read-tree --reset -u HEAD &&
|
|
|
|
|
2014-06-29 06:34:22 +00:00
|
|
|
has_cr LFonly &&
|
|
|
|
has_cr CRLFonly &&
|
|
|
|
LFonlydiff=$(git diff LFonly) &&
|
|
|
|
CRLFonlydiff=$(git diff CRLFonly) &&
|
|
|
|
LFwithNULdiff=$(git diff LFwithNUL) &&
|
2016-06-28 08:01:13 +00:00
|
|
|
test -z "$LFonlydiff" -a -z "$CRLFonlydiff" -a -z "$LFwithNULdiff"
|
2010-05-19 20:43:09 +00:00
|
|
|
'
|
|
|
|
|
2010-05-19 20:43:11 +00:00
|
|
|
test_expect_success 'text=auto, autocrlf=true does not normalize binary files' '
|
2010-05-19 20:43:09 +00:00
|
|
|
|
2014-06-29 06:34:22 +00:00
|
|
|
rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
|
2010-05-19 20:43:09 +00:00
|
|
|
git config core.autocrlf true &&
|
2010-05-19 20:43:11 +00:00
|
|
|
echo "* text=auto" > .gitattributes &&
|
2010-05-19 20:43:09 +00:00
|
|
|
git read-tree --reset -u HEAD &&
|
|
|
|
|
2014-06-29 06:34:22 +00:00
|
|
|
! has_cr LFwithNUL &&
|
|
|
|
LFwithNULdiff=$(git diff LFwithNUL) &&
|
|
|
|
test -z "$LFwithNULdiff"
|
2010-05-19 20:43:09 +00:00
|
|
|
'
|
|
|
|
|
2010-05-19 20:43:10 +00:00
|
|
|
test_expect_success 'eol=crlf _does_ normalize binary files' '
|
2010-05-19 20:43:09 +00:00
|
|
|
|
2014-06-29 06:34:22 +00:00
|
|
|
rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
|
|
|
|
echo "LFwithNUL eol=crlf" > .gitattributes &&
|
2010-05-19 20:43:09 +00:00
|
|
|
git read-tree --reset -u HEAD &&
|
|
|
|
|
2014-06-29 06:34:22 +00:00
|
|
|
has_cr LFwithNUL &&
|
|
|
|
LFwithNULdiff=$(git diff LFwithNUL) &&
|
|
|
|
test -z "$LFwithNULdiff"
|
2010-05-19 20:43:09 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_done
|