blob: da3c81357b8ffee7d6fc3f2d4301e9c3c9d076fd [file] [log] [blame]
Junio C Hamanoc8596002005-06-07 11:36:30 -07001#!/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. ./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"
15compare_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
22check_cache_at () {
Junio C Hamano6973dca2006-04-21 23:57:45 -070023 clean_if_empty=`git-diff-files -- "$1"`
Junio C Hamanoc8596002005-06-07 11:36:30 -070024 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
36test_expect_success \
37 setup \
38 'echo frotz >frotz &&
39 echo nitfol >nitfol &&
40 echo bozbar >bozbar &&
41 echo rezrov >rezrov &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -070042 git-update-index --add nitfol bozbar rezrov &&
Junio C Hamanoc8596002005-06-07 11:36:30 -070043 treeH=`git-write-tree` &&
44 echo treeH $treeH &&
45 git-ls-tree $treeH &&
46
47 echo gnusto >bozbar &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -070048 git-update-index --add frotz bozbar --force-remove rezrov &&
Junio C Hamanoc8596002005-06-07 11:36:30 -070049 git-ls-files --stage >M.out &&
50 treeM=`git-write-tree` &&
51 echo treeM $treeM &&
52 git-ls-tree $treeM &&
Mark Allencebe4032005-06-27 18:40:31 -070053 sum bozbar frotz nitfol >M.sum &&
Junio C Hamanoc8596002005-06-07 11:36:30 -070054 git-diff-tree $treeH $treeM'
55
56test_expect_success \
57 '1, 2, 3 - no carry forward' \
Junio C Hamanofcc387d2006-05-17 01:17:46 -070058 'rm -f .git/index nitfol bozbar rezrov frotz &&
59 git-read-tree --reset -u $treeH &&
Junio C Hamanoc8596002005-06-07 11:36:30 -070060 git-read-tree -m -u $treeH $treeM &&
61 git-ls-files --stage >1-3.out &&
62 cmp M.out 1-3.out &&
Mark Allencebe4032005-06-27 18:40:31 -070063 sum bozbar frotz nitfol >actual3.sum &&
64 cmp M.sum actual3.sum &&
Junio C Hamanoc8596002005-06-07 11:36:30 -070065 check_cache_at bozbar clean &&
66 check_cache_at frotz clean &&
67 check_cache_at nitfol clean'
68
Junio C Hamanoc8596002005-06-07 11:36:30 -070069test_expect_success \
70 '4 - carry forward local addition.' \
Junio C Hamanofcc387d2006-05-17 01:17:46 -070071 'rm -f .git/index nitfol bozbar rezrov frotz &&
72 git-read-tree --reset -u $treeH &&
73 echo "+100644 X 0 yomin" >expected &&
74 echo yomin >yomin &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -070075 git-update-index --add yomin &&
Junio C Hamanoc8596002005-06-07 11:36:30 -070076 git-read-tree -m -u $treeH $treeM &&
Pavel Roskin4d9d62f2005-08-10 23:56:21 -040077 git-ls-files --stage >4.out || return 1
Linus Torvaldsc928c672006-05-25 22:41:02 -070078 diff -U0 M.out 4.out >4diff.out
Junio C Hamanoc8596002005-06-07 11:36:30 -070079 compare_change 4diff.out expected &&
80 check_cache_at yomin clean &&
Mark Allencebe4032005-06-27 18:40:31 -070081 sum bozbar frotz nitfol >actual4.sum &&
82 cmp M.sum actual4.sum &&
Junio C Hamanoc8596002005-06-07 11:36:30 -070083 echo yomin >yomin1 &&
84 diff yomin yomin1 &&
85 rm -f yomin1'
86
87test_expect_success \
88 '5 - carry forward local addition.' \
Junio C Hamanofcc387d2006-05-17 01:17:46 -070089 'rm -f .git/index nitfol bozbar rezrov frotz &&
90 git-read-tree --reset -u $treeH &&
91 git-read-tree -m -u $treeH &&
Junio C Hamanoc8596002005-06-07 11:36:30 -070092 echo yomin >yomin &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -070093 git-update-index --add yomin &&
Junio C Hamanoc8596002005-06-07 11:36:30 -070094 echo yomin yomin >yomin &&
95 git-read-tree -m -u $treeH $treeM &&
Pavel Roskin4d9d62f2005-08-10 23:56:21 -040096 git-ls-files --stage >5.out || return 1
Linus Torvaldsc928c672006-05-25 22:41:02 -070097 diff -U0 M.out 5.out >5diff.out
Junio C Hamanoc8596002005-06-07 11:36:30 -070098 compare_change 5diff.out expected &&
99 check_cache_at yomin dirty &&
Mark Allencebe4032005-06-27 18:40:31 -0700100 sum bozbar frotz nitfol >actual5.sum &&
101 cmp M.sum actual5.sum &&
Junio C Hamano7d95ee92005-06-08 02:08:54 -0700102 : dirty index should have prevented -u from checking it out. &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700103 echo yomin yomin >yomin1 &&
104 diff yomin yomin1 &&
105 rm -f yomin1'
106
107test_expect_success \
108 '6 - local addition already has the same.' \
Junio C Hamanofcc387d2006-05-17 01:17:46 -0700109 'rm -f .git/index nitfol bozbar rezrov frotz &&
110 git-read-tree --reset -u $treeH &&
111 echo frotz >frotz &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700112 git-update-index --add frotz &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700113 git-read-tree -m -u $treeH $treeM &&
114 git-ls-files --stage >6.out &&
Linus Torvaldsc928c672006-05-25 22:41:02 -0700115 diff -U0 M.out 6.out &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700116 check_cache_at frotz clean &&
Mark Allencebe4032005-06-27 18:40:31 -0700117 sum bozbar frotz nitfol >actual3.sum &&
118 cmp M.sum actual3.sum &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700119 echo frotz >frotz1 &&
120 diff frotz frotz1 &&
121 rm -f frotz1'
122
123test_expect_success \
124 '7 - local addition already has the same.' \
Junio C Hamanofcc387d2006-05-17 01:17:46 -0700125 'rm -f .git/index nitfol bozbar rezrov frotz &&
126 git-read-tree --reset -u $treeH &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700127 echo frotz >frotz &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700128 git-update-index --add frotz &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700129 echo frotz frotz >frotz &&
130 git-read-tree -m -u $treeH $treeM &&
131 git-ls-files --stage >7.out &&
Linus Torvaldsc928c672006-05-25 22:41:02 -0700132 diff -U0 M.out 7.out &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700133 check_cache_at frotz dirty &&
Mark Allencebe4032005-06-27 18:40:31 -0700134 sum bozbar frotz nitfol >actual7.sum &&
135 if cmp M.sum actual7.sum; then false; else :; fi &&
Junio C Hamano7d95ee92005-06-08 02:08:54 -0700136 : dirty index should have prevented -u from checking it out. &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700137 echo frotz frotz >frotz1 &&
138 diff frotz frotz1 &&
139 rm -f frotz1'
140
141test_expect_success \
142 '8 - conflicting addition.' \
Junio C Hamanofcc387d2006-05-17 01:17:46 -0700143 'rm -f .git/index nitfol bozbar rezrov frotz &&
144 git-read-tree --reset -u $treeH &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700145 echo frotz frotz >frotz &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700146 git-update-index --add frotz &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700147 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
148
149test_expect_success \
150 '9 - conflicting addition.' \
Junio C Hamanofcc387d2006-05-17 01:17:46 -0700151 'rm -f .git/index nitfol bozbar rezrov frotz &&
152 git-read-tree --reset -u $treeH &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700153 echo frotz frotz >frotz &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700154 git-update-index --add frotz &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700155 echo frotz >frotz &&
156 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
157
158test_expect_success \
159 '10 - path removed.' \
Junio C Hamanofcc387d2006-05-17 01:17:46 -0700160 'rm -f .git/index nitfol bozbar rezrov frotz &&
161 git-read-tree --reset -u $treeH &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700162 echo rezrov >rezrov &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700163 git-update-index --add rezrov &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700164 git-read-tree -m -u $treeH $treeM &&
165 git-ls-files --stage >10.out &&
166 cmp M.out 10.out &&
Mark Allencebe4032005-06-27 18:40:31 -0700167 sum bozbar frotz nitfol >actual10.sum &&
168 cmp M.sum actual10.sum'
Junio C Hamanoc8596002005-06-07 11:36:30 -0700169
170test_expect_success \
171 '11 - dirty path removed.' \
Junio C Hamanofcc387d2006-05-17 01:17:46 -0700172 'rm -f .git/index nitfol bozbar rezrov frotz &&
173 git-read-tree --reset -u $treeH &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700174 echo rezrov >rezrov &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700175 git-update-index --add rezrov &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700176 echo rezrov rezrov >rezrov &&
177 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
178
179test_expect_success \
180 '12 - unmatching local changes being removed.' \
Junio C Hamanofcc387d2006-05-17 01:17:46 -0700181 'rm -f .git/index nitfol bozbar rezrov frotz &&
182 git-read-tree --reset -u $treeH &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700183 echo rezrov rezrov >rezrov &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700184 git-update-index --add rezrov &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700185 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
186
187test_expect_success \
188 '13 - unmatching local changes being removed.' \
Junio C Hamanofcc387d2006-05-17 01:17:46 -0700189 'rm -f .git/index nitfol bozbar rezrov frotz &&
190 git-read-tree --reset -u $treeH &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700191 echo rezrov rezrov >rezrov &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700192 git-update-index --add rezrov &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700193 echo rezrov >rezrov &&
194 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
195
196cat >expected <<EOF
197-100644 X 0 nitfol
198+100644 X 0 nitfol
199EOF
200
201test_expect_success \
202 '14 - unchanged in two heads.' \
Junio C Hamanofcc387d2006-05-17 01:17:46 -0700203 'rm -f .git/index nitfol bozbar rezrov frotz &&
204 git-read-tree --reset -u $treeH &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700205 echo nitfol nitfol >nitfol &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700206 git-update-index --add nitfol &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700207 git-read-tree -m -u $treeH $treeM &&
Pavel Roskin4d9d62f2005-08-10 23:56:21 -0400208 git-ls-files --stage >14.out || return 1
Linus Torvaldsc928c672006-05-25 22:41:02 -0700209 diff -U0 M.out 14.out >14diff.out
Junio C Hamanoc8596002005-06-07 11:36:30 -0700210 compare_change 14diff.out expected &&
Mark Allencebe4032005-06-27 18:40:31 -0700211 sum bozbar frotz >actual14.sum &&
212 grep -v nitfol M.sum > expected14.sum &&
213 cmp expected14.sum actual14.sum &&
214 sum bozbar frotz nitfol >actual14a.sum &&
215 if cmp M.sum actual14a.sum; then false; else :; fi &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700216 check_cache_at nitfol clean &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700217 echo nitfol nitfol >nitfol1 &&
218 diff nitfol nitfol1 &&
219 rm -f nitfol1'
220
221test_expect_success \
222 '15 - unchanged in two heads.' \
Junio C Hamanofcc387d2006-05-17 01:17:46 -0700223 'rm -f .git/index nitfol bozbar rezrov frotz &&
224 git-read-tree --reset -u $treeH &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700225 echo nitfol nitfol >nitfol &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700226 git-update-index --add nitfol &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700227 echo nitfol nitfol nitfol >nitfol &&
228 git-read-tree -m -u $treeH $treeM &&
Pavel Roskin4d9d62f2005-08-10 23:56:21 -0400229 git-ls-files --stage >15.out || return 1
Linus Torvaldsc928c672006-05-25 22:41:02 -0700230 diff -U0 M.out 15.out >15diff.out
Junio C Hamanoc8596002005-06-07 11:36:30 -0700231 compare_change 15diff.out expected &&
232 check_cache_at nitfol dirty &&
Mark Allencebe4032005-06-27 18:40:31 -0700233 sum bozbar frotz >actual15.sum &&
234 grep -v nitfol M.sum > expected15.sum &&
235 cmp expected15.sum actual15.sum &&
236 sum bozbar frotz nitfol >actual15a.sum &&
237 if cmp M.sum actual15a.sum; then false; else :; fi &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700238 echo nitfol nitfol nitfol >nitfol1 &&
239 diff nitfol nitfol1 &&
240 rm -f nitfol1'
241
242test_expect_success \
243 '16 - conflicting local change.' \
Junio C Hamanofcc387d2006-05-17 01:17:46 -0700244 'rm -f .git/index nitfol bozbar rezrov frotz &&
245 git-read-tree --reset -u $treeH &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700246 echo bozbar bozbar >bozbar &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700247 git-update-index --add bozbar &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700248 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
249
250test_expect_success \
251 '17 - conflicting local change.' \
Junio C Hamanofcc387d2006-05-17 01:17:46 -0700252 'rm -f .git/index nitfol bozbar rezrov frotz &&
253 git-read-tree --reset -u $treeH &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700254 echo bozbar bozbar >bozbar &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700255 git-update-index --add bozbar &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700256 echo bozbar bozbar bozbar >bozbar &&
257 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
258
259test_expect_success \
260 '18 - local change already having a good result.' \
Junio C Hamanofcc387d2006-05-17 01:17:46 -0700261 'rm -f .git/index nitfol bozbar rezrov frotz &&
262 git-read-tree --reset -u $treeH &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700263 echo gnusto >bozbar &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700264 git-update-index --add bozbar &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700265 git-read-tree -m -u $treeH $treeM &&
266 git-ls-files --stage >18.out &&
Linus Torvaldsc928c672006-05-25 22:41:02 -0700267 diff -U0 M.out 18.out &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700268 check_cache_at bozbar clean &&
Mark Allencebe4032005-06-27 18:40:31 -0700269 sum bozbar frotz nitfol >actual18.sum &&
270 cmp M.sum actual18.sum'
Junio C Hamanoc8596002005-06-07 11:36:30 -0700271
272test_expect_success \
273 '19 - local change already having a good result, further modified.' \
Junio C Hamanofcc387d2006-05-17 01:17:46 -0700274 'rm -f .git/index nitfol bozbar rezrov frotz &&
275 git-read-tree --reset -u $treeH &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700276 echo gnusto >bozbar &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700277 git-update-index --add bozbar &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700278 echo gnusto gnusto >bozbar &&
279 git-read-tree -m -u $treeH $treeM &&
280 git-ls-files --stage >19.out &&
Linus Torvaldsc928c672006-05-25 22:41:02 -0700281 diff -U0 M.out 19.out &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700282 check_cache_at bozbar dirty &&
Mark Allencebe4032005-06-27 18:40:31 -0700283 sum frotz nitfol >actual19.sum &&
284 grep -v bozbar M.sum > expected19.sum &&
285 cmp expected19.sum actual19.sum &&
286 sum bozbar frotz nitfol >actual19a.sum &&
287 if cmp M.sum actual19a.sum; then false; else :; fi &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700288 echo gnusto gnusto >bozbar1 &&
289 diff bozbar bozbar1 &&
290 rm -f bozbar1'
291
292test_expect_success \
293 '20 - no local change, use new tree.' \
Junio C Hamanofcc387d2006-05-17 01:17:46 -0700294 'rm -f .git/index nitfol bozbar rezrov frotz &&
295 git-read-tree --reset -u $treeH &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700296 echo bozbar >bozbar &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700297 git-update-index --add bozbar &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700298 git-read-tree -m -u $treeH $treeM &&
299 git-ls-files --stage >20.out &&
Linus Torvaldsc928c672006-05-25 22:41:02 -0700300 diff -U0 M.out 20.out &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700301 check_cache_at bozbar clean &&
Mark Allencebe4032005-06-27 18:40:31 -0700302 sum bozbar frotz nitfol >actual20.sum &&
303 cmp M.sum actual20.sum'
Junio C Hamanoc8596002005-06-07 11:36:30 -0700304
305test_expect_success \
306 '21 - no local change, dirty cache.' \
Junio C Hamanofcc387d2006-05-17 01:17:46 -0700307 'rm -f .git/index nitfol bozbar rezrov frotz &&
308 git-read-tree --reset -u $treeH &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700309 echo bozbar >bozbar &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700310 git-update-index --add bozbar &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700311 echo gnusto gnusto >bozbar &&
312 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
313
314# Also make sure we did not break DF vs DF/DF case.
315test_expect_success \
316 'DF vs DF/DF case setup.' \
Junio C Hamanofcc387d2006-05-17 01:17:46 -0700317 'rm -f .git/index
Junio C Hamanoc8596002005-06-07 11:36:30 -0700318 echo DF >DF &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700319 git-update-index --add DF &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700320 treeDF=`git-write-tree` &&
321 echo treeDF $treeDF &&
322 git-ls-tree $treeDF &&
323
324 rm -f DF &&
325 mkdir DF &&
326 echo DF/DF >DF/DF &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700327 git-update-index --add --remove DF DF/DF &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700328 treeDFDF=`git-write-tree` &&
329 echo treeDFDF $treeDFDF &&
330 git-ls-tree $treeDFDF &&
331 git-ls-files --stage >DFDF.out'
332
333test_expect_success \
334 'DF vs DF/DF case test.' \
335 'rm -f .git/index &&
336 rm -fr DF &&
337 echo DF >DF &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700338 git-update-index --add DF &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700339 git-read-tree -m -u $treeDF $treeDFDF &&
340 git-ls-files --stage >DFDFcheck.out &&
Linus Torvaldsc928c672006-05-25 22:41:02 -0700341 diff -U0 DFDF.out DFDFcheck.out &&
Junio C Hamanoc8596002005-06-07 11:36:30 -0700342 check_cache_at DF/DF clean'
343
344test_done