Do a cross-project merge of Paul Mackerras' gitk visualizer
[git/git.git] / t / t1005-read-tree-m-2way-emu23.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Junio C Hamano
4 #
5
6 test_description='Two way merge with read-tree --emu23 $H $M
7
8 This test tries two-way merge (aka fast forward with carry forward).
9
10 There is the head (called H) and another commit (called M), which is
11 simply ahead of H. The index and the work tree contains a state that
12 is derived from H, but may also have local changes. This test checks
13 all the combinations described in the two-tree merge "carry forward"
14 rules, found in <Documentation/git-rev-tree.txt>.
15
16 In the test, these paths are used:
17 bozbar - in H, stays in M, modified from bozbar to gnusto
18 frotz - not in H added in M
19 nitfol - in H, stays in M unmodified
20 rezrov - in H, deleted in M
21 yomin - not in H nor M
22 '
23 . ./test-lib.sh
24
25 read_tree_twoway () {
26 git-read-tree --emu23 "$1" "$2" &&
27 git-ls-files --stage &&
28 git-merge-cache git-merge-one-file-script -a &&
29 git-ls-files --stage
30 }
31
32 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
33 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
34 compare_change () {
35 cat current
36 sed -n >current \
37 -e '/^--- /d; /^+++ /d; /^@@ /d;' \
38 -e 's/^\([-+][0-7][0-7][0-7][0-7][0-7][0-7]\) '"$_x40"' /\1 X /p' \
39 "$1"
40 diff -u expected current
41 }
42
43 check_cache_at () {
44 clean_if_empty=`git-diff-files "$1"`
45 case "$clean_if_empty" in
46 '') echo "$1: clean" ;;
47 ?*) echo "$1: dirty" ;;
48 esac
49 case "$2,$clean_if_empty" in
50 clean,) : ;;
51 clean,?*) false ;;
52 dirty,) false ;;
53 dirty,?*) : ;;
54 esac
55 }
56
57 check_stages () {
58 cat >expected_stages
59 git-ls-files --stage | sed -e "s/ $_x40 / X /" >current_stages
60 diff -u expected_stages current_stages
61 }
62
63 test_expect_success \
64 setup \
65 'echo frotz >frotz &&
66 echo nitfol >nitfol &&
67 echo bozbar >bozbar &&
68 echo rezrov >rezrov &&
69 echo yomin >yomin &&
70 git-update-cache --add nitfol bozbar rezrov &&
71 treeH=`git-write-tree` &&
72 echo treeH $treeH &&
73 git-ls-tree $treeH &&
74
75 echo gnusto >bozbar &&
76 git-update-cache --add frotz bozbar --force-remove rezrov &&
77 git-ls-files --stage >M.out &&
78 treeM=`git-write-tree` &&
79 echo treeM $treeM &&
80 git-ls-tree $treeM &&
81 git-diff-tree $treeH $treeM'
82
83 # "read-tree -m H I+H M" but I is empty so this is "read-tree -m H H M".
84 #
85 # bozbar [O && A && B && O==A && O!=B (#14) ==> B] take M by read-tree
86 # frotz [!O && !A && B (#2) ==> B] take M by read-tree
87 # nitfol [O && A && B && O==A && O==B (#15) ==> B] take M by read-tree
88 # rezrov [O && A && !B && O==A (#10) ==> no merge] removed by script
89 #
90 # Earlier one did not have #2ALT so taking M was done by the script,
91 # which also updated the work tree and making frotz clean. With #2ALT,
92 # this is resolved by read-tree itself and the path is left dirty
93 # because we are not testing "read-tree -u --emu23".
94 test_expect_success \
95 '1, 2, 3 - no carry forward' \
96 'rm -f .git/index &&
97 read_tree_twoway $treeH $treeM &&
98 git-ls-files --stage >1-3.out &&
99 diff -u M.out 1-3.out &&
100 check_cache_at bozbar dirty &&
101 check_cache_at frotz dirty && # same as pure 2-way again.
102 check_cache_at nitfol dirty'
103
104 echo '+100644 X 0 yomin' >expected
105
106 test_expect_success \
107 '4 - carry forward local addition.' \
108 'rm -f .git/index &&
109 git-update-cache --add yomin &&
110 read_tree_twoway $treeH $treeM &&
111 git-ls-files --stage >4.out || exit
112 diff -u M.out 4.out >4diff.out
113 compare_change 4diff.out expected &&
114 check_cache_at yomin clean'
115
116 # "read-tree -m H I+H M" where !H && !M; so (I+H) not being up-to-date
117 # should not matter. Thanks to #3ALT, this is now possible.
118 test_expect_success \
119 '5 - carry forward local addition.' \
120 'rm -f .git/index &&
121 echo yomin >yomin &&
122 git-update-cache --add yomin &&
123 echo yomin yomin >yomin &&
124 read_tree_twoway $treeH $treeM &&
125 git-ls-files --stage >5.out || exit
126 diff -u M.out 5.out >5diff.out
127 compare_change 5diff.out expected &&
128 check_cache_at yomin dirty'
129
130 # "read-tree -m H I+H M" where !H && M && (I+H) == M, so this should
131 # succeed (even the entry is clean), now thanks to #5ALT.
132 test_expect_success \
133 '6 - local addition already has the same.' \
134 'rm -f .git/index &&
135 git-update-cache --add frotz &&
136 read_tree_twoway $treeH $treeM &&
137 git-ls-files --stage >6.out &&
138 diff -u M.out 6.out &&
139 check_cache_at frotz clean'
140
141 # Exactly the same pattern as above but with dirty cache. This also
142 # should succeed, now thanks to #5ALT.
143 test_expect_success \
144 '7 - local addition already has the same.' \
145 'rm -f .git/index &&
146 echo frotz >frotz &&
147 git-update-cache --add frotz &&
148 echo frotz frotz >frotz &&
149 read_tree_twoway $treeH $treeM &&
150 git-ls-files --stage >7.out &&
151 diff -u M.out 7.out &&
152 check_cache_at frotz dirty'
153
154 test_expect_success \
155 '8 - conflicting addition.' \
156 'rm -f .git/index &&
157 echo frotz frotz >frotz &&
158 git-update-cache --add frotz &&
159 if read_tree_twoway $treeH $treeM; then false; else :; fi'
160
161 test_expect_success \
162 '9 - conflicting addition.' \
163 'rm -f .git/index &&
164 echo frotz frotz >frotz &&
165 git-update-cache --add frotz &&
166 echo frotz >frotz &&
167 if read_tree_twoway $treeH $treeM; then false; else :; fi'
168
169 test_expect_success \
170 '10 - path removed.' \
171 'rm -f .git/index &&
172 echo rezrov >rezrov &&
173 git-update-cache --add rezrov &&
174 read_tree_twoway $treeH $treeM &&
175 git-ls-files --stage >10.out &&
176 diff -u M.out 10.out'
177
178 test_expect_success \
179 '11 - dirty path removed.' \
180 'rm -f .git/index &&
181 echo rezrov >rezrov &&
182 git-update-cache --add rezrov &&
183 echo rezrov rezrov >rezrov &&
184 if read_tree_twoway $treeH $treeM; then false; else :; fi'
185
186 test_expect_success \
187 '12 - unmatching local changes being removed.' \
188 'rm -f .git/index &&
189 echo rezrov rezrov >rezrov &&
190 git-update-cache --add rezrov &&
191 if read_tree_twoway $treeH $treeM; then false; else :; fi'
192
193 test_expect_success \
194 '13 - unmatching local changes being removed.' \
195 'rm -f .git/index &&
196 echo rezrov rezrov >rezrov &&
197 git-update-cache --add rezrov &&
198 echo rezrov >rezrov &&
199 if read_tree_twoway $treeH $treeM; then false; else :; fi'
200
201 cat >expected <<EOF
202 -100644 X 0 nitfol
203 +100644 X 0 nitfol
204 EOF
205
206 test_expect_success \
207 '14 - unchanged in two heads.' \
208 'rm -f .git/index &&
209 echo nitfol nitfol >nitfol &&
210 git-update-cache --add nitfol &&
211 read_tree_twoway $treeH $treeM &&
212 git-ls-files --stage >14.out || exit
213 diff -u M.out 14.out >14diff.out
214 compare_change 14diff.out expected &&
215 check_cache_at nitfol clean'
216
217 test_expect_success \
218 '15 - unchanged in two heads.' \
219 'rm -f .git/index &&
220 echo nitfol nitfol >nitfol &&
221 git-update-cache --add nitfol &&
222 echo nitfol nitfol nitfol >nitfol &&
223 read_tree_twoway $treeH $treeM &&
224 git-ls-files --stage >15.out || exit
225 diff -u M.out 15.out >15diff.out
226 compare_change 15diff.out expected &&
227 check_cache_at nitfol dirty'
228
229 # This is different from straight 2-way merge in that it leaves
230 # three stages of bozbar in the index file without failing, so
231 # the user can run git-diff-stages to examine the situation.
232 # With #2ALT, frotz is resolved internally.
233 test_expect_success \
234 '16 - conflicting local change.' \
235 'rm -f .git/index &&
236 echo bozbar bozbar >bozbar &&
237 git-update-cache --add bozbar &&
238 git-read-tree --emu23 $treeH $treeM &&
239 check_stages' <<\EOF
240 100644 X 1 bozbar
241 100644 X 2 bozbar
242 100644 X 3 bozbar
243 100644 X 0 frotz
244 100644 X 0 nitfol
245 100644 X 1 rezrov
246 100644 X 2 rezrov
247 EOF
248
249 test_expect_success \
250 '17 - conflicting local change.' \
251 'rm -f .git/index &&
252 echo bozbar bozbar >bozbar &&
253 git-update-cache --add bozbar &&
254 echo bozbar bozbar bozbar >bozbar &&
255 if read_tree_twoway $treeH $treeM; then false; else :; fi'
256
257 test_expect_success \
258 '18 - local change already having a good result.' \
259 'rm -f .git/index &&
260 echo gnusto >bozbar &&
261 git-update-cache --add bozbar &&
262 read_tree_twoway $treeH $treeM &&
263 git-ls-files --stage >18.out &&
264 diff -u M.out 18.out &&
265 check_cache_at bozbar clean'
266
267 test_expect_success \
268 '19 - local change already having a good result, further modified.' \
269 'rm -f .git/index &&
270 echo gnusto >bozbar &&
271 git-update-cache --add bozbar &&
272 echo gnusto gnusto >bozbar &&
273 read_tree_twoway $treeH $treeM &&
274 git-ls-files --stage >19.out &&
275 diff -u M.out 19.out &&
276 check_cache_at bozbar dirty'
277
278 test_expect_success \
279 '20 - no local change, use new tree.' \
280 'rm -f .git/index &&
281 echo bozbar >bozbar &&
282 git-update-cache --add bozbar &&
283 read_tree_twoway $treeH $treeM &&
284 git-ls-files --stage >20.out &&
285 diff -u M.out 20.out &&
286 check_cache_at bozbar dirty'
287
288 test_expect_success \
289 '21 - no local change, dirty cache.' \
290 'rm -f .git/index &&
291 echo bozbar >bozbar &&
292 git-update-cache --add bozbar &&
293 echo gnusto gnusto >bozbar &&
294 if read_tree_twoway $treeH $treeM; then false; else :; fi'
295
296 # Also make sure we did not break DF vs DF/DF case.
297 test_expect_success \
298 'DF vs DF/DF case setup.' \
299 'rm -f .git/index &&
300 echo DF >DF &&
301 git-update-cache --add DF &&
302 treeDF=`git-write-tree` &&
303 echo treeDF $treeDF &&
304 git-ls-tree $treeDF &&
305
306 rm -f DF &&
307 mkdir DF &&
308 echo DF/DF >DF/DF &&
309 git-update-cache --add --remove DF DF/DF &&
310 treeDFDF=`git-write-tree` &&
311 echo treeDFDF $treeDFDF &&
312 git-ls-tree $treeDFDF &&
313 git-ls-files --stage >DFDF.out'
314
315 test_expect_success \
316 'DF vs DF/DF case test.' \
317 'rm -f .git/index &&
318 rm -fr DF &&
319 echo DF >DF &&
320 git-update-cache --add DF &&
321 read_tree_twoway $treeDF $treeDFDF &&
322 git-ls-files --stage >DFDFcheck.out &&
323 diff -u DFDF.out DFDFcheck.out &&
324 check_cache_at DF/DF clean && # different from pure 2-way
325 :'
326
327 test_done