t0026-eol-config.sh 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/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 &&

J
Jonathan Nieder 已提交
15
	echo "one text" > .gitattributes &&
16 17 18 19 20 21 22

	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 &&

23 24
	one=$(git rev-parse HEAD:one) &&
	two=$(git rev-parse HEAD:two) &&
25 26 27 28 29 30 31 32 33 34 35 36

	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 &&
37 38
	onediff=$(git diff one) &&
	twodiff=$(git diff two) &&
39 40 41 42 43 44 45 46 47 48 49
	test -z "$onediff" -a -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 &&
50 51
	onediff=$(git diff one) &&
	twodiff=$(git diff two) &&
52 53 54 55 56 57 58 59 60 61 62 63
	test -z "$onediff" -a -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 &&
64 65
	onediff=$(git diff one) &&
	twodiff=$(git diff two) &&
66 67 68 69 70 71 72 73 74 75 76 77
	test -z "$onediff" -a -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 &&
78 79
	onediff=$(git diff one) &&
	twodiff=$(git diff two) &&
80 81 82 83
	test -z "$onediff" -a -z "$twodiff"
'

test_done