3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='Two way merge with read-tree -m -u $H $M
8 This is identical to t1001, but uses -u to update the work tree as well.
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"
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
23 clean_if_empty
=`git-diff-files "$1"`
24 case "$clean_if_empty" in
25 '') echo "$1: clean" ;;
26 ?
*) echo "$1: dirty" ;;
28 case "$2,$clean_if_empty" in
39 echo nitfol >nitfol &&
40 echo bozbar >bozbar &&
41 echo rezrov >rezrov &&
43 git-update-index --add nitfol bozbar rezrov &&
44 treeH=`git-write-tree` &&
48 echo gnusto >bozbar &&
49 git-update-index --add frotz bozbar --force-remove rezrov &&
50 git-ls-files --stage >M.out &&
51 treeM=`git-write-tree` &&
54 sum bozbar frotz nitfol >M.sum &&
55 git-diff-tree $treeH $treeM'
58 '1, 2, 3 - no carry forward' \
60 git-read-tree -m -u $treeH $treeM &&
61 git-ls-files --stage >1-3.out &&
63 sum bozbar frotz nitfol >actual3.sum &&
64 cmp M.sum actual3.sum &&
65 check_cache_at bozbar clean &&
66 check_cache_at frotz clean &&
67 check_cache_at nitfol clean'
69 echo '+100644 X 0 yomin' >expected
72 '4 - carry forward local addition.' \
74 git-update-index --add yomin &&
75 git-read-tree -m -u $treeH $treeM &&
76 git-ls-files --stage >4.out || return 1
77 diff --unified=0 M.out 4.out >4diff.out
78 compare_change 4diff.out expected &&
79 check_cache_at yomin clean &&
80 sum bozbar frotz nitfol >actual4.sum &&
81 cmp M.sum actual4.sum &&
87 '5 - carry forward local addition.' \
90 git-update-index --add yomin &&
91 echo yomin yomin >yomin &&
92 git-read-tree -m -u $treeH $treeM &&
93 git-ls-files --stage >5.out || return 1
94 diff --unified=0 M.out 5.out >5diff.out
95 compare_change 5diff.out expected &&
96 check_cache_at yomin dirty &&
97 sum bozbar frotz nitfol >actual5.sum &&
98 cmp M.sum actual5.sum &&
99 : dirty index should have prevented -u from checking it out. &&
100 echo yomin yomin >yomin1 &&
104 test_expect_success \
105 '6 - local addition already has the same.' \
107 git-update-index --add frotz &&
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 &&
112 sum bozbar frotz nitfol >actual3.sum &&
113 cmp M.sum actual3.sum &&
114 echo frotz >frotz1 &&
118 test_expect_success \
119 '7 - local addition already has the same.' \
122 git-update-index --add frotz &&
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 &&
128 sum bozbar frotz nitfol >actual7.sum &&
129 if cmp M.sum actual7.sum; then false; else :; fi &&
130 : dirty index should have prevented -u from checking it out. &&
131 echo frotz frotz >frotz1 &&
135 test_expect_success \
136 '8 - conflicting addition.' \
138 echo frotz frotz >frotz &&
139 git-update-index --add frotz &&
140 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
142 test_expect_success \
143 '9 - conflicting addition.' \
145 echo frotz frotz >frotz &&
146 git-update-index --add frotz &&
148 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
150 test_expect_success \
151 '10 - path removed.' \
153 echo rezrov >rezrov &&
154 git-update-index --add rezrov &&
155 git-read-tree -m -u $treeH $treeM &&
156 git-ls-files --stage >10.out &&
158 sum bozbar frotz nitfol >actual10.sum &&
159 cmp M.sum actual10.sum'
161 test_expect_success \
162 '11 - dirty path removed.' \
164 echo rezrov >rezrov &&
165 git-update-index --add rezrov &&
166 echo rezrov rezrov >rezrov &&
167 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
169 test_expect_success \
170 '12 - unmatching local changes being removed.' \
172 echo rezrov rezrov >rezrov &&
173 git-update-index --add rezrov &&
174 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
176 test_expect_success \
177 '13 - unmatching local changes being removed.' \
179 echo rezrov rezrov >rezrov &&
180 git-update-index --add rezrov &&
181 echo rezrov >rezrov &&
182 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
189 test_expect_success \
190 '14 - unchanged in two heads.' \
192 echo nitfol nitfol >nitfol &&
193 git-update-index --add nitfol &&
194 git-read-tree -m -u $treeH $treeM &&
195 git-ls-files --stage >14.out || return 1
196 diff --unified=0 M.out 14.out >14diff.out
197 compare_change 14diff.out expected &&
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 &&
203 check_cache_at nitfol clean &&
204 echo nitfol nitfol >nitfol1 &&
205 diff nitfol nitfol1 &&
208 test_expect_success \
209 '15 - unchanged in two heads.' \
211 echo nitfol nitfol >nitfol &&
212 git-update-index --add nitfol &&
213 echo nitfol nitfol nitfol >nitfol &&
214 git-read-tree -m -u $treeH $treeM &&
215 git-ls-files --stage >15.out || return 1
216 diff --unified=0 M.out 15.out >15diff.out
217 compare_change 15diff.out expected &&
218 check_cache_at nitfol dirty &&
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 &&
224 echo nitfol nitfol nitfol >nitfol1 &&
225 diff nitfol nitfol1 &&
228 test_expect_success \
229 '16 - conflicting local change.' \
231 echo bozbar bozbar >bozbar &&
232 git-update-index --add bozbar &&
233 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
235 test_expect_success \
236 '17 - conflicting local change.' \
238 echo bozbar bozbar >bozbar &&
239 git-update-index --add bozbar &&
240 echo bozbar bozbar bozbar >bozbar &&
241 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
243 test_expect_success \
244 '18 - local change already having a good result.' \
246 echo gnusto >bozbar &&
247 git-update-index --add bozbar &&
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 &&
252 sum bozbar frotz nitfol >actual18.sum &&
253 cmp M.sum actual18.sum'
255 test_expect_success \
256 '19 - local change already having a good result, further modified.' \
258 echo gnusto >bozbar &&
259 git-update-index --add bozbar &&
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 &&
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 &&
270 echo gnusto gnusto >bozbar1 &&
271 diff bozbar bozbar1 &&
274 test_expect_success \
275 '20 - no local change, use new tree.' \
277 echo bozbar >bozbar &&
278 git-update-index --add bozbar &&
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 &&
283 sum bozbar frotz nitfol >actual20.sum &&
284 cmp M.sum actual20.sum'
286 test_expect_success \
287 '21 - no local change, dirty cache.' \
289 echo bozbar >bozbar &&
290 git-update-index --add bozbar &&
291 echo gnusto gnusto >bozbar &&
292 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
294 # Also make sure we did not break DF vs DF/DF case.
295 test_expect_success \
296 'DF vs DF/DF case setup.' \
299 git-update-index --add DF &&
300 treeDF=`git-write-tree` &&
301 echo treeDF $treeDF &&
302 git-ls-tree $treeDF &&
307 git-update-index --add --remove DF DF/DF &&
308 treeDFDF=`git-write-tree` &&
309 echo treeDFDF $treeDFDF &&
310 git-ls-tree $treeDFDF &&
311 git-ls-files --stage >DFDF.out'
313 test_expect_success \
314 'DF vs DF/DF case test.' \
318 git-update-index --add DF &&
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'