]>
Commit | Line | Data |
---|---|---|
c8596009 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
6 | test_description='Two way merge with read-tree -m -u $H $M | |
7 | ||
8 | This is identical to t1001, but uses -u to update the work tree as well. | |
9 | ||
10 | ' | |
11 | . ./test-lib.sh | |
12 | ||
13 | _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' | |
14 | _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40" | |
15 | compare_change () { | |
16 | sed >current \ | |
17 | -e '/^--- /d; /^+++ /d; /^@@ /d;' \ | |
18 | -e 's/^\(.[0-7][0-7][0-7][0-7][0-7][0-7]\) '"$_x40"' /\1 X /' "$1" | |
19 | diff -u expected current | |
20 | } | |
21 | ||
22 | check_cache_at () { | |
23 | clean_if_empty=`git-diff-files "$1"` | |
24 | case "$clean_if_empty" in | |
25 | '') echo "$1: clean" ;; | |
26 | ?*) echo "$1: dirty" ;; | |
27 | esac | |
28 | case "$2,$clean_if_empty" in | |
29 | clean,) : ;; | |
30 | clean,?*) false ;; | |
31 | dirty,) false ;; | |
32 | dirty,?*) : ;; | |
33 | esac | |
34 | } | |
35 | ||
36 | test_expect_success \ | |
37 | setup \ | |
38 | 'echo frotz >frotz && | |
39 | echo nitfol >nitfol && | |
40 | echo bozbar >bozbar && | |
41 | echo rezrov >rezrov && | |
42 | echo yomin >yomin && | |
215a7ad1 | 43 | git-update-index --add nitfol bozbar rezrov && |
c8596009 JH |
44 | treeH=`git-write-tree` && |
45 | echo treeH $treeH && | |
46 | git-ls-tree $treeH && | |
47 | ||
48 | echo gnusto >bozbar && | |
215a7ad1 | 49 | git-update-index --add frotz bozbar --force-remove rezrov && |
c8596009 JH |
50 | git-ls-files --stage >M.out && |
51 | treeM=`git-write-tree` && | |
52 | echo treeM $treeM && | |
53 | git-ls-tree $treeM && | |
cebe403b | 54 | sum bozbar frotz nitfol >M.sum && |
c8596009 JH |
55 | git-diff-tree $treeH $treeM' |
56 | ||
57 | test_expect_success \ | |
58 | '1, 2, 3 - no carry forward' \ | |
59 | 'rm -f .git/index && | |
60 | git-read-tree -m -u $treeH $treeM && | |
61 | git-ls-files --stage >1-3.out && | |
62 | cmp M.out 1-3.out && | |
cebe403b MA |
63 | sum bozbar frotz nitfol >actual3.sum && |
64 | cmp M.sum actual3.sum && | |
c8596009 JH |
65 | check_cache_at bozbar clean && |
66 | check_cache_at frotz clean && | |
67 | check_cache_at nitfol clean' | |
68 | ||
69 | echo '+100644 X 0 yomin' >expected | |
70 | ||
71 | test_expect_success \ | |
72 | '4 - carry forward local addition.' \ | |
73 | 'rm -f .git/index && | |
215a7ad1 | 74 | git-update-index --add yomin && |
c8596009 | 75 | git-read-tree -m -u $treeH $treeM && |
4d9d62fa | 76 | git-ls-files --stage >4.out || return 1 |
c8596009 JH |
77 | diff --unified=0 M.out 4.out >4diff.out |
78 | compare_change 4diff.out expected && | |
79 | check_cache_at yomin clean && | |
cebe403b MA |
80 | sum bozbar frotz nitfol >actual4.sum && |
81 | cmp M.sum actual4.sum && | |
c8596009 JH |
82 | echo yomin >yomin1 && |
83 | diff yomin yomin1 && | |
84 | rm -f yomin1' | |
85 | ||
86 | test_expect_success \ | |
87 | '5 - carry forward local addition.' \ | |
88 | 'rm -f .git/index && | |
89 | echo yomin >yomin && | |
215a7ad1 | 90 | git-update-index --add yomin && |
c8596009 JH |
91 | echo yomin yomin >yomin && |
92 | git-read-tree -m -u $treeH $treeM && | |
4d9d62fa | 93 | git-ls-files --stage >5.out || return 1 |
c8596009 JH |
94 | diff --unified=0 M.out 5.out >5diff.out |
95 | compare_change 5diff.out expected && | |
96 | check_cache_at yomin dirty && | |
cebe403b MA |
97 | sum bozbar frotz nitfol >actual5.sum && |
98 | cmp M.sum actual5.sum && | |
7d95ee93 | 99 | : dirty index should have prevented -u from checking it out. && |
c8596009 JH |
100 | echo yomin yomin >yomin1 && |
101 | diff yomin yomin1 && | |
102 | rm -f yomin1' | |
103 | ||
104 | test_expect_success \ | |
105 | '6 - local addition already has the same.' \ | |
106 | 'rm -f .git/index && | |
215a7ad1 | 107 | git-update-index --add frotz && |
c8596009 JH |
108 | git-read-tree -m -u $treeH $treeM && |
109 | git-ls-files --stage >6.out && | |
110 | diff --unified=0 M.out 6.out && | |
111 | check_cache_at frotz clean && | |
cebe403b MA |
112 | sum bozbar frotz nitfol >actual3.sum && |
113 | cmp M.sum actual3.sum && | |
c8596009 JH |
114 | echo frotz >frotz1 && |
115 | diff frotz frotz1 && | |
116 | rm -f frotz1' | |
117 | ||
118 | test_expect_success \ | |
119 | '7 - local addition already has the same.' \ | |
120 | 'rm -f .git/index && | |
121 | echo frotz >frotz && | |
215a7ad1 | 122 | git-update-index --add frotz && |
c8596009 JH |
123 | echo frotz frotz >frotz && |
124 | git-read-tree -m -u $treeH $treeM && | |
125 | git-ls-files --stage >7.out && | |
126 | diff --unified=0 M.out 7.out && | |
127 | check_cache_at frotz dirty && | |
cebe403b MA |
128 | sum bozbar frotz nitfol >actual7.sum && |
129 | if cmp M.sum actual7.sum; then false; else :; fi && | |
7d95ee93 | 130 | : dirty index should have prevented -u from checking it out. && |
c8596009 JH |
131 | echo frotz frotz >frotz1 && |
132 | diff frotz frotz1 && | |
133 | rm -f frotz1' | |
134 | ||
135 | test_expect_success \ | |
136 | '8 - conflicting addition.' \ | |
137 | 'rm -f .git/index && | |
138 | echo frotz frotz >frotz && | |
215a7ad1 | 139 | git-update-index --add frotz && |
c8596009 JH |
140 | if git-read-tree -m -u $treeH $treeM; then false; else :; fi' |
141 | ||
142 | test_expect_success \ | |
143 | '9 - conflicting addition.' \ | |
144 | 'rm -f .git/index && | |
145 | echo frotz frotz >frotz && | |
215a7ad1 | 146 | git-update-index --add frotz && |
c8596009 JH |
147 | echo frotz >frotz && |
148 | if git-read-tree -m -u $treeH $treeM; then false; else :; fi' | |
149 | ||
150 | test_expect_success \ | |
151 | '10 - path removed.' \ | |
152 | 'rm -f .git/index && | |
153 | echo rezrov >rezrov && | |
215a7ad1 | 154 | git-update-index --add rezrov && |
c8596009 JH |
155 | git-read-tree -m -u $treeH $treeM && |
156 | git-ls-files --stage >10.out && | |
157 | cmp M.out 10.out && | |
cebe403b MA |
158 | sum bozbar frotz nitfol >actual10.sum && |
159 | cmp M.sum actual10.sum' | |
c8596009 JH |
160 | |
161 | test_expect_success \ | |
162 | '11 - dirty path removed.' \ | |
163 | 'rm -f .git/index && | |
164 | echo rezrov >rezrov && | |
215a7ad1 | 165 | git-update-index --add rezrov && |
c8596009 JH |
166 | echo rezrov rezrov >rezrov && |
167 | if git-read-tree -m -u $treeH $treeM; then false; else :; fi' | |
168 | ||
169 | test_expect_success \ | |
170 | '12 - unmatching local changes being removed.' \ | |
171 | 'rm -f .git/index && | |
172 | echo rezrov rezrov >rezrov && | |
215a7ad1 | 173 | git-update-index --add rezrov && |
c8596009 JH |
174 | if git-read-tree -m -u $treeH $treeM; then false; else :; fi' |
175 | ||
176 | test_expect_success \ | |
177 | '13 - unmatching local changes being removed.' \ | |
178 | 'rm -f .git/index && | |
179 | echo rezrov rezrov >rezrov && | |
215a7ad1 | 180 | git-update-index --add rezrov && |
c8596009 JH |
181 | echo rezrov >rezrov && |
182 | if git-read-tree -m -u $treeH $treeM; then false; else :; fi' | |
183 | ||
184 | cat >expected <<EOF | |
185 | -100644 X 0 nitfol | |
186 | +100644 X 0 nitfol | |
187 | EOF | |
188 | ||
189 | test_expect_success \ | |
190 | '14 - unchanged in two heads.' \ | |
191 | 'rm -f .git/index && | |
192 | echo nitfol nitfol >nitfol && | |
215a7ad1 | 193 | git-update-index --add nitfol && |
c8596009 | 194 | git-read-tree -m -u $treeH $treeM && |
4d9d62fa | 195 | git-ls-files --stage >14.out || return 1 |
c8596009 JH |
196 | diff --unified=0 M.out 14.out >14diff.out |
197 | compare_change 14diff.out expected && | |
cebe403b MA |
198 | sum bozbar frotz >actual14.sum && |
199 | grep -v nitfol M.sum > expected14.sum && | |
200 | cmp expected14.sum actual14.sum && | |
201 | sum bozbar frotz nitfol >actual14a.sum && | |
202 | if cmp M.sum actual14a.sum; then false; else :; fi && | |
c8596009 | 203 | check_cache_at nitfol clean && |
c8596009 JH |
204 | echo nitfol nitfol >nitfol1 && |
205 | diff nitfol nitfol1 && | |
206 | rm -f nitfol1' | |
207 | ||
208 | test_expect_success \ | |
209 | '15 - unchanged in two heads.' \ | |
210 | 'rm -f .git/index && | |
211 | echo nitfol nitfol >nitfol && | |
215a7ad1 | 212 | git-update-index --add nitfol && |
c8596009 JH |
213 | echo nitfol nitfol nitfol >nitfol && |
214 | git-read-tree -m -u $treeH $treeM && | |
4d9d62fa | 215 | git-ls-files --stage >15.out || return 1 |
c8596009 JH |
216 | diff --unified=0 M.out 15.out >15diff.out |
217 | compare_change 15diff.out expected && | |
218 | check_cache_at nitfol dirty && | |
cebe403b MA |
219 | sum bozbar frotz >actual15.sum && |
220 | grep -v nitfol M.sum > expected15.sum && | |
221 | cmp expected15.sum actual15.sum && | |
222 | sum bozbar frotz nitfol >actual15a.sum && | |
223 | if cmp M.sum actual15a.sum; then false; else :; fi && | |
c8596009 JH |
224 | echo nitfol nitfol nitfol >nitfol1 && |
225 | diff nitfol nitfol1 && | |
226 | rm -f nitfol1' | |
227 | ||
228 | test_expect_success \ | |
229 | '16 - conflicting local change.' \ | |
230 | 'rm -f .git/index && | |
231 | echo bozbar bozbar >bozbar && | |
215a7ad1 | 232 | git-update-index --add bozbar && |
c8596009 JH |
233 | if git-read-tree -m -u $treeH $treeM; then false; else :; fi' |
234 | ||
235 | test_expect_success \ | |
236 | '17 - conflicting local change.' \ | |
237 | 'rm -f .git/index && | |
238 | echo bozbar bozbar >bozbar && | |
215a7ad1 | 239 | git-update-index --add bozbar && |
c8596009 JH |
240 | echo bozbar bozbar bozbar >bozbar && |
241 | if git-read-tree -m -u $treeH $treeM; then false; else :; fi' | |
242 | ||
243 | test_expect_success \ | |
244 | '18 - local change already having a good result.' \ | |
245 | 'rm -f .git/index && | |
246 | echo gnusto >bozbar && | |
215a7ad1 | 247 | git-update-index --add bozbar && |
c8596009 JH |
248 | git-read-tree -m -u $treeH $treeM && |
249 | git-ls-files --stage >18.out && | |
250 | diff --unified=0 M.out 18.out && | |
251 | check_cache_at bozbar clean && | |
cebe403b MA |
252 | sum bozbar frotz nitfol >actual18.sum && |
253 | cmp M.sum actual18.sum' | |
c8596009 JH |
254 | |
255 | test_expect_success \ | |
256 | '19 - local change already having a good result, further modified.' \ | |
257 | 'rm -f .git/index && | |
258 | echo gnusto >bozbar && | |
215a7ad1 | 259 | git-update-index --add bozbar && |
c8596009 JH |
260 | echo gnusto gnusto >bozbar && |
261 | git-read-tree -m -u $treeH $treeM && | |
262 | git-ls-files --stage >19.out && | |
263 | diff --unified=0 M.out 19.out && | |
264 | check_cache_at bozbar dirty && | |
cebe403b MA |
265 | sum frotz nitfol >actual19.sum && |
266 | grep -v bozbar M.sum > expected19.sum && | |
267 | cmp expected19.sum actual19.sum && | |
268 | sum bozbar frotz nitfol >actual19a.sum && | |
269 | if cmp M.sum actual19a.sum; then false; else :; fi && | |
c8596009 JH |
270 | echo gnusto gnusto >bozbar1 && |
271 | diff bozbar bozbar1 && | |
272 | rm -f bozbar1' | |
273 | ||
274 | test_expect_success \ | |
275 | '20 - no local change, use new tree.' \ | |
276 | 'rm -f .git/index && | |
277 | echo bozbar >bozbar && | |
215a7ad1 | 278 | git-update-index --add bozbar && |
c8596009 JH |
279 | git-read-tree -m -u $treeH $treeM && |
280 | git-ls-files --stage >20.out && | |
281 | diff --unified=0 M.out 20.out && | |
282 | check_cache_at bozbar clean && | |
cebe403b MA |
283 | sum bozbar frotz nitfol >actual20.sum && |
284 | cmp M.sum actual20.sum' | |
c8596009 JH |
285 | |
286 | test_expect_success \ | |
287 | '21 - no local change, dirty cache.' \ | |
288 | 'rm -f .git/index && | |
289 | echo bozbar >bozbar && | |
215a7ad1 | 290 | git-update-index --add bozbar && |
c8596009 JH |
291 | echo gnusto gnusto >bozbar && |
292 | if git-read-tree -m -u $treeH $treeM; then false; else :; fi' | |
293 | ||
294 | # Also make sure we did not break DF vs DF/DF case. | |
295 | test_expect_success \ | |
296 | 'DF vs DF/DF case setup.' \ | |
297 | 'rm -f .git/index && | |
298 | echo DF >DF && | |
215a7ad1 | 299 | git-update-index --add DF && |
c8596009 JH |
300 | treeDF=`git-write-tree` && |
301 | echo treeDF $treeDF && | |
302 | git-ls-tree $treeDF && | |
303 | ||
304 | rm -f DF && | |
305 | mkdir DF && | |
306 | echo DF/DF >DF/DF && | |
215a7ad1 | 307 | git-update-index --add --remove DF DF/DF && |
c8596009 JH |
308 | treeDFDF=`git-write-tree` && |
309 | echo treeDFDF $treeDFDF && | |
310 | git-ls-tree $treeDFDF && | |
311 | git-ls-files --stage >DFDF.out' | |
312 | ||
313 | test_expect_success \ | |
314 | 'DF vs DF/DF case test.' \ | |
315 | 'rm -f .git/index && | |
316 | rm -fr DF && | |
317 | echo DF >DF && | |
215a7ad1 | 318 | git-update-index --add DF && |
c8596009 JH |
319 | git-read-tree -m -u $treeDF $treeDFDF && |
320 | git-ls-files --stage >DFDFcheck.out && | |
321 | diff --unified=0 DFDF.out DFDFcheck.out && | |
322 | check_cache_at DF/DF clean' | |
323 | ||
324 | test_done |