blob: 5e8d5fa50c9a6a548e5f2fdb11186c165519d06f [file] [log] [blame]
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +02001#!/bin/sh
2
Jonathan Nieder18acb302010-08-05 06:09:33 -05003test_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'
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +020014
15. ./test-lib.sh
16
Ramsay Jonesa31d0662010-12-14 18:32:12 +000017test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b
Eric Sunshineca02ad32010-09-17 09:16:01 -040018
Torsten Bögershausen65237282016-06-28 10:01:13 +020019compare_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
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +020026test_expect_success setup '
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +020027 git config core.autocrlf false &&
Jonathan Nieder18acb302010-08-05 06:09:33 -050028
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +020029 echo first line | append_cr >file &&
30 echo first line >control_file &&
31 echo only line >inert_file &&
Jonathan Nieder18acb302010-08-05 06:09:33 -050032
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +020033 git add file control_file inert_file &&
Jonathan Nieder18acb302010-08-05 06:09:33 -050034 test_tick &&
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +020035 git commit -m "Initial" &&
36 git tag initial &&
37 git branch side &&
Jonathan Nieder18acb302010-08-05 06:09:33 -050038
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +020039 echo "* text=auto" >.gitattributes &&
Torsten Bögershausen65237282016-06-28 10:01:13 +020040 echo first line >file &&
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +020041 git add .gitattributes file &&
Jonathan Nieder18acb302010-08-05 06:09:33 -050042 test_tick &&
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +020043 git commit -m "normalize file" &&
Jonathan Nieder18acb302010-08-05 06:09:33 -050044
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +020045 echo same line | append_cr >>file &&
46 echo same line >>control_file &&
47 git add file control_file &&
Jonathan Nieder18acb302010-08-05 06:09:33 -050048 test_tick &&
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +020049 git commit -m "add line from a" &&
50 git tag a &&
Jonathan Nieder18acb302010-08-05 06:09:33 -050051
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +020052 git rm .gitattributes &&
53 rm file &&
54 git checkout file &&
Jonathan Nieder18acb302010-08-05 06:09:33 -050055 test_tick &&
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +020056 git commit -m "remove .gitattributes" &&
57 git tag c &&
Jonathan Nieder18acb302010-08-05 06:09:33 -050058
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +020059 git checkout side &&
60 echo same line | append_cr >>file &&
61 echo same line >>control_file &&
62 git add file control_file &&
Jonathan Nieder18acb302010-08-05 06:09:33 -050063 test_tick &&
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +020064 git commit -m "add line from b" &&
65 git tag b &&
Jonathan Nieder18acb302010-08-05 06:09:33 -050066
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +020067 git checkout master
68'
69
Jonathan Niederbeeeb452010-08-05 06:13:04 -050070test_expect_success 'set up fuzz_conflict() helper' '
71 fuzz_conflict() {
Eric Sunshineca02ad32010-09-17 09:16:01 -040072 sed $SED_OPTIONS -e "s/^\([<>=]......\) .*/\1/" "$@"
Jonathan Niederbeeeb452010-08-05 06:13:04 -050073 }
74'
75
Jonathan Nieder18acb302010-08-05 06:09:33 -050076test_expect_success 'Merge after setting text=auto' '
77 cat <<-\EOF >expected &&
78 first line
79 same line
80 EOF
81
Brice Lambson5f4e02e2014-08-30 23:39:07 +020082 if test_have_prereq NATIVE_CRLF; then
83 append_cr <expected >expected.temp &&
84 mv expected.temp expected
85 fi &&
Jonathan Niederbeeeb452010-08-05 06:13:04 -050086 git config merge.renormalize true &&
Jonathan Nieder18acb302010-08-05 06:09:33 -050087 git rm -fr . &&
88 rm -f .gitattributes &&
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +020089 git reset --hard a &&
90 git merge b &&
Torsten Bögershausen65237282016-06-28 10:01:13 +020091 compare_files expected file
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +020092'
93
Junio C Hamano1335d762016-07-08 10:59:15 -070094test_expect_success 'Merge addition of text=auto eol=LF' '
95 git config core.eol lf &&
Jonathan Nieder18acb302010-08-05 06:09:33 -050096 cat <<-\EOF >expected &&
97 first line
98 same line
99 EOF
100
Jonathan Niederbeeeb452010-08-05 06:13:04 -0500101 git config merge.renormalize true &&
Jonathan Nieder18acb302010-08-05 06:09:33 -0500102 git rm -fr . &&
103 rm -f .gitattributes &&
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +0200104 git reset --hard b &&
105 git merge a &&
Torsten Bögershausen65237282016-06-28 10:01:13 +0200106 compare_files expected file
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +0200107'
108
Junio C Hamano1335d762016-07-08 10:59:15 -0700109test_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
Jonathan Niederbeeeb452010-08-05 06:13:04 -0500128test_expect_success 'Detect CRLF/LF conflict after setting text=auto' '
Junio C Hamano1335d762016-07-08 10:59:15 -0700129 git config core.eol native &&
Brice Lambson5f4e02e2014-08-30 23:39:07 +0200130 echo "<<<<<<<" >expected &&
Junio C Hamano1335d762016-07-08 10:59:15 -0700131 echo first line >>expected &&
132 echo same line >>expected &&
133 echo ======= >>expected &&
Brice Lambson5f4e02e2014-08-30 23:39:07 +0200134 echo first line | append_cr >>expected &&
135 echo same line | append_cr >>expected &&
136 echo ">>>>>>>" >>expected &&
Jonathan Niederbeeeb452010-08-05 06:13:04 -0500137 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 &&
Torsten Bögershausen65237282016-06-28 10:01:13 +0200142 compare_files expected file.fuzzy
Jonathan Niederbeeeb452010-08-05 06:13:04 -0500143'
144
145test_expect_success 'Detect LF/CRLF conflict from addition of text=auto' '
Brice Lambson5f4e02e2014-08-30 23:39:07 +0200146 echo "<<<<<<<" >expected &&
147 echo first line | append_cr >>expected &&
148 echo same line | append_cr >>expected &&
Junio C Hamano1335d762016-07-08 10:59:15 -0700149 echo ======= >>expected &&
150 echo first line >>expected &&
151 echo same line >>expected &&
Brice Lambson5f4e02e2014-08-30 23:39:07 +0200152 echo ">>>>>>>" >>expected &&
Jonathan Niederbeeeb452010-08-05 06:13:04 -0500153 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 &&
Torsten Bögershausen65237282016-06-28 10:01:13 +0200158 compare_files expected file.fuzzy
Jonathan Niederbeeeb452010-08-05 06:13:04 -0500159'
160
Jonathan Niederd347cee2010-08-05 06:11:12 -0500161test_expect_failure 'checkout -m after setting text=auto' '
162 cat <<-\EOF >expected &&
163 first line
164 same line
165 EOF
166
Jonathan Niederbeeeb452010-08-05 06:13:04 -0500167 git config merge.renormalize true &&
Jonathan Niederd347cee2010-08-05 06:11:12 -0500168 git rm -fr . &&
169 rm -f .gitattributes &&
170 git reset --hard initial &&
171 git checkout a -- . &&
172 git checkout -m b &&
Torsten Bögershausen65237282016-06-28 10:01:13 +0200173 compare_files expected file
Jonathan Niederd347cee2010-08-05 06:11:12 -0500174'
175
176test_expect_failure 'checkout -m addition of text=auto' '
177 cat <<-\EOF >expected &&
178 first line
179 same line
180 EOF
181
Jonathan Niederbeeeb452010-08-05 06:13:04 -0500182 git config merge.renormalize true &&
Jonathan Niederd347cee2010-08-05 06:11:12 -0500183 git rm -fr . &&
184 rm -f .gitattributes file &&
185 git reset --hard initial &&
186 git checkout b -- . &&
187 git checkout -m a &&
Torsten Bögershausen65237282016-06-28 10:01:13 +0200188 compare_files expected file
Jonathan Niederd347cee2010-08-05 06:11:12 -0500189'
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
Jonathan Niederbeeeb452010-08-05 06:13:04 -0500197 git config merge.renormalize true &&
Jonathan Niederd347cee2010-08-05 06:11:12 -0500198 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 &&
Torsten Bögershausen65237282016-06-28 10:01:13 +0200202 compare_files expected file
Jonathan Niederd347cee2010-08-05 06:11:12 -0500203'
204
Eyvind Bernhardsen331a1832010-07-02 21:20:48 +0200205test_expect_success 'Test delete/normalize conflict' '
Jonathan Nieder18acb302010-08-05 06:09:33 -0500206 git checkout -f side &&
207 git rm -fr . &&
208 rm -f .gitattributes &&
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +0200209 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