3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='Merge base and parent list computation.
14 GIT_COMMITTER_EMAIL
=git@
comm.iter.xz
15 GIT_COMMITTER_NAME
='C O Mmiter'
16 GIT_AUTHOR_NAME
='A U Thor'
17 GIT_AUTHOR_EMAIL
=git@au.thor.xz
18 export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
28 PARENTS
="${PARENTS}-p $P "
31 GIT_COMMITTER_DATE
="$(($M + $OFFSET)) $Z" &&
32 GIT_AUTHOR_DATE
=$GIT_COMMITTER_DATE &&
33 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
&&
35 commit
=$
(echo $NAME | git commit-tree
$T $PARENTS) &&
37 echo $commit >.git
/refs
/tags
/$NAME &&
41 test_expect_success
'setup' '
42 T=$(git mktree </dev/null)
45 test_expect_success
'set up G and H' '
57 G=$(doit 7 G $B $E) &&
61 test_expect_success
'merge-base G H' '
62 git name-rev $B >expected &&
64 MB=$(git merge-base G H) &&
65 git name-rev "$MB" >actual.single &&
67 MB=$(git merge-base --all G H) &&
68 git name-rev "$MB" >actual.all &&
70 MB=$(git show-branch --merge-base G H) &&
71 git name-rev "$MB" >actual.sb &&
73 test_cmp expected actual.single &&
74 test_cmp expected actual.all &&
75 test_cmp expected actual.sb
78 test_expect_success
'merge-base/show-branch --independent' '
79 git name-rev "$H" >expected1 &&
80 git name-rev "$H" "$G" >expected2 &&
82 parents=$(git merge-base --independent H) &&
83 git name-rev $parents >actual1.mb &&
84 parents=$(git merge-base --independent A H G) &&
85 git name-rev $parents >actual2.mb &&
87 parents=$(git show-branch --independent H) &&
88 git name-rev $parents >actual1.sb &&
89 parents=$(git show-branch --independent A H G) &&
90 git name-rev $parents >actual2.sb &&
92 test_cmp expected1 actual1.mb &&
93 test_cmp expected2 actual2.mb &&
94 test_cmp expected1 actual1.sb &&
95 test_cmp expected2 actual2.sb
98 test_expect_success
'unsynchronized clocks' '
99 # This test is to demonstrate that relying on timestamps in a distributed
100 # SCM to provide a _consistent_ partial ordering of commits leads to
104 # Structure timestamps
116 # The left and right chains of commits can be of any length and complexity as
117 # long as all of the timestamps are greater than that of S.
121 C0=$(doit -3 C0 $S) &&
122 C1=$(doit -2 C1 $C0) &&
123 C2=$(doit -1 C2 $C1) &&
125 L0=$(doit 1 L0 $S) &&
126 L1=$(doit 2 L1 $L0) &&
127 L2=$(doit 3 L2 $L1) &&
129 R0=$(doit 1 R0 $S) &&
130 R1=$(doit 2 R1 $R0) &&
131 R2=$(doit 3 R2 $R1) &&
133 PL=$(doit 4 PL $L2 $C2) &&
134 PR=$(doit 4 PR $C2 $R2) &&
136 git name-rev $C2 >expected &&
138 MB=$(git merge-base PL PR) &&
139 git name-rev "$MB" >actual.single &&
141 MB=$(git merge-base --all PL PR) &&
142 git name-rev "$MB" >actual.all &&
144 test_cmp expected actual.single &&
145 test_cmp expected actual.all
148 test_expect_success
'--independent with unsynchronized clocks' '
150 I1=$(doit -10 I1 $IB) &&
151 I2=$(doit -9 I2 $I1) &&
152 I3=$(doit -8 I3 $I2) &&
153 I4=$(doit -7 I4 $I3) &&
154 I5=$(doit -6 I5 $I4) &&
155 I6=$(doit -5 I6 $I5) &&
156 I7=$(doit -4 I7 $I6) &&
157 I8=$(doit -3 I8 $I7) &&
158 IH=$(doit -2 IH $I8) &&
160 echo $IH >expected &&
161 git merge-base --independent IB IH >actual &&
162 test_cmp expected actual
165 test_expect_success
'merge-base for octopus-step (setup)' '
166 # Another set to demonstrate base between one commit and a merge
167 # in the documentation.
169 # * C (MMC) * B (MMB) * A (MMA)
199 test_expect_success
'merge-base A B C' '
200 git rev-parse --verify MM1 >expected &&
201 git rev-parse --verify MMR >expected.sb &&
203 git merge-base --all MMA MMB MMC >actual &&
204 git merge-base --all --octopus MMA MMB MMC >actual.common &&
205 git show-branch --merge-base MMA MMB MMC >actual.sb &&
207 test_cmp expected actual &&
208 test_cmp expected.sb actual.common &&
209 test_cmp expected.sb actual.sb
212 test_expect_success
'criss-cross merge-base for octopus-step' '
213 git reset --hard MMR &&
215 git reset --hard E &&
218 git merge -s ours CC1 &&
221 git reset --hard CC1 &&
222 git merge -s ours CC2 &&
225 git rev-parse CC1 CC2 >expected &&
226 git merge-base --all CCB CCA^^ CCA^^2 >actual &&
228 sort expected >expected.sorted &&
229 sort actual >actual.sorted &&
230 test_cmp expected.sorted actual.sorted
233 test_expect_success
'using reflog to find the fork point' '
235 git checkout -b base $E &&
240 git commit --allow-empty -m "Base commit #$count" &&
241 git rev-parse HEAD >expect$count &&
242 git checkout -B derived &&
243 git commit --allow-empty -m "Derived #$count" &&
244 git rev-parse HEAD >derived$count &&
245 git checkout -B base $E || exit 1
250 git merge-base --fork-point base $(cat derived$count) >actual &&
251 test_cmp expect$count actual || exit 1
255 # check that we correctly default to HEAD
256 git checkout derived &&
257 git merge-base --fork-point base >actual &&
258 test_cmp expect3 actual
261 test_expect_success
'merge-base --octopus --all for complex tree' '
262 # Best common ancestor for JE, JAA and JDD is JC
282 git reset --hard J &&
284 git reset --hard J &&
285 test_commit JTEMP1 &&
288 git reset --hard J &&
289 test_commit JTEMP2 &&
292 git reset --hard J &&
293 test_commit JTEMP3 &&
295 git rev-parse JC >expected &&
296 git merge-base --all --octopus JAA JDD JE >actual &&
297 test_cmp expected actual