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