]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6038-merge-text-auto.sh
hashmap: use *_entry APIs for iteration
[thirdparty/git.git] / t / t6038-merge-text-auto.sh
CommitLineData
f217f0e8
EB
1#!/bin/sh
2
18acb30e
JN
3test_description='CRLF merge conflict across text=auto change
4
5* [master] remove .gitattributes
6 ! [side] add line from b
7--
8 + [side] add line from b
9* [master] remove .gitattributes
10* [master^] add line from a
11* [master~2] normalize file
12*+ [side^] Initial
13'
f217f0e8
EB
14
15. ./test-lib.sh
16
a31d0665 17test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b
ca02ad34 18
65237284
TB
19compare_files () {
20 tr '\015\000' QN <"$1" >"$1".expect &&
21 tr '\015\000' QN <"$2" >"$2".actual &&
22 test_cmp "$1".expect "$2".actual &&
23 rm "$1".expect "$2".actual
24}
25
f217f0e8 26test_expect_success setup '
f217f0e8 27 git config core.autocrlf false &&
18acb30e 28
f217f0e8
EB
29 echo first line | append_cr >file &&
30 echo first line >control_file &&
31 echo only line >inert_file &&
18acb30e 32
f217f0e8 33 git add file control_file inert_file &&
18acb30e 34 test_tick &&
f217f0e8
EB
35 git commit -m "Initial" &&
36 git tag initial &&
37 git branch side &&
18acb30e 38
f217f0e8 39 echo "* text=auto" >.gitattributes &&
65237284 40 echo first line >file &&
f217f0e8 41 git add .gitattributes file &&
18acb30e 42 test_tick &&
f217f0e8 43 git commit -m "normalize file" &&
18acb30e 44
f217f0e8
EB
45 echo same line | append_cr >>file &&
46 echo same line >>control_file &&
47 git add file control_file &&
18acb30e 48 test_tick &&
f217f0e8
EB
49 git commit -m "add line from a" &&
50 git tag a &&
18acb30e 51
f217f0e8
EB
52 git rm .gitattributes &&
53 rm file &&
54 git checkout file &&
18acb30e 55 test_tick &&
f217f0e8
EB
56 git commit -m "remove .gitattributes" &&
57 git tag c &&
18acb30e 58
f217f0e8
EB
59 git checkout side &&
60 echo same line | append_cr >>file &&
61 echo same line >>control_file &&
62 git add file control_file &&
18acb30e 63 test_tick &&
f217f0e8
EB
64 git commit -m "add line from b" &&
65 git tag b &&
18acb30e 66
f217f0e8
EB
67 git checkout master
68'
69
beeeb454
JN
70test_expect_success 'set up fuzz_conflict() helper' '
71 fuzz_conflict() {
ca02ad34 72 sed $SED_OPTIONS -e "s/^\([<>=]......\) .*/\1/" "$@"
beeeb454
JN
73 }
74'
75
18acb30e
JN
76test_expect_success 'Merge after setting text=auto' '
77 cat <<-\EOF >expected &&
78 first line
79 same line
80 EOF
81
5f4e02e5
BL
82 if test_have_prereq NATIVE_CRLF; then
83 append_cr <expected >expected.temp &&
84 mv expected.temp expected
85 fi &&
beeeb454 86 git config merge.renormalize true &&
18acb30e
JN
87 git rm -fr . &&
88 rm -f .gitattributes &&
f217f0e8
EB
89 git reset --hard a &&
90 git merge b &&
65237284 91 compare_files expected file
f217f0e8
EB
92'
93
1335d76e
JH
94test_expect_success 'Merge addition of text=auto eol=LF' '
95 git config core.eol lf &&
18acb30e
JN
96 cat <<-\EOF >expected &&
97 first line
98 same line
99 EOF
100
beeeb454 101 git config merge.renormalize true &&
18acb30e
JN
102 git rm -fr . &&
103 rm -f .gitattributes &&
f217f0e8
EB
104 git reset --hard b &&
105 git merge a &&
65237284 106 compare_files expected file
f217f0e8
EB
107'
108
1335d76e
JH
109test_expect_success 'Merge addition of text=auto eol=CRLF' '
110 git config core.eol crlf &&
111 cat <<-\EOF >expected &&
112 first line
113 same line
114 EOF
115
116 append_cr <expected >expected.temp &&
117 mv expected.temp expected &&
118 git config merge.renormalize true &&
119 git rm -fr . &&
120 rm -f .gitattributes &&
121 git reset --hard b &&
122 echo >&2 "After git reset --hard b" &&
123 git ls-files -s --eol >&2 &&
124 git merge a &&
125 compare_files expected file
126'
127
beeeb454 128test_expect_success 'Detect CRLF/LF conflict after setting text=auto' '
1335d76e 129 git config core.eol native &&
5f4e02e5 130 echo "<<<<<<<" >expected &&
1335d76e
JH
131 echo first line >>expected &&
132 echo same line >>expected &&
133 echo ======= >>expected &&
5f4e02e5
BL
134 echo first line | append_cr >>expected &&
135 echo same line | append_cr >>expected &&
136 echo ">>>>>>>" >>expected &&
beeeb454
JN
137 git config merge.renormalize false &&
138 rm -f .gitattributes &&
139 git reset --hard a &&
140 test_must_fail git merge b &&
141 fuzz_conflict file >file.fuzzy &&
65237284 142 compare_files expected file.fuzzy
beeeb454
JN
143'
144
145test_expect_success 'Detect LF/CRLF conflict from addition of text=auto' '
5f4e02e5
BL
146 echo "<<<<<<<" >expected &&
147 echo first line | append_cr >>expected &&
148 echo same line | append_cr >>expected &&
1335d76e
JH
149 echo ======= >>expected &&
150 echo first line >>expected &&
151 echo same line >>expected &&
5f4e02e5 152 echo ">>>>>>>" >>expected &&
beeeb454
JN
153 git config merge.renormalize false &&
154 rm -f .gitattributes &&
155 git reset --hard b &&
156 test_must_fail git merge a &&
157 fuzz_conflict file >file.fuzzy &&
65237284 158 compare_files expected file.fuzzy
beeeb454
JN
159'
160
d347cee4
JN
161test_expect_failure 'checkout -m after setting text=auto' '
162 cat <<-\EOF >expected &&
163 first line
164 same line
165 EOF
166
beeeb454 167 git config merge.renormalize true &&
d347cee4
JN
168 git rm -fr . &&
169 rm -f .gitattributes &&
170 git reset --hard initial &&
171 git checkout a -- . &&
172 git checkout -m b &&
65237284 173 compare_files expected file
d347cee4
JN
174'
175
176test_expect_failure 'checkout -m addition of text=auto' '
177 cat <<-\EOF >expected &&
178 first line
179 same line
180 EOF
181
beeeb454 182 git config merge.renormalize true &&
d347cee4
JN
183 git rm -fr . &&
184 rm -f .gitattributes file &&
185 git reset --hard initial &&
186 git checkout b -- . &&
187 git checkout -m a &&
65237284 188 compare_files expected file
d347cee4
JN
189'
190
191test_expect_failure 'cherry-pick patch from after text=auto was added' '
192 append_cr <<-\EOF >expected &&
193 first line
194 same line
195 EOF
196
beeeb454 197 git config merge.renormalize true &&
d347cee4
JN
198 git rm -fr . &&
199 git reset --hard b &&
200 test_must_fail git cherry-pick a >err 2>&1 &&
201 grep "[Nn]othing added" err &&
65237284 202 compare_files expected file
d347cee4
JN
203'
204
331a1838 205test_expect_success 'Test delete/normalize conflict' '
18acb30e
JN
206 git checkout -f side &&
207 git rm -fr . &&
208 rm -f .gitattributes &&
f217f0e8
EB
209 git reset --hard initial &&
210 git rm file &&
211 git commit -m "remove file" &&
212 git checkout master &&
213 git reset --hard a^ &&
214 git merge side
215'
216
217test_done