blob: a0b79b4839fb21a96bf8aca769542d93b21bb90f [file] [log] [blame]
Junio C Hamano2ecd9052005-05-14 01:46:46 -07001#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='Three way merge with read-tree -m
7
8This test tries three-way merge with read-tree -m
9
10There is one ancestor (called O for Original) and two branches A
11and B derived from it. We want to do a 3-way merge between A and
12B, using O as the common ancestor.
13
14 merge A O B
15
16Decisions are made by comparing contents of O, A and B pathname
17by pathname. The result is determined by the following guiding
18principle:
19
20 - If only A does something to it and B does not touch it, take
21 whatever A does.
22
23 - If only B does something to it and A does not touch it, take
24 whatever B does.
25
26 - If both A and B does something but in the same way, take
27 whatever they do.
28
29 - If A and B does something but different things, we need a
30 3-way merge:
31
32 - We cannot do anything about the following cases:
33
34 * O does not have it. A and B both must be adding to the
35 same path independently.
36
37 * A deletes it. B must be modifying.
38
39 - Otherwise, A and B are modifying. Run 3-way merge.
40
41First, the case matrix.
42
43 - Vertical axis is for A'\''s actions.
44 - Horizontal axis is for B'\''s actions.
45
46.----------------------------------------------------------------.
47| A B | No Action | Delete | Modify | Add |
48|------------+------------+------------+------------+------------|
49| No Action | | | | |
50| | select O | delete | select B | select B |
51| | | | | |
52|------------+------------+------------+------------+------------|
53| Delete | | | ********** | can |
54| | delete | delete | merge | not |
55| | | | | happen |
56|------------+------------+------------+------------+------------|
57| Modify | | ********** | ?????????? | can |
58| | select A | merge | select A=B | not |
59| | | | merge | happen |
60|------------+------------+------------+------------+------------|
61| Add | | can | can | ?????????? |
62| | select A | not | not | select A=B |
63| | | happen | happen | merge |
64.----------------------------------------------------------------.
65
66In addition:
67
68 SS: a special case of MM, where A and B makes the same modification.
69 LL: a special case of AA, where A and B creates the same file.
70 TT: a special case of MM, where A and B makes mergeable changes.
71 DF: a special case, where A makes a directory and B makes a file.
72
73'
Junio C Hamano2ecd9052005-05-14 01:46:46 -070074. ./test-lib.sh
Jens Lehmannea5070c2011-05-25 22:10:41 +020075. "$TEST_DIRECTORY"/lib-read-tree.sh
Junio C Hamanobfdbee92008-08-08 02:26:28 -070076. "$TEST_DIRECTORY"/lib-read-tree-m-3way.sh
Junio C Hamano2ecd9052005-05-14 01:46:46 -070077
78################################################################
Junio C Hamano32192e62005-06-11 02:50:51 -070079# Trivial "majority when 3 stages exist" merge plus #2ALT, #3ALT
80# and #5ALT trivial merges.
Junio C Hamano2ecd9052005-05-14 01:46:46 -070081
Junio C Hamano2ecd9052005-05-14 01:46:46 -070082cat >expected <<\EOF
Junio C Hamano2eab9452005-05-26 14:38:19 -070083100644 X 2 AA
84100644 X 3 AA
Junio C Hamano32192e62005-06-11 02:50:51 -070085100644 X 0 AN
Junio C Hamano2eab9452005-05-26 14:38:19 -070086100644 X 1 DD
87100644 X 3 DF
88100644 X 2 DF/DF
89100644 X 1 DM
90100644 X 3 DM
91100644 X 1 DN
92100644 X 3 DN
Junio C Hamanoe7f9bc42005-06-10 18:37:47 -070093100644 X 0 LL
Junio C Hamano2eab9452005-05-26 14:38:19 -070094100644 X 1 MD
95100644 X 2 MD
96100644 X 1 MM
97100644 X 2 MM
98100644 X 3 MM
99100644 X 0 MN
Junio C Hamano32192e62005-06-11 02:50:51 -0700100100644 X 0 NA
Junio C Hamano2eab9452005-05-26 14:38:19 -0700101100644 X 1 ND
102100644 X 2 ND
103100644 X 0 NM
104100644 X 0 NN
105100644 X 0 SS
106100644 X 1 TT
107100644 X 2 TT
108100644 X 3 TT
109100644 X 2 Z/AA
110100644 X 3 Z/AA
Junio C Hamano32192e62005-06-11 02:50:51 -0700111100644 X 0 Z/AN
Junio C Hamano2eab9452005-05-26 14:38:19 -0700112100644 X 1 Z/DD
113100644 X 1 Z/DM
114100644 X 3 Z/DM
115100644 X 1 Z/DN
116100644 X 3 Z/DN
117100644 X 1 Z/MD
118100644 X 2 Z/MD
119100644 X 1 Z/MM
120100644 X 2 Z/MM
121100644 X 3 Z/MM
122100644 X 0 Z/MN
Junio C Hamano32192e62005-06-11 02:50:51 -0700123100644 X 0 Z/NA
Junio C Hamano2eab9452005-05-26 14:38:19 -0700124100644 X 1 Z/ND
125100644 X 2 Z/ND
126100644 X 0 Z/NM
127100644 X 0 Z/NN
Junio C Hamano2ecd9052005-05-14 01:46:46 -0700128EOF
129
Junio C Hamanof225b212005-06-08 14:55:35 -0700130check_result () {
Junio C Hamano5be60072007-07-02 22:52:14 -0700131 git ls-files --stage | sed -e 's/ '"$_x40"' / X /' >current &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700132 test_cmp expected current
Junio C Hamanof225b212005-06-08 14:55:35 -0700133}
Junio C Hamano7d95ee92005-06-08 02:08:54 -0700134
135# This is done on an empty work directory, which is the normal
136# merge person behaviour.
Junio C Hamano2ecd9052005-05-14 01:46:46 -0700137test_expect_success \
Junio C Hamano5be60072007-07-02 22:52:14 -0700138 '3-way merge with git read-tree -m, empty cache' \
Junio C Hamano7d95ee92005-06-08 02:08:54 -0700139 "rm -fr [NDMALTS][NDMALTSF] Z &&
140 rm .git/index &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200141 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700142 check_result"
Junio C Hamano7d95ee92005-06-08 02:08:54 -0700143
144# This starts out with the first head, which is the normal
145# patch submitter behaviour.
146test_expect_success \
Junio C Hamano5be60072007-07-02 22:52:14 -0700147 '3-way merge with git read-tree -m, match H' \
Junio C Hamanof225b212005-06-08 14:55:35 -0700148 "rm -fr [NDMALTS][NDMALTSF] Z &&
149 rm .git/index &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200150 read_tree_must_succeed $tree_A &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700151 git checkout-index -f -u -a &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200152 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700153 check_result"
154
155: <<\END_OF_CASE_TABLE
156
157We have so far tested only empty index and clean-and-matching-A index
158case which are trivial. Make sure index requirements are also
Junio C Hamano3e03aaf2005-09-28 12:56:18 -0700159checked.
Junio C Hamanof225b212005-06-08 14:55:35 -0700160
Junio C Hamano5be60072007-07-02 22:52:14 -0700161"git read-tree -m O A B"
Junio C Hamanof225b212005-06-08 14:55:35 -0700162
163 O A B result index requirements
164-------------------------------------------------------------------
165 1 missing missing missing - must not exist.
166 ------------------------------------------------------------------
Junio C Hamano3e03aaf2005-09-28 12:56:18 -0700167 2 missing missing exists take B* must match B, if exists.
Junio C Hamanof225b212005-06-08 14:55:35 -0700168 ------------------------------------------------------------------
Junio C Hamano3e03aaf2005-09-28 12:56:18 -0700169 3 missing exists missing take A* must match A, if exists.
Junio C Hamanof225b212005-06-08 14:55:35 -0700170 ------------------------------------------------------------------
171 4 missing exists A!=B no merge must match A and be
172 up-to-date, if exists.
173 ------------------------------------------------------------------
Junio C Hamano3e03aaf2005-09-28 12:56:18 -0700174 5 missing exists A==B take A must match A, if exists.
Junio C Hamanof225b212005-06-08 14:55:35 -0700175 ------------------------------------------------------------------
Junio C Hamano3e03aaf2005-09-28 12:56:18 -0700176 6 exists missing missing remove must not exist.
Junio C Hamanof225b212005-06-08 14:55:35 -0700177 ------------------------------------------------------------------
178 7 exists missing O!=B no merge must not exist.
179 ------------------------------------------------------------------
Junio C Hamano3e03aaf2005-09-28 12:56:18 -0700180 8 exists missing O==B remove must not exist.
Junio C Hamanof225b212005-06-08 14:55:35 -0700181 ------------------------------------------------------------------
182 9 exists O!=A missing no merge must match A and be
183 up-to-date, if exists.
184 ------------------------------------------------------------------
Junio C Hamanoea4b52a2007-04-07 05:42:01 -0700185 10 exists O==A missing no merge must match A
Junio C Hamanof225b212005-06-08 14:55:35 -0700186 ------------------------------------------------------------------
187 11 exists O!=A O!=B no merge must match A and be
188 A!=B up-to-date, if exists.
189 ------------------------------------------------------------------
190 12 exists O!=A O!=B take A must match A, if exists.
191 A==B
192 ------------------------------------------------------------------
193 13 exists O!=A O==B take A must match A, if exists.
194 ------------------------------------------------------------------
Junio C Hamano3e03aaf2005-09-28 12:56:18 -0700195 14 exists O==A O!=B take B if exists, must either (1)
Junio C Hamanof225b212005-06-08 14:55:35 -0700196 match A and be up-to-date,
197 or (2) match B.
198 ------------------------------------------------------------------
199 15 exists O==A O==B take B must match A if exists.
Junio C Hamano4d3fe0c2005-09-06 12:53:56 -0700200 ------------------------------------------------------------------
201 16 exists O==A O==B barf must match A if exists.
202 *multi* in one in another
Junio C Hamanof225b212005-06-08 14:55:35 -0700203-------------------------------------------------------------------
204
Junio C Hamano3e03aaf2005-09-28 12:56:18 -0700205Note: we need to be careful in case 2 and 3. The tree A may contain
206DF (file) when tree B require DF to be a directory by having DF/DF
207(file).
Junio C Hamanof225b212005-06-08 14:55:35 -0700208
209END_OF_CASE_TABLE
210
Junio C Hamano41ac4142008-02-01 01:50:53 -0800211test_expect_success '1 - must not have an entry not in A.' "
212 rm -f .git/index XX &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700213 echo XX >XX &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700214 git update-index --add XX &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200215 read_tree_must_fail -m $tree_O $tree_A $tree_B
Junio C Hamano41ac4142008-02-01 01:50:53 -0800216"
Junio C Hamanof225b212005-06-08 14:55:35 -0700217
Junio C Hamano32192e62005-06-11 02:50:51 -0700218test_expect_success \
219 '2 - must match B in !O && !A && B case.' \
Junio C Hamanof225b212005-06-08 14:55:35 -0700220 "rm -f .git/index NA &&
221 cp .orig-B/NA NA &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700222 git update-index --add NA &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200223 read_tree_must_succeed -m $tree_O $tree_A $tree_B"
Junio C Hamanof225b212005-06-08 14:55:35 -0700224
225test_expect_success \
Junio C Hamano32192e62005-06-11 02:50:51 -0700226 '2 - matching B alone is OK in !O && !A && B case.' \
227 "rm -f .git/index NA &&
228 cp .orig-B/NA NA &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700229 git update-index --add NA &&
Junio C Hamano32192e62005-06-11 02:50:51 -0700230 echo extra >>NA &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200231 read_tree_must_succeed -m $tree_O $tree_A $tree_B"
Junio C Hamano32192e62005-06-11 02:50:51 -0700232
233test_expect_success \
234 '3 - must match A in !O && A && !B case.' \
Junio C Hamanof225b212005-06-08 14:55:35 -0700235 "rm -f .git/index AN &&
236 cp .orig-A/AN AN &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700237 git update-index --add AN &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200238 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700239 check_result"
240
Junio C Hamano32192e62005-06-11 02:50:51 -0700241test_expect_success \
242 '3 - matching A alone is OK in !O && A && !B case.' \
Junio C Hamanof225b212005-06-08 14:55:35 -0700243 "rm -f .git/index AN &&
244 cp .orig-A/AN AN &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700245 git update-index --add AN &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700246 echo extra >>AN &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200247 read_tree_must_succeed -m $tree_O $tree_A $tree_B"
Junio C Hamanof225b212005-06-08 14:55:35 -0700248
Junio C Hamano41ac4142008-02-01 01:50:53 -0800249test_expect_success \
250 '3 (fail) - must match A in !O && A && !B case.' "
251 rm -f .git/index AN &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700252 cp .orig-A/AN AN &&
253 echo extra >>AN &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700254 git update-index --add AN &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200255 read_tree_must_fail -m $tree_O $tree_A $tree_B
Junio C Hamano41ac4142008-02-01 01:50:53 -0800256"
Junio C Hamanof225b212005-06-08 14:55:35 -0700257
258test_expect_success \
259 '4 - must match and be up-to-date in !O && A && B && A!=B case.' \
260 "rm -f .git/index AA &&
261 cp .orig-A/AA AA &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700262 git update-index --add AA &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200263 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700264 check_result"
265
Junio C Hamano41ac4142008-02-01 01:50:53 -0800266test_expect_success \
267 '4 (fail) - must match and be up-to-date in !O && A && B && A!=B case.' "
268 rm -f .git/index AA &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700269 cp .orig-A/AA AA &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700270 git update-index --add AA &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700271 echo extra >>AA &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200272 read_tree_must_fail -m $tree_O $tree_A $tree_B
Junio C Hamano41ac4142008-02-01 01:50:53 -0800273"
Junio C Hamanof225b212005-06-08 14:55:35 -0700274
Junio C Hamano41ac4142008-02-01 01:50:53 -0800275test_expect_success \
276 '4 (fail) - must match and be up-to-date in !O && A && B && A!=B case.' "
277 rm -f .git/index AA &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700278 cp .orig-A/AA AA &&
279 echo extra >>AA &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700280 git update-index --add AA &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200281 read_tree_must_fail -m $tree_O $tree_A $tree_B
Junio C Hamano41ac4142008-02-01 01:50:53 -0800282"
Junio C Hamanof225b212005-06-08 14:55:35 -0700283
284test_expect_success \
Junio C Hamanoe7f9bc42005-06-10 18:37:47 -0700285 '5 - must match in !O && A && B && A==B case.' \
Junio C Hamanof225b212005-06-08 14:55:35 -0700286 "rm -f .git/index LL &&
287 cp .orig-A/LL LL &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700288 git update-index --add LL &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200289 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700290 check_result"
291
Junio C Hamanoe7f9bc42005-06-10 18:37:47 -0700292test_expect_success \
293 '5 - must match in !O && A && B && A==B case.' \
Junio C Hamanof225b212005-06-08 14:55:35 -0700294 "rm -f .git/index LL &&
295 cp .orig-A/LL LL &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700296 git update-index --add LL &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700297 echo extra >>LL &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200298 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
Junio C Hamanoe7f9bc42005-06-10 18:37:47 -0700299 check_result"
Junio C Hamanof225b212005-06-08 14:55:35 -0700300
Junio C Hamano41ac4142008-02-01 01:50:53 -0800301test_expect_success \
302 '5 (fail) - must match A in !O && A && B && A==B case.' "
303 rm -f .git/index LL &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700304 cp .orig-A/LL LL &&
305 echo extra >>LL &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700306 git update-index --add LL &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200307 read_tree_must_fail -m $tree_O $tree_A $tree_B
Junio C Hamano41ac4142008-02-01 01:50:53 -0800308"
Junio C Hamanof225b212005-06-08 14:55:35 -0700309
Junio C Hamano41ac4142008-02-01 01:50:53 -0800310test_expect_success \
311 '6 - must not exist in O && !A && !B case' "
312 rm -f .git/index DD &&
Jonathan Niedera48fcd82010-10-30 20:46:54 -0500313 echo DD >DD &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700314 git update-index --add DD &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200315 read_tree_must_fail -m $tree_O $tree_A $tree_B
Junio C Hamano41ac4142008-02-01 01:50:53 -0800316"
Junio C Hamanof225b212005-06-08 14:55:35 -0700317
Junio C Hamano41ac4142008-02-01 01:50:53 -0800318test_expect_success \
319 '7 - must not exist in O && !A && B && O!=B case' "
320 rm -f .git/index DM &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700321 cp .orig-B/DM DM &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700322 git update-index --add DM &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200323 read_tree_must_fail -m $tree_O $tree_A $tree_B
Junio C Hamano41ac4142008-02-01 01:50:53 -0800324"
Junio C Hamanof225b212005-06-08 14:55:35 -0700325
Junio C Hamano41ac4142008-02-01 01:50:53 -0800326test_expect_success \
327 '8 - must not exist in O && !A && B && O==B case' "
328 rm -f .git/index DN &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700329 cp .orig-B/DN DN &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700330 git update-index --add DN &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200331 read_tree_must_fail -m $tree_O $tree_A $tree_B
Junio C Hamano41ac4142008-02-01 01:50:53 -0800332"
Junio C Hamanof225b212005-06-08 14:55:35 -0700333
334test_expect_success \
335 '9 - must match and be up-to-date in O && A && !B && O!=A case' \
336 "rm -f .git/index MD &&
337 cp .orig-A/MD MD &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700338 git update-index --add MD &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200339 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700340 check_result"
341
Junio C Hamano41ac4142008-02-01 01:50:53 -0800342test_expect_success \
343 '9 (fail) - must match and be up-to-date in O && A && !B && O!=A case' "
344 rm -f .git/index MD &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700345 cp .orig-A/MD MD &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700346 git update-index --add MD &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700347 echo extra >>MD &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200348 read_tree_must_fail -m $tree_O $tree_A $tree_B
Junio C Hamano41ac4142008-02-01 01:50:53 -0800349"
Junio C Hamanof225b212005-06-08 14:55:35 -0700350
Junio C Hamano41ac4142008-02-01 01:50:53 -0800351test_expect_success \
352 '9 (fail) - must match and be up-to-date in O && A && !B && O!=A case' "
353 rm -f .git/index MD &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700354 cp .orig-A/MD MD &&
355 echo extra >>MD &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700356 git update-index --add MD &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200357 read_tree_must_fail -m $tree_O $tree_A $tree_B
Junio C Hamano41ac4142008-02-01 01:50:53 -0800358"
Junio C Hamanof225b212005-06-08 14:55:35 -0700359
360test_expect_success \
361 '10 - must match and be up-to-date in O && A && !B && O==A case' \
362 "rm -f .git/index ND &&
363 cp .orig-A/ND ND &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700364 git update-index --add ND &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200365 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700366 check_result"
367
Junio C Hamano41ac4142008-02-01 01:50:53 -0800368test_expect_success \
369 '10 (fail) - must match and be up-to-date in O && A && !B && O==A case' "
370 rm -f .git/index ND &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700371 cp .orig-A/ND ND &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700372 git update-index --add ND &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700373 echo extra >>ND &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200374 read_tree_must_fail -m $tree_O $tree_A $tree_B
Junio C Hamano41ac4142008-02-01 01:50:53 -0800375"
Junio C Hamanof225b212005-06-08 14:55:35 -0700376
Junio C Hamano41ac4142008-02-01 01:50:53 -0800377test_expect_success \
378 '10 (fail) - must match and be up-to-date in O && A && !B && O==A case' "
379 rm -f .git/index ND &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700380 cp .orig-A/ND ND &&
381 echo extra >>ND &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700382 git update-index --add ND &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200383 read_tree_must_fail -m $tree_O $tree_A $tree_B
Junio C Hamano41ac4142008-02-01 01:50:53 -0800384"
Junio C Hamanof225b212005-06-08 14:55:35 -0700385
386test_expect_success \
387 '11 - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' \
388 "rm -f .git/index MM &&
389 cp .orig-A/MM MM &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700390 git update-index --add MM &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200391 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700392 check_result"
393
Junio C Hamano41ac4142008-02-01 01:50:53 -0800394test_expect_success \
395 '11 (fail) - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' "
396 rm -f .git/index MM &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700397 cp .orig-A/MM MM &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700398 git update-index --add MM &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700399 echo extra >>MM &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200400 read_tree_must_fail -m $tree_O $tree_A $tree_B
Junio C Hamano41ac4142008-02-01 01:50:53 -0800401"
Junio C Hamanof225b212005-06-08 14:55:35 -0700402
Junio C Hamano41ac4142008-02-01 01:50:53 -0800403test_expect_success \
404 '11 (fail) - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' "
405 rm -f .git/index MM &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700406 cp .orig-A/MM MM &&
407 echo extra >>MM &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700408 git update-index --add MM &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200409 read_tree_must_fail -m $tree_O $tree_A $tree_B
Junio C Hamano41ac4142008-02-01 01:50:53 -0800410"
Junio C Hamanof225b212005-06-08 14:55:35 -0700411
412test_expect_success \
413 '12 - must match A in O && A && B && O!=A && A==B case' \
414 "rm -f .git/index SS &&
415 cp .orig-A/SS SS &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700416 git update-index --add SS &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200417 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700418 check_result"
419
420test_expect_success \
421 '12 - must match A in O && A && B && O!=A && A==B case' \
422 "rm -f .git/index SS &&
423 cp .orig-A/SS SS &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700424 git update-index --add SS &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700425 echo extra >>SS &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200426 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700427 check_result"
428
Junio C Hamano41ac4142008-02-01 01:50:53 -0800429test_expect_success \
430 '12 (fail) - must match A in O && A && B && O!=A && A==B case' "
431 rm -f .git/index SS &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700432 cp .orig-A/SS SS &&
433 echo extra >>SS &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700434 git update-index --add SS &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200435 read_tree_must_fail -m $tree_O $tree_A $tree_B
Junio C Hamano41ac4142008-02-01 01:50:53 -0800436"
Junio C Hamanof225b212005-06-08 14:55:35 -0700437
438test_expect_success \
439 '13 - must match A in O && A && B && O!=A && O==B case' \
440 "rm -f .git/index MN &&
441 cp .orig-A/MN MN &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700442 git update-index --add MN &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200443 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700444 check_result"
445
446test_expect_success \
447 '13 - must match A in O && A && B && O!=A && O==B case' \
448 "rm -f .git/index MN &&
449 cp .orig-A/MN MN &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700450 git update-index --add MN &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700451 echo extra >>MN &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200452 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700453 check_result"
454
455test_expect_success \
456 '14 - must match and be up-to-date in O && A && B && O==A && O!=B case' \
457 "rm -f .git/index NM &&
458 cp .orig-A/NM NM &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700459 git update-index --add NM &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200460 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700461 check_result"
462
Junio C Hamano036d51c2005-06-11 02:53:57 -0700463test_expect_success \
464 '14 - may match B in O && A && B && O==A && O!=B case' \
465 "rm -f .git/index NM &&
466 cp .orig-B/NM NM &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700467 git update-index --add NM &&
Junio C Hamano036d51c2005-06-11 02:53:57 -0700468 echo extra >>NM &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200469 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
Junio C Hamano036d51c2005-06-11 02:53:57 -0700470 check_result"
471
Junio C Hamano41ac4142008-02-01 01:50:53 -0800472test_expect_success \
473 '14 (fail) - must match and be up-to-date in O && A && B && O==A && O!=B case' "
474 rm -f .git/index NM &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700475 cp .orig-A/NM NM &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700476 git update-index --add NM &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700477 echo extra >>NM &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200478 read_tree_must_fail -m $tree_O $tree_A $tree_B
Junio C Hamano41ac4142008-02-01 01:50:53 -0800479"
Junio C Hamanof225b212005-06-08 14:55:35 -0700480
Junio C Hamano41ac4142008-02-01 01:50:53 -0800481test_expect_success \
482 '14 (fail) - must match and be up-to-date in O && A && B && O==A && O!=B case' "
483 rm -f .git/index NM &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700484 cp .orig-A/NM NM &&
485 echo extra >>NM &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700486 git update-index --add NM &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200487 read_tree_must_fail -m $tree_O $tree_A $tree_B
Junio C Hamano41ac4142008-02-01 01:50:53 -0800488"
Junio C Hamanof225b212005-06-08 14:55:35 -0700489
490test_expect_success \
491 '15 - must match A in O && A && B && O==A && O==B case' \
492 "rm -f .git/index NN &&
493 cp .orig-A/NN NN &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700494 git update-index --add NN &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200495 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700496 check_result"
497
498test_expect_success \
499 '15 - must match A in O && A && B && O==A && O==B case' \
500 "rm -f .git/index NN &&
501 cp .orig-A/NN NN &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700502 git update-index --add NN &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700503 echo extra >>NN &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200504 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700505 check_result"
506
Junio C Hamano41ac4142008-02-01 01:50:53 -0800507test_expect_success \
508 '15 (fail) - must match A in O && A && B && O==A && O==B case' "
509 rm -f .git/index NN &&
Junio C Hamanof225b212005-06-08 14:55:35 -0700510 cp .orig-A/NN NN &&
511 echo extra >>NN &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700512 git update-index --add NN &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200513 read_tree_must_fail -m $tree_O $tree_A $tree_B
Junio C Hamano41ac4142008-02-01 01:50:53 -0800514"
Junio C Hamano2ecd9052005-05-14 01:46:46 -0700515
Junio C Hamano4d3fe0c2005-09-06 12:53:56 -0700516# #16
517test_expect_success \
518 '16 - A matches in one and B matches in another.' \
519 'rm -f .git/index F16 &&
520 echo F16 >F16 &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700521 git update-index --add F16 &&
Elia Pinto86e30432014-04-28 05:57:31 -0700522 tree0=$(git write-tree) &&
Junio C Hamano4d3fe0c2005-09-06 12:53:56 -0700523 echo E16 >F16 &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700524 git update-index F16 &&
Elia Pinto86e30432014-04-28 05:57:31 -0700525 tree1=$(git write-tree) &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200526 read_tree_must_succeed -m $tree0 $tree1 $tree1 $tree0 &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700527 git ls-files --stage'
Junio C Hamano4d3fe0c2005-09-06 12:53:56 -0700528
Junio C Hamano2ecd9052005-05-14 01:46:46 -0700529test_done