#!/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 && echo "one text" > .gitattributes && for w in Hello world how are you; do echo $w; done >one && for w in I am very very fine thank you; do echo $w; done >two && git add . && git commit -m initial && one=$(git rev-parse HEAD:one) && two=$(git rev-parse HEAD:two) && echo happy. ' test_expect_success 'eol=lf puts LFs in normalized file' ' rm -f .gitattributes tmp one two && git config core.eol lf && git read-tree --reset -u HEAD && ! has_cr one && ! has_cr two && onediff=$(git diff one) && twodiff=$(git diff two) && test -z "$onediff" && test -z "$twodiff" ' test_expect_success 'eol=crlf puts CRLFs in normalized file' ' rm -f .gitattributes tmp one two && git config core.eol crlf && git read-tree --reset -u HEAD && has_cr one && ! has_cr two && onediff=$(git diff one) && twodiff=$(git diff two) && test -z "$onediff" && test -z "$twodiff" ' test_expect_success 'autocrlf=true overrides eol=lf' ' rm -f .gitattributes tmp one two && git config core.eol lf && git config core.autocrlf true && git read-tree --reset -u HEAD && has_cr one && has_cr two && onediff=$(git diff one) && twodiff=$(git diff two) && test -z "$onediff" && test -z "$twodiff" ' test_expect_success 'autocrlf=true overrides unset eol' ' rm -f .gitattributes tmp one two && git config --unset-all core.eol && git config core.autocrlf true && git read-tree --reset -u HEAD && has_cr one && has_cr two && onediff=$(git diff one) && twodiff=$(git diff two) && test -z "$onediff" && test -z "$twodiff" ' test_expect_success NATIVE_CRLF 'eol native is crlf' ' rm -rf native_eol && mkdir native_eol && ( cd native_eol && printf "*.txt text\n" >.gitattributes && printf "one\r\ntwo\r\nthree\r\n" >filedos.txt && printf "one\ntwo\nthree\n" >fileunix.txt && git init && git config core.autocrlf false && git config core.eol native && git add filedos.txt fileunix.txt && git commit -m "first" && rm file*.txt && git reset --hard HEAD && has_cr filedos.txt && has_cr fileunix.txt ) ' 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"> <"\techo \"one text\" > .gitattributes &&\n"> <"\n"> <"\tfor w in Hello world how are you; do echo $w; done >one &&\n"> <"\tfor w in I am very very fine thank you; do echo $w; done >two &&\n"> <"\tgit add . &&\n"> <"\n"> <"\tgit commit -m initial &&\n"> <"\n"> <"\tone=$(git rev-parse HEAD:one) &&\n"> <"\ttwo=$(git rev-parse HEAD:two) &&\n"> <"\n"> <"\techo happy.\n"> ) } ) (C {(test_expect_success)} {(SQ <"eol=lf puts LFs in normalized file">)} { (SQ <"\n"> <"\n"> <"\trm -f .gitattributes tmp one two &&\n"> <"\tgit config core.eol lf &&\n"> <"\tgit read-tree --reset -u HEAD &&\n"> <"\n"> <"\t! has_cr one &&\n"> <"\t! has_cr two &&\n"> <"\tonediff=$(git diff one) &&\n"> <"\ttwodiff=$(git diff two) &&\n"> <"\ttest -z \"$onediff\" && test -z \"$twodiff\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"eol=crlf puts CRLFs in normalized file">)} { (SQ <"\n"> <"\n"> <"\trm -f .gitattributes tmp one two &&\n"> <"\tgit config core.eol crlf &&\n"> <"\tgit read-tree --reset -u HEAD &&\n"> <"\n"> <"\thas_cr one &&\n"> <"\t! has_cr two &&\n"> <"\tonediff=$(git diff one) &&\n"> <"\ttwodiff=$(git diff two) &&\n"> <"\ttest -z \"$onediff\" && test -z \"$twodiff\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"autocrlf=true overrides eol=lf">)} { (SQ <"\n"> <"\n"> <"\trm -f .gitattributes tmp one two &&\n"> <"\tgit config core.eol lf &&\n"> <"\tgit config core.autocrlf true &&\n"> <"\tgit read-tree --reset -u HEAD &&\n"> <"\n"> <"\thas_cr one &&\n"> <"\thas_cr two &&\n"> <"\tonediff=$(git diff one) &&\n"> <"\ttwodiff=$(git diff two) &&\n"> <"\ttest -z \"$onediff\" && test -z \"$twodiff\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"autocrlf=true overrides unset eol">)} { (SQ <"\n"> <"\n"> <"\trm -f .gitattributes tmp one two &&\n"> <"\tgit config --unset-all core.eol &&\n"> <"\tgit config core.autocrlf true &&\n"> <"\tgit read-tree --reset -u HEAD &&\n"> <"\n"> <"\thas_cr one &&\n"> <"\thas_cr two &&\n"> <"\tonediff=$(git diff one) &&\n"> <"\ttwodiff=$(git diff two) &&\n"> <"\ttest -z \"$onediff\" && test -z \"$twodiff\"\n"> ) } ) (C {(test_expect_success)} {(NATIVE_CRLF)} {(SQ <"eol native is crlf">)} { (SQ <"\n"> <"\n"> <"\trm -rf native_eol && mkdir native_eol &&\n"> <"\t(\n"> <"\t\tcd native_eol &&\n"> <"\t\tprintf \"*.txt text\\n\" >.gitattributes &&\n"> <"\t\tprintf \"one\\r\\ntwo\\r\\nthree\\r\\n\" >filedos.txt &&\n"> <"\t\tprintf \"one\\ntwo\\nthree\\n\" >fileunix.txt &&\n"> <"\t\tgit init &&\n"> <"\t\tgit config core.autocrlf false &&\n"> <"\t\tgit config core.eol native &&\n"> <"\t\tgit add filedos.txt fileunix.txt &&\n"> <"\t\tgit commit -m \"first\" &&\n"> <"\t\trm file*.txt &&\n"> <"\t\tgit reset --hard HEAD &&\n"> <"\t\thas_cr filedos.txt &&\n"> <"\t\thas_cr fileunix.txt\n"> <"\t)\n"> ) } ) (C {(test_done)}) ] )