merge-one-file: compute empty blob object ID
[git/debian.git] / t / t6038-merge-text-auto.sh
blob5e8d5fa50c9a6a548e5f2fdb11186c165519d06f
1 #!/bin/sh
3 test_description='CRLF merge conflict across text=auto change
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
15 . ./test-lib.sh
17 test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b
19 compare_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
26 test_expect_success setup '
27 git config core.autocrlf false &&
29 echo first line | append_cr >file &&
30 echo first line >control_file &&
31 echo only line >inert_file &&
33 git add file control_file inert_file &&
34 test_tick &&
35 git commit -m "Initial" &&
36 git tag initial &&
37 git branch side &&
39 echo "* text=auto" >.gitattributes &&
40 echo first line >file &&
41 git add .gitattributes file &&
42 test_tick &&
43 git commit -m "normalize file" &&
45 echo same line | append_cr >>file &&
46 echo same line >>control_file &&
47 git add file control_file &&
48 test_tick &&
49 git commit -m "add line from a" &&
50 git tag a &&
52 git rm .gitattributes &&
53 rm file &&
54 git checkout file &&
55 test_tick &&
56 git commit -m "remove .gitattributes" &&
57 git tag c &&
59 git checkout side &&
60 echo same line | append_cr >>file &&
61 echo same line >>control_file &&
62 git add file control_file &&
63 test_tick &&
64 git commit -m "add line from b" &&
65 git tag b &&
67 git checkout master
70 test_expect_success 'set up fuzz_conflict() helper' '
71 fuzz_conflict() {
72 sed $SED_OPTIONS -e "s/^\([<>=]......\) .*/\1/" "$@"
76 test_expect_success 'Merge after setting text=auto' '
77 cat <<-\EOF >expected &&
78 first line
79 same line
80 EOF
82 if test_have_prereq NATIVE_CRLF; then
83 append_cr <expected >expected.temp &&
84 mv expected.temp expected
85 fi &&
86 git config merge.renormalize true &&
87 git rm -fr . &&
88 rm -f .gitattributes &&
89 git reset --hard a &&
90 git merge b &&
91 compare_files expected file
94 test_expect_success 'Merge addition of text=auto eol=LF' '
95 git config core.eol lf &&
96 cat <<-\EOF >expected &&
97 first line
98 same line
99 EOF
101 git config merge.renormalize true &&
102 git rm -fr . &&
103 rm -f .gitattributes &&
104 git reset --hard b &&
105 git merge a &&
106 compare_files expected file
109 test_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
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
128 test_expect_success 'Detect CRLF/LF conflict after setting text=auto' '
129 git config core.eol native &&
130 echo "<<<<<<<" >expected &&
131 echo first line >>expected &&
132 echo same line >>expected &&
133 echo ======= >>expected &&
134 echo first line | append_cr >>expected &&
135 echo same line | append_cr >>expected &&
136 echo ">>>>>>>" >>expected &&
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 &&
142 compare_files expected file.fuzzy
145 test_expect_success 'Detect LF/CRLF conflict from addition of text=auto' '
146 echo "<<<<<<<" >expected &&
147 echo first line | append_cr >>expected &&
148 echo same line | append_cr >>expected &&
149 echo ======= >>expected &&
150 echo first line >>expected &&
151 echo same line >>expected &&
152 echo ">>>>>>>" >>expected &&
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 &&
158 compare_files expected file.fuzzy
161 test_expect_failure 'checkout -m after setting text=auto' '
162 cat <<-\EOF >expected &&
163 first line
164 same line
167 git config merge.renormalize true &&
168 git rm -fr . &&
169 rm -f .gitattributes &&
170 git reset --hard initial &&
171 git checkout a -- . &&
172 git checkout -m b &&
173 compare_files expected file
176 test_expect_failure 'checkout -m addition of text=auto' '
177 cat <<-\EOF >expected &&
178 first line
179 same line
182 git config merge.renormalize true &&
183 git rm -fr . &&
184 rm -f .gitattributes file &&
185 git reset --hard initial &&
186 git checkout b -- . &&
187 git checkout -m a &&
188 compare_files expected file
191 test_expect_failure 'cherry-pick patch from after text=auto was added' '
192 append_cr <<-\EOF >expected &&
193 first line
194 same line
197 git config merge.renormalize true &&
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 &&
202 compare_files expected file
205 test_expect_success 'Test delete/normalize conflict' '
206 git checkout -f side &&
207 git rm -fr . &&
208 rm -f .gitattributes &&
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
217 test_done