summaryrefslogtreecommitdiff
path: root/t/t6038-merge-text-auto.sh
blob: a7ea4b626b553d5563207b95fbd10afdae47002c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/sh

test_description='CRLF merge conflict across text=auto change

* [master] remove .gitattributes
 ! [side] add line from b
--
 + [side] add line from b
*  [master] remove .gitattributes
*  [master^] add line from a
*  [master~2] normalize file
*+ [side^] Initial
'

. ./test-lib.sh

test_expect_success setup '
	git config merge.renormalize true &&
	git config core.autocrlf false &&

	echo first line | append_cr >file &&
	echo first line >control_file &&
	echo only line >inert_file &&

	git add file control_file inert_file &&
	test_tick &&
	git commit -m "Initial" &&
	git tag initial &&
	git branch side &&

	echo "* text=auto" >.gitattributes &&
	touch file &&
	git add .gitattributes file &&
	test_tick &&
	git commit -m "normalize file" &&

	echo same line | append_cr >>file &&
	echo same line >>control_file &&
	git add file control_file &&
	test_tick &&
	git commit -m "add line from a" &&
	git tag a &&

	git rm .gitattributes &&
	rm file &&
	git checkout file &&
	test_tick &&
	git commit -m "remove .gitattributes" &&
	git tag c &&

	git checkout side &&
	echo same line | append_cr >>file &&
	echo same line >>control_file &&
	git add file control_file &&
	test_tick &&
	git commit -m "add line from b" &&
	git tag b &&

	git checkout master
'

test_expect_success 'Merge after setting text=auto' '
	cat <<-\EOF >expected &&
	first line
	same line
	EOF

	git rm -fr . &&
	rm -f .gitattributes &&
	git reset --hard a &&
	git merge b &&
	test_cmp expected file
'

test_expect_success 'Merge addition of text=auto' '
	cat <<-\EOF >expected &&
	first line
	same line
	EOF

	git rm -fr . &&
	rm -f .gitattributes &&
	git reset --hard b &&
	git merge a &&
	test_cmp expected file
'

test_expect_failure 'checkout -m after setting text=auto' '
	cat <<-\EOF >expected &&
	first line
	same line
	EOF

	git rm -fr . &&
	rm -f .gitattributes &&
	git reset --hard initial &&
	git checkout a -- . &&
	git checkout -m b &&
	test_cmp expected file
'

test_expect_failure 'checkout -m addition of text=auto' '
	cat <<-\EOF >expected &&
	first line
	same line
	EOF

	git rm -fr . &&
	rm -f .gitattributes file &&
	git reset --hard initial &&
	git checkout b -- . &&
	git checkout -m a &&
	test_cmp expected file
'

test_expect_failure 'cherry-pick patch from after text=auto was added' '
	append_cr <<-\EOF >expected &&
	first line
	same line
	EOF

	git rm -fr . &&
	git reset --hard b &&
	test_must_fail git cherry-pick a >err 2>&1 &&
	grep "[Nn]othing added" err &&
	test_cmp expected file
'

test_expect_success 'Test delete/normalize conflict' '
	git checkout -f side &&
	git rm -fr . &&
	rm -f .gitattributes &&
	git reset --hard initial &&
	git rm file &&
	git commit -m "remove file" &&
	git checkout master &&
	git reset --hard a^ &&
	git merge side
'

test_done