3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='Merge base computation.
11 test_expect_success
'setup' '
12 T=$(git write-tree) &&
17 GIT_COMMITTER_EMAIL=git@comm.iter.xz &&
18 GIT_COMMITTER_NAME="C O Mmiter" &&
19 GIT_AUTHOR_NAME="A U Thor" &&
20 GIT_AUTHOR_EMAIL=git@au.thor.xz &&
21 export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL &&
31 PARENTS="${PARENTS}-p $P "
34 GIT_COMMITTER_DATE="$(($M + $OFFSET)) $Z" &&
35 GIT_AUTHOR_DATE=$GIT_COMMITTER_DATE &&
36 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE &&
38 commit=$(echo $NAME | git commit-tree $T $PARENTS) &&
40 echo $commit >.git/refs/tags/$NAME &&
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
'unsynchronized clocks' '
79 # This test is to demonstrate that relying on timestamps in a distributed
80 # SCM to provide a _consistent_ partial ordering of commits leads to
84 # Structure timestamps
96 # The left and right chains of commits can be of any length and complexity as
97 # long as all of the timestamps are greater than that of S.
101 C0=$(doit -3 C0 $S) &&
102 C1=$(doit -2 C1 $C0) &&
103 C2=$(doit -1 C2 $C1) &&
105 L0=$(doit 1 L0 $S) &&
106 L1=$(doit 2 L1 $L0) &&
107 L2=$(doit 3 L2 $L1) &&
109 R0=$(doit 1 R0 $S) &&
110 R1=$(doit 2 R1 $R0) &&
111 R2=$(doit 3 R2 $R1) &&
113 PL=$(doit 4 PL $L2 $C2) &&
114 PR=$(doit 4 PR $C2 $R2)
116 git name-rev $C2 >expected &&
118 MB=$(git merge-base PL PR) &&
119 git name-rev "$MB" >actual.single &&
121 MB=$(git merge-base --all PL PR) &&
122 git name-rev "$MB" >actual.all &&
124 test_cmp expected actual.single &&
125 test_cmp expected actual.all
128 test_expect_success
'merge-base for octopus-step (setup)' '
129 # Another set to demonstrate base between one commit and a merge
130 # in the documentation.
132 # * C (MMC) * B (MMB) * A (MMA)
162 test_expect_success
'merge-base A B C' '
163 git rev-parse --verify MM1 >expected &&
164 git rev-parse --verify MMR >expected.sb &&
166 git merge-base --all MMA MMB MMC >actual &&
167 git merge-base --all --octopus MMA MMB MMC >actual.common &&
168 git show-branch --merge-base MMA MMB MMC >actual.sb &&
170 test_cmp expected actual &&
171 test_cmp expected.sb actual.common &&
172 test_cmp expected.sb actual.sb
175 test_expect_success
'criss-cross merge-base for octopus-step' '
176 git reset --hard MMR &&
178 git reset --hard E &&
181 git merge -s ours CC1 &&
184 git reset --hard CC1 &&
185 git merge -s ours CC2 &&
188 git rev-parse CC1 CC2 >expected &&
189 git merge-base --all CCB CCA^^ CCA^^2 >actual &&
191 sort expected >expected.sorted &&
192 sort actual >actual.sorted &&
193 test_cmp expected.sorted actual.sorted