Merge branch 't/config/owner-link' into refs/top-bases/gitweb-additions
[git/gitweb.git] / t / t6038-merge-text-auto.sh
blob85c10b0940a896bb49aefee9a2885b1c39217bab
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 test_expect_success setup '
20 git config core.autocrlf false &&
22 echo first line | append_cr >file &&
23 echo first line >control_file &&
24 echo only line >inert_file &&
26 git add file control_file inert_file &&
27 test_tick &&
28 git commit -m "Initial" &&
29 git tag initial &&
30 git branch side &&
32 echo "* text=auto" >.gitattributes &&
33 touch file &&
34 git add .gitattributes file &&
35 test_tick &&
36 git commit -m "normalize file" &&
38 echo same line | append_cr >>file &&
39 echo same line >>control_file &&
40 git add file control_file &&
41 test_tick &&
42 git commit -m "add line from a" &&
43 git tag a &&
45 git rm .gitattributes &&
46 rm file &&
47 git checkout file &&
48 test_tick &&
49 git commit -m "remove .gitattributes" &&
50 git tag c &&
52 git checkout side &&
53 echo same line | append_cr >>file &&
54 echo same line >>control_file &&
55 git add file control_file &&
56 test_tick &&
57 git commit -m "add line from b" &&
58 git tag b &&
60 git checkout master
63 test_expect_success 'set up fuzz_conflict() helper' '
64 fuzz_conflict() {
65 sed $SED_OPTIONS -e "s/^\([<>=]......\) .*/\1/" "$@"
69 test_expect_success 'Merge after setting text=auto' '
70 cat <<-\EOF >expected &&
71 first line
72 same line
73 EOF
75 if test_have_prereq NATIVE_CRLF; then
76 append_cr <expected >expected.temp &&
77 mv expected.temp expected
78 fi &&
79 git config merge.renormalize true &&
80 git rm -fr . &&
81 rm -f .gitattributes &&
82 git reset --hard a &&
83 git merge b &&
84 test_cmp expected file
87 test_expect_success 'Merge addition of text=auto' '
88 cat <<-\EOF >expected &&
89 first line
90 same line
91 EOF
93 if test_have_prereq NATIVE_CRLF; then
94 append_cr <expected >expected.temp &&
95 mv expected.temp expected
96 fi &&
97 git config merge.renormalize true &&
98 git rm -fr . &&
99 rm -f .gitattributes &&
100 git reset --hard b &&
101 git merge a &&
102 test_cmp expected file
105 test_expect_success 'Detect CRLF/LF conflict after setting text=auto' '
106 echo "<<<<<<<" >expected &&
107 if test_have_prereq NATIVE_CRLF; then
108 echo first line | append_cr >>expected &&
109 echo same line | append_cr >>expected &&
110 echo ======= | append_cr >>expected
111 else
112 echo first line >>expected &&
113 echo same line >>expected &&
114 echo ======= >>expected
115 fi &&
116 echo first line | append_cr >>expected &&
117 echo same line | append_cr >>expected &&
118 echo ">>>>>>>" >>expected &&
119 git config merge.renormalize false &&
120 rm -f .gitattributes &&
121 git reset --hard a &&
122 test_must_fail git merge b &&
123 fuzz_conflict file >file.fuzzy &&
124 test_cmp expected file.fuzzy
127 test_expect_success 'Detect LF/CRLF conflict from addition of text=auto' '
128 echo "<<<<<<<" >expected &&
129 echo first line | append_cr >>expected &&
130 echo same line | append_cr >>expected &&
131 if test_have_prereq NATIVE_CRLF; then
132 echo ======= | append_cr >>expected &&
133 echo first line | append_cr >>expected &&
134 echo same line | append_cr >>expected
135 else
136 echo ======= >>expected &&
137 echo first line >>expected &&
138 echo same line >>expected
139 fi &&
140 echo ">>>>>>>" >>expected &&
141 git config merge.renormalize false &&
142 rm -f .gitattributes &&
143 git reset --hard b &&
144 test_must_fail git merge a &&
145 fuzz_conflict file >file.fuzzy &&
146 test_cmp expected file.fuzzy
149 test_expect_failure 'checkout -m after setting text=auto' '
150 cat <<-\EOF >expected &&
151 first line
152 same line
155 git config merge.renormalize true &&
156 git rm -fr . &&
157 rm -f .gitattributes &&
158 git reset --hard initial &&
159 git checkout a -- . &&
160 git checkout -m b &&
161 test_cmp expected file
164 test_expect_failure 'checkout -m addition of text=auto' '
165 cat <<-\EOF >expected &&
166 first line
167 same line
170 git config merge.renormalize true &&
171 git rm -fr . &&
172 rm -f .gitattributes file &&
173 git reset --hard initial &&
174 git checkout b -- . &&
175 git checkout -m a &&
176 test_cmp expected file
179 test_expect_failure 'cherry-pick patch from after text=auto was added' '
180 append_cr <<-\EOF >expected &&
181 first line
182 same line
185 git config merge.renormalize true &&
186 git rm -fr . &&
187 git reset --hard b &&
188 test_must_fail git cherry-pick a >err 2>&1 &&
189 grep "[Nn]othing added" err &&
190 test_cmp expected file
193 test_expect_success 'Test delete/normalize conflict' '
194 git checkout -f side &&
195 git rm -fr . &&
196 rm -f .gitattributes &&
197 git reset --hard initial &&
198 git rm file &&
199 git commit -m "remove file" &&
200 git checkout master &&
201 git reset --hard a^ &&
202 git merge side
205 test_done