3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='Merge base and parent list computation.
9 TEST_PASSES_SANITIZE_LEAK
=true
15 GIT_COMMITTER_EMAIL
=git@
comm.iter.xz
16 GIT_COMMITTER_NAME
='C O Mmiter'
17 GIT_AUTHOR_NAME
='A U Thor'
18 GIT_AUTHOR_EMAIL
=git@au.thor.xz
19 export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
29 PARENTS
="${PARENTS}-p $P "
32 GIT_COMMITTER_DATE
="$(($M + $OFFSET)) $Z" &&
33 GIT_AUTHOR_DATE
=$GIT_COMMITTER_DATE &&
34 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
&&
36 commit
=$
(echo $NAME | git commit-tree
$T $PARENTS) &&
38 git update-ref
"refs/tags/$NAME" "$commit" &&
42 test_expect_success
'setup' '
43 T=$(git mktree </dev/null)
46 test_expect_success
'set up G and H' '
58 G=$(doit 7 G $B $E) &&
62 test_expect_success
'merge-base G H' '
63 git name-rev $B >expected &&
65 MB=$(git merge-base G H) &&
66 git name-rev "$MB" >actual.single &&
68 MB=$(git merge-base --all G H) &&
69 git name-rev "$MB" >actual.all &&
71 MB=$(git show-branch --merge-base G H) &&
72 git name-rev "$MB" >actual.sb &&
74 test_cmp expected actual.single &&
75 test_cmp expected actual.all &&
76 test_cmp expected actual.sb
79 test_expect_success
'merge-base/show-branch --independent' '
80 git name-rev "$H" >expected1 &&
81 git name-rev "$H" "$G" >expected2 &&
83 parents=$(git merge-base --independent H) &&
84 git name-rev $parents >actual1.mb &&
85 parents=$(git merge-base --independent A H G) &&
86 git name-rev $parents >actual2.mb &&
88 parents=$(git show-branch --independent H) &&
89 git name-rev $parents >actual1.sb &&
90 parents=$(git show-branch --independent A H G) &&
91 git name-rev $parents >actual2.sb &&
93 test_cmp expected1 actual1.mb &&
94 test_cmp expected2 actual2.mb &&
95 test_cmp expected1 actual1.sb &&
96 test_cmp expected2 actual2.sb
99 test_expect_success
'unsynchronized clocks' '
100 # This test is to demonstrate that relying on timestamps in a distributed
101 # SCM to provide a _consistent_ partial ordering of commits leads to
105 # Structure timestamps
117 # The left and right chains of commits can be of any length and complexity as
118 # long as all of the timestamps are greater than that of S.
122 C0=$(doit -3 C0 $S) &&
123 C1=$(doit -2 C1 $C0) &&
124 C2=$(doit -1 C2 $C1) &&
126 L0=$(doit 1 L0 $S) &&
127 L1=$(doit 2 L1 $L0) &&
128 L2=$(doit 3 L2 $L1) &&
130 R0=$(doit 1 R0 $S) &&
131 R1=$(doit 2 R1 $R0) &&
132 R2=$(doit 3 R2 $R1) &&
134 PL=$(doit 4 PL $L2 $C2) &&
135 PR=$(doit 4 PR $C2 $R2) &&
137 git name-rev $C2 >expected &&
139 MB=$(git merge-base PL PR) &&
140 git name-rev "$MB" >actual.single &&
142 MB=$(git merge-base --all PL PR) &&
143 git name-rev "$MB" >actual.all &&
145 test_cmp expected actual.single &&
146 test_cmp expected actual.all
149 test_expect_success
'--independent with unsynchronized clocks' '
151 I1=$(doit -10 I1 $IB) &&
152 I2=$(doit -9 I2 $I1) &&
153 I3=$(doit -8 I3 $I2) &&
154 I4=$(doit -7 I4 $I3) &&
155 I5=$(doit -6 I5 $I4) &&
156 I6=$(doit -5 I6 $I5) &&
157 I7=$(doit -4 I7 $I6) &&
158 I8=$(doit -3 I8 $I7) &&
159 IH=$(doit -2 IH $I8) &&
161 echo $IH >expected &&
162 git merge-base --independent IB IH >actual &&
163 test_cmp expected actual
166 test_expect_success
'merge-base for octopus-step (setup)' '
167 # Another set to demonstrate base between one commit and a merge
168 # in the documentation.
170 # * C (MMC) * B (MMB) * A (MMA)
200 test_expect_success
'merge-base A B C' '
201 git rev-parse --verify MM1 >expected &&
202 git rev-parse --verify MMR >expected.sb &&
204 git merge-base --all MMA MMB MMC >actual &&
205 git merge-base --all --octopus MMA MMB MMC >actual.common &&
206 git show-branch --merge-base MMA MMB MMC >actual.sb &&
208 test_cmp expected actual &&
209 test_cmp expected.sb actual.common &&
210 test_cmp expected.sb actual.sb
213 test_expect_success
'criss-cross merge-base for octopus-step' '
214 git reset --hard MMR &&
216 git reset --hard E &&
219 # E is a root commit unrelated to MMR root on which CC1 is based
220 git merge -s ours --allow-unrelated-histories CC1 &&
223 git reset --hard CC1 &&
224 # E is a root commit unrelated to MMR root on which CC1 is based
225 git merge -s ours --allow-unrelated-histories CC2 &&
228 git rev-parse CC1 CC2 >expected &&
229 git merge-base --all CCB CCA^^ CCA^^2 >actual &&
231 sort expected >expected.sorted &&
232 sort actual >actual.sorted &&
233 test_cmp expected.sorted actual.sorted
236 test_expect_success
'using reflog to find the fork point' '
238 git checkout -b base $E &&
243 git commit --allow-empty -m "Base commit #$count" &&
244 git rev-parse HEAD >expect$count &&
245 git checkout -B derived &&
246 git commit --allow-empty -m "Derived #$count" &&
247 git rev-parse HEAD >derived$count &&
248 git checkout -B base $E || exit 1
253 git merge-base --fork-point base $(cat derived$count) >actual &&
254 test_cmp expect$count actual || exit 1
258 # check that we correctly default to HEAD
259 git checkout derived &&
260 git merge-base --fork-point base >actual &&
261 test_cmp expect3 actual
264 test_expect_success
'--fork-point works with empty reflog' '
265 git -c core.logallrefupdates=false branch no-reflog base &&
266 git merge-base --fork-point no-reflog derived &&
267 test_cmp expect3 actual
270 test_expect_success
'merge-base --octopus --all for complex tree' '
271 # Best common ancestor for JE, JAA and JDD is JC
291 git reset --hard J &&
293 git reset --hard J &&
294 test_commit JTEMP1 &&
297 git reset --hard J &&
298 test_commit JTEMP2 &&
301 git reset --hard J &&
302 test_commit JTEMP3 &&
304 git rev-parse JC >expected &&
305 git merge-base --all --octopus JAA JDD JE >actual &&
306 test_cmp expected actual