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-cache --add nitfol bozbar rezrov &&
44 treeH=`git-write-tree` &&
48 echo gnusto >bozbar &&
49 git-update-cache --add frotz bozbar --force-remove rezrov &&
50 git-ls-files --stage >M.out &&
51 treeM=`git-write-tree` &&
54 sha1sum bozbar frotz nitfol >M.sha1 &&
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 &&
64 check_cache_at bozbar clean &&
65 check_cache_at frotz clean &&
66 check_cache_at nitfol clean'
68 echo '+100644 X 0 yomin' >expected
71 '4 - carry forward local addition.' \
73 git-update-cache --add yomin &&
74 git-read-tree -m -u $treeH $treeM &&
75 git-ls-files --stage >4.out || exit
76 diff --unified=0 M.out 4.out >4diff.out
77 compare_change 4diff.out expected &&
78 check_cache_at yomin clean &&
85 '5 - carry forward local addition.' \
88 git-update-cache --add yomin &&
89 echo yomin yomin >yomin &&
90 git-read-tree -m -u $treeH $treeM &&
91 git-ls-files --stage >5.out || exit
92 diff --unified=0 M.out 5.out >5diff.out
93 compare_change 5diff.out expected &&
94 check_cache_at yomin dirty &&
96 : dirty index should have prevented -u from checking it out. &&
97 echo yomin yomin >yomin1 &&
101 test_expect_success \
102 '6 - local addition already has the same.' \
104 git-update-cache --add frotz &&
105 git-read-tree -m -u $treeH $treeM &&
106 git-ls-files --stage >6.out &&
107 diff --unified=0 M.out 6.out &&
108 check_cache_at frotz clean &&
110 echo frotz >frotz1 &&
114 test_expect_success \
115 '7 - local addition already has the same.' \
118 git-update-cache --add frotz &&
119 echo frotz frotz >frotz &&
120 git-read-tree -m -u $treeH $treeM &&
121 git-ls-files --stage >7.out &&
122 diff --unified=0 M.out 7.out &&
123 check_cache_at frotz dirty &&
124 if sha1sum -c M.sha1; then false; else :; fi &&
125 : dirty index should have prevented -u from checking it out. &&
126 echo frotz frotz >frotz1 &&
130 test_expect_success \
131 '8 - conflicting addition.' \
133 echo frotz frotz >frotz &&
134 git-update-cache --add frotz &&
135 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
137 test_expect_success \
138 '9 - conflicting addition.' \
140 echo frotz frotz >frotz &&
141 git-update-cache --add frotz &&
143 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
145 test_expect_success \
146 '10 - path removed.' \
148 echo rezrov >rezrov &&
149 git-update-cache --add rezrov &&
150 git-read-tree -m -u $treeH $treeM &&
151 git-ls-files --stage >10.out &&
155 test_expect_success \
156 '11 - dirty path removed.' \
158 echo rezrov >rezrov &&
159 git-update-cache --add rezrov &&
160 echo rezrov rezrov >rezrov &&
161 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
163 test_expect_success \
164 '12 - unmatching local changes being removed.' \
166 echo rezrov rezrov >rezrov &&
167 git-update-cache --add rezrov &&
168 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
170 test_expect_success \
171 '13 - unmatching local changes being removed.' \
173 echo rezrov rezrov >rezrov &&
174 git-update-cache --add rezrov &&
175 echo rezrov >rezrov &&
176 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
183 test_expect_success \
184 '14 - unchanged in two heads.' \
186 echo nitfol nitfol >nitfol &&
187 git-update-cache --add nitfol &&
188 git-read-tree -m -u $treeH $treeM &&
189 git-ls-files --stage >14.out || exit
190 diff --unified=0 M.out 14.out >14diff.out
191 compare_change 14diff.out expected &&
192 check_cache_at nitfol clean &&
193 grep -v nitfol M.sha1 | sha1sum -c &&
194 if sha1sum -c M.sha1; then false; else :; fi &&
195 echo nitfol nitfol >nitfol1 &&
196 diff nitfol nitfol1 &&
199 test_expect_success \
200 '15 - unchanged in two heads.' \
202 echo nitfol nitfol >nitfol &&
203 git-update-cache --add nitfol &&
204 echo nitfol nitfol nitfol >nitfol &&
205 git-read-tree -m -u $treeH $treeM &&
206 git-ls-files --stage >15.out || exit
207 diff --unified=0 M.out 15.out >15diff.out
208 compare_change 15diff.out expected &&
209 check_cache_at nitfol dirty &&
210 grep -v nitfol M.sha1 | sha1sum -c &&
211 if sha1sum -c M.sha1; then false; else :; fi &&
212 echo nitfol nitfol nitfol >nitfol1 &&
213 diff nitfol nitfol1 &&
216 test_expect_success \
217 '16 - conflicting local change.' \
219 echo bozbar bozbar >bozbar &&
220 git-update-cache --add bozbar &&
221 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
223 test_expect_success \
224 '17 - conflicting local change.' \
226 echo bozbar bozbar >bozbar &&
227 git-update-cache --add bozbar &&
228 echo bozbar bozbar bozbar >bozbar &&
229 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
231 test_expect_success \
232 '18 - local change already having a good result.' \
234 echo gnusto >bozbar &&
235 git-update-cache --add bozbar &&
236 git-read-tree -m -u $treeH $treeM &&
237 git-ls-files --stage >18.out &&
238 diff --unified=0 M.out 18.out &&
239 check_cache_at bozbar clean &&
242 test_expect_success \
243 '19 - local change already having a good result, further modified.' \
245 echo gnusto >bozbar &&
246 git-update-cache --add bozbar &&
247 echo gnusto gnusto >bozbar &&
248 git-read-tree -m -u $treeH $treeM &&
249 git-ls-files --stage >19.out &&
250 diff --unified=0 M.out 19.out &&
251 check_cache_at bozbar dirty &&
252 grep -v bozbar M.sha1 | sha1sum -c &&
253 if sha1sum -c M.sha1; then false; else :; fi &&
254 echo gnusto gnusto >bozbar1 &&
255 diff bozbar bozbar1 &&
258 test_expect_success \
259 '20 - no local change, use new tree.' \
261 echo bozbar >bozbar &&
262 git-update-cache --add bozbar &&
263 git-read-tree -m -u $treeH $treeM &&
264 git-ls-files --stage >20.out &&
265 diff --unified=0 M.out 20.out &&
266 check_cache_at bozbar clean &&
269 test_expect_success \
270 '21 - no local change, dirty cache.' \
272 echo bozbar >bozbar &&
273 git-update-cache --add bozbar &&
274 echo gnusto gnusto >bozbar &&
275 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
277 # Also make sure we did not break DF vs DF/DF case.
278 test_expect_success \
279 'DF vs DF/DF case setup.' \
282 git-update-cache --add DF &&
283 treeDF=`git-write-tree` &&
284 echo treeDF $treeDF &&
285 git-ls-tree $treeDF &&
290 git-update-cache --add --remove DF DF/DF &&
291 treeDFDF=`git-write-tree` &&
292 echo treeDFDF $treeDFDF &&
293 git-ls-tree $treeDFDF &&
294 git-ls-files --stage >DFDF.out'
296 test_expect_success \
297 'DF vs DF/DF case test.' \
301 git-update-cache --add DF &&
302 git-read-tree -m -u $treeDF $treeDFDF &&
303 git-ls-files --stage >DFDFcheck.out &&
304 diff --unified=0 DFDF.out DFDFcheck.out &&
305 check_cache_at DF/DF clean'