Do a cross-project merge of Paul Mackerras' gitk visualizer
[git/git.git] / t / t1002-read-tree-m-u-2way.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Junio C Hamano
4 #
5
6 test_description='Two way merge with read-tree -m -u $H $M
7
8 This 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"
15 compare_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
22 check_cache_at () {
23 clean_if_empty=`git-diff-files "$1"`
24 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
36 test_expect_success \
37 setup \
38 'echo frotz >frotz &&
39 echo nitfol >nitfol &&
40 echo bozbar >bozbar &&
41 echo rezrov >rezrov &&
42 echo yomin >yomin &&
43 git-update-cache --add nitfol bozbar rezrov &&
44 treeH=`git-write-tree` &&
45 echo treeH $treeH &&
46 git-ls-tree $treeH &&
47
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` &&
52 echo treeM $treeM &&
53 git-ls-tree $treeM &&
54 sha1sum bozbar frotz nitfol >M.sha1 &&
55 git-diff-tree $treeH $treeM'
56
57 test_expect_success \
58 '1, 2, 3 - no carry forward' \
59 'rm -f .git/index &&
60 git-read-tree -m -u $treeH $treeM &&
61 git-ls-files --stage >1-3.out &&
62 cmp M.out 1-3.out &&
63 sha1sum -c M.sha1 &&
64 check_cache_at bozbar clean &&
65 check_cache_at frotz clean &&
66 check_cache_at nitfol clean'
67
68 echo '+100644 X 0 yomin' >expected
69
70 test_expect_success \
71 '4 - carry forward local addition.' \
72 'rm -f .git/index &&
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 &&
79 sha1sum -c M.sha1 &&
80 echo yomin >yomin1 &&
81 diff yomin yomin1 &&
82 rm -f yomin1'
83
84 test_expect_success \
85 '5 - carry forward local addition.' \
86 'rm -f .git/index &&
87 echo yomin >yomin &&
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 &&
95 sha1sum -c M.sha1 &&
96 : dirty index should have prevented -u from checking it out. &&
97 echo yomin yomin >yomin1 &&
98 diff yomin yomin1 &&
99 rm -f yomin1'
100
101 test_expect_success \
102 '6 - local addition already has the same.' \
103 'rm -f .git/index &&
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 &&
109 sha1sum -c M.sha1 &&
110 echo frotz >frotz1 &&
111 diff frotz frotz1 &&
112 rm -f frotz1'
113
114 test_expect_success \
115 '7 - local addition already has the same.' \
116 'rm -f .git/index &&
117 echo frotz >frotz &&
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 &&
127 diff frotz frotz1 &&
128 rm -f frotz1'
129
130 test_expect_success \
131 '8 - conflicting addition.' \
132 'rm -f .git/index &&
133 echo frotz frotz >frotz &&
134 git-update-cache --add frotz &&
135 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
136
137 test_expect_success \
138 '9 - conflicting addition.' \
139 'rm -f .git/index &&
140 echo frotz frotz >frotz &&
141 git-update-cache --add frotz &&
142 echo frotz >frotz &&
143 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
144
145 test_expect_success \
146 '10 - path removed.' \
147 'rm -f .git/index &&
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 &&
152 cmp M.out 10.out &&
153 sha1sum -c M.sha1'
154
155 test_expect_success \
156 '11 - dirty path removed.' \
157 'rm -f .git/index &&
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'
162
163 test_expect_success \
164 '12 - unmatching local changes being removed.' \
165 'rm -f .git/index &&
166 echo rezrov rezrov >rezrov &&
167 git-update-cache --add rezrov &&
168 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
169
170 test_expect_success \
171 '13 - unmatching local changes being removed.' \
172 'rm -f .git/index &&
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'
177
178 cat >expected <<EOF
179 -100644 X 0 nitfol
180 +100644 X 0 nitfol
181 EOF
182
183 test_expect_success \
184 '14 - unchanged in two heads.' \
185 'rm -f .git/index &&
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 &&
197 rm -f nitfol1'
198
199 test_expect_success \
200 '15 - unchanged in two heads.' \
201 'rm -f .git/index &&
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 &&
214 rm -f nitfol1'
215
216 test_expect_success \
217 '16 - conflicting local change.' \
218 'rm -f .git/index &&
219 echo bozbar bozbar >bozbar &&
220 git-update-cache --add bozbar &&
221 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
222
223 test_expect_success \
224 '17 - conflicting local change.' \
225 'rm -f .git/index &&
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'
230
231 test_expect_success \
232 '18 - local change already having a good result.' \
233 'rm -f .git/index &&
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 &&
240 sha1sum -c M.sha1'
241
242 test_expect_success \
243 '19 - local change already having a good result, further modified.' \
244 'rm -f .git/index &&
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 &&
256 rm -f bozbar1'
257
258 test_expect_success \
259 '20 - no local change, use new tree.' \
260 'rm -f .git/index &&
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 &&
267 sha1sum -c M.sha1'
268
269 test_expect_success \
270 '21 - no local change, dirty cache.' \
271 'rm -f .git/index &&
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'
276
277 # Also make sure we did not break DF vs DF/DF case.
278 test_expect_success \
279 'DF vs DF/DF case setup.' \
280 'rm -f .git/index &&
281 echo DF >DF &&
282 git-update-cache --add DF &&
283 treeDF=`git-write-tree` &&
284 echo treeDF $treeDF &&
285 git-ls-tree $treeDF &&
286
287 rm -f DF &&
288 mkdir DF &&
289 echo DF/DF >DF/DF &&
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'
295
296 test_expect_success \
297 'DF vs DF/DF case test.' \
298 'rm -f .git/index &&
299 rm -fr DF &&
300 echo DF >DF &&
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'
306
307 test_done