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