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