#!/bin/sh global test_description := ''CRLF conversion'' source ./test-lib.sh proc has_cr { tr '\015' Q <$1 | grep Q >/dev/null } test_expect_success setup ' git config core.autocrlf false && 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 && git add . && git commit -m initial && LFonly=$(git rev-parse HEAD:LFonly) && CRLFonly=$(git rev-parse HEAD:CRLFonly) && LFwithNUL=$(git rev-parse HEAD:LFwithNUL) && echo happy. ' test_expect_success 'default settings cause no changes' ' rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL && git read-tree --reset -u HEAD && ! 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" ' test_expect_success 'crlf=true causes a CRLF file to be normalized' ' # Backwards compatibility check rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL && echo "CRLFonly crlf" > .gitattributes && git read-tree --reset -u HEAD && # Note, "normalized" means that git will normalize it if added has_cr CRLFonly && CRLFonlydiff=$(git diff CRLFonly) && test -n "$CRLFonlydiff" ' test_expect_success 'text=true causes a CRLF file to be normalized' ' rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL && echo "CRLFonly text" > .gitattributes && git read-tree --reset -u HEAD && # Note, "normalized" means that git will normalize it if added has_cr CRLFonly && CRLFonlydiff=$(git diff CRLFonly) && test -n "$CRLFonlydiff" ' test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=false' ' rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL && git config core.autocrlf false && echo "LFonly eol=crlf" > .gitattributes && git read-tree --reset -u HEAD && has_cr LFonly && LFonlydiff=$(git diff LFonly) && test -z "$LFonlydiff" ' test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=input' ' rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL && git config core.autocrlf input && echo "LFonly eol=crlf" > .gitattributes && git read-tree --reset -u HEAD && has_cr LFonly && LFonlydiff=$(git diff LFonly) && test -z "$LFonlydiff" ' test_expect_success 'eol=lf gives a normalized file LFs with autocrlf=true' ' rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL && git config core.autocrlf true && echo "LFonly eol=lf" > .gitattributes && git read-tree --reset -u HEAD && ! has_cr LFonly && LFonlydiff=$(git diff LFonly) && test -z "$LFonlydiff" ' test_expect_success 'autocrlf=true does not normalize CRLF files' ' rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL && git config core.autocrlf true && git read-tree --reset -u HEAD && 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" ' test_expect_success 'text=auto, autocrlf=true does not normalize CRLF files' ' rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL && git config core.autocrlf true && echo "* text=auto" > .gitattributes && git read-tree --reset -u HEAD && 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" ' test_expect_success 'text=auto, autocrlf=true does not normalize binary files' ' rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL && git config core.autocrlf true && echo "* text=auto" > .gitattributes && git read-tree --reset -u HEAD && ! has_cr LFwithNUL && LFwithNULdiff=$(git diff LFwithNUL) && test -z "$LFwithNULdiff" ' test_expect_success 'eol=crlf _does_ normalize binary files' ' rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL && echo "LFwithNUL eol=crlf" > .gitattributes && git read-tree --reset -u HEAD && has_cr LFwithNUL && LFwithNULdiff=$(git diff LFwithNUL) && test -z "$LFwithNULdiff" ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"CRLF conversion">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (FuncDef name: has_cr body: (BraceGroup children: [ (Pipeline children: [ (SimpleCommand words: [{(tr)} {(SQ <"\\015">)} {(Q)}] redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {(DQ ($ VSub_Number "$1"))} spids: [30] ) ] ) (SimpleCommand words: [{(grep)} {(Q)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[41])] ) ] negated: False ) ] spids: [19] ) spids: [15 18] ) (C {(test_expect_success)} {(setup)} { (SQ <"\n"> <"\n"> <"\tgit config core.autocrlf false &&\n"> <"\n"> <"\tfor w in Hello world how are you; do echo $w; done >LFonly &&\n"> <"\tfor w in I am very very fine thank you; do echo ${w}Q; done | q_to_cr >CRLFonly &&\n"> < "\tfor w in Oh here is a QNUL byte how alarming; do echo ${w}; done | q_to_nul >LFwithNUL &&\n" > <"\tgit add . &&\n"> <"\n"> <"\tgit commit -m initial &&\n"> <"\n"> <"\tLFonly=$(git rev-parse HEAD:LFonly) &&\n"> <"\tCRLFonly=$(git rev-parse HEAD:CRLFonly) &&\n"> <"\tLFwithNUL=$(git rev-parse HEAD:LFwithNUL) &&\n"> <"\n"> <"\techo happy.\n"> ) } ) (C {(test_expect_success)} {(SQ <"default settings cause no changes">)} { (SQ <"\n"> <"\n"> <"\trm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&\n"> <"\tgit read-tree --reset -u HEAD &&\n"> <"\n"> <"\t! has_cr LFonly &&\n"> <"\thas_cr CRLFonly &&\n"> <"\tLFonlydiff=$(git diff LFonly) &&\n"> <"\tCRLFonlydiff=$(git diff CRLFonly) &&\n"> <"\tLFwithNULdiff=$(git diff LFwithNUL) &&\n"> <"\ttest -z \"$LFonlydiff\" -a -z \"$CRLFonlydiff\" -a -z \"$LFwithNULdiff\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"crlf=true causes a CRLF file to be normalized">)} { (SQ <"\n"> <"\n"> <"\t# Backwards compatibility check\n"> <"\trm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&\n"> <"\techo \"CRLFonly crlf\" > .gitattributes &&\n"> <"\tgit read-tree --reset -u HEAD &&\n"> <"\n"> <"\t# Note, \"normalized\" means that git will normalize it if added\n"> <"\thas_cr CRLFonly &&\n"> <"\tCRLFonlydiff=$(git diff CRLFonly) &&\n"> <"\ttest -n \"$CRLFonlydiff\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"text=true causes a CRLF file to be normalized">)} { (SQ <"\n"> <"\n"> <"\trm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&\n"> <"\techo \"CRLFonly text\" > .gitattributes &&\n"> <"\tgit read-tree --reset -u HEAD &&\n"> <"\n"> <"\t# Note, \"normalized\" means that git will normalize it if added\n"> <"\thas_cr CRLFonly &&\n"> <"\tCRLFonlydiff=$(git diff CRLFonly) &&\n"> <"\ttest -n \"$CRLFonlydiff\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"eol=crlf gives a normalized file CRLFs with autocrlf=false">)} { (SQ <"\n"> <"\n"> <"\trm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&\n"> <"\tgit config core.autocrlf false &&\n"> <"\techo \"LFonly eol=crlf\" > .gitattributes &&\n"> <"\tgit read-tree --reset -u HEAD &&\n"> <"\n"> <"\thas_cr LFonly &&\n"> <"\tLFonlydiff=$(git diff LFonly) &&\n"> <"\ttest -z \"$LFonlydiff\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"eol=crlf gives a normalized file CRLFs with autocrlf=input">)} { (SQ <"\n"> <"\n"> <"\trm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&\n"> <"\tgit config core.autocrlf input &&\n"> <"\techo \"LFonly eol=crlf\" > .gitattributes &&\n"> <"\tgit read-tree --reset -u HEAD &&\n"> <"\n"> <"\thas_cr LFonly &&\n"> <"\tLFonlydiff=$(git diff LFonly) &&\n"> <"\ttest -z \"$LFonlydiff\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"eol=lf gives a normalized file LFs with autocrlf=true">)} { (SQ <"\n"> <"\n"> <"\trm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&\n"> <"\tgit config core.autocrlf true &&\n"> <"\techo \"LFonly eol=lf\" > .gitattributes &&\n"> <"\tgit read-tree --reset -u HEAD &&\n"> <"\n"> <"\t! has_cr LFonly &&\n"> <"\tLFonlydiff=$(git diff LFonly) &&\n"> <"\ttest -z \"$LFonlydiff\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"autocrlf=true does not normalize CRLF files">)} { (SQ <"\n"> <"\n"> <"\trm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&\n"> <"\tgit config core.autocrlf true &&\n"> <"\tgit read-tree --reset -u HEAD &&\n"> <"\n"> <"\thas_cr LFonly &&\n"> <"\thas_cr CRLFonly &&\n"> <"\tLFonlydiff=$(git diff LFonly) &&\n"> <"\tCRLFonlydiff=$(git diff CRLFonly) &&\n"> <"\tLFwithNULdiff=$(git diff LFwithNUL) &&\n"> <"\ttest -z \"$LFonlydiff\" -a -z \"$CRLFonlydiff\" -a -z \"$LFwithNULdiff\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"text=auto, autocrlf=true does not normalize CRLF files">)} { (SQ <"\n"> <"\n"> <"\trm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&\n"> <"\tgit config core.autocrlf true &&\n"> <"\techo \"* text=auto\" > .gitattributes &&\n"> <"\tgit read-tree --reset -u HEAD &&\n"> <"\n"> <"\thas_cr LFonly &&\n"> <"\thas_cr CRLFonly &&\n"> <"\tLFonlydiff=$(git diff LFonly) &&\n"> <"\tCRLFonlydiff=$(git diff CRLFonly) &&\n"> <"\tLFwithNULdiff=$(git diff LFwithNUL) &&\n"> <"\ttest -z \"$LFonlydiff\" -a -z \"$CRLFonlydiff\" -a -z \"$LFwithNULdiff\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"text=auto, autocrlf=true does not normalize binary files">)} { (SQ <"\n"> <"\n"> <"\trm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&\n"> <"\tgit config core.autocrlf true &&\n"> <"\techo \"* text=auto\" > .gitattributes &&\n"> <"\tgit read-tree --reset -u HEAD &&\n"> <"\n"> <"\t! has_cr LFwithNUL &&\n"> <"\tLFwithNULdiff=$(git diff LFwithNUL) &&\n"> <"\ttest -z \"$LFwithNULdiff\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"eol=crlf _does_ normalize binary files">)} { (SQ <"\n"> <"\n"> <"\trm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&\n"> <"\techo \"LFwithNUL eol=crlf\" > .gitattributes &&\n"> <"\tgit read-tree --reset -u HEAD &&\n"> <"\n"> <"\thas_cr LFwithNUL &&\n"> <"\tLFwithNULdiff=$(git diff LFwithNUL) &&\n"> <"\ttest -z \"$LFwithNULdiff\"\n"> ) } ) (C {(test_done)}) ] )