]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6010-merge-base.sh
status: fix bug with missing --ignore files
[thirdparty/git.git] / t / t6010-merge-base.sh
CommitLineData
53de71f8
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='Merge base computation.
7'
8
9. ./test-lib.sh
10
5be60078 11T=$(git write-tree)
53de71f8
JH
12
13M=1130000000
14Z=+0000
15
0e46e704
BD
16GIT_COMMITTER_EMAIL=git@comm.iter.xz
17GIT_COMMITTER_NAME='C O Mmiter'
18GIT_AUTHOR_NAME='A U Thor'
19GIT_AUTHOR_EMAIL=git@au.thor.xz
20export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
53de71f8
JH
21
22doit() {
23 OFFSET=$1; shift
24 NAME=$1; shift
25 PARENTS=
26 for P
27 do
28 PARENTS="${PARENTS}-p $P "
29 done
30 GIT_COMMITTER_DATE="$(($M + $OFFSET)) $Z"
31 GIT_AUTHOR_DATE=$GIT_COMMITTER_DATE
32 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
5be60078 33 commit=$(echo $NAME | git commit-tree $T $PARENTS)
53de71f8
JH
34 echo $commit >.git/refs/tags/$NAME
35 echo $commit
36}
37
e3ae6bb9
SV
38# E---D---C---B---A
39# \'-_ \ \
40# \ `---------G \
41# \ \
42# F----------------H
43
53de71f8
JH
44# Setup...
45E=$(doit 5 E)
46D=$(doit 4 D $E)
47F=$(doit 6 F $E)
48C=$(doit 3 C $D)
49B=$(doit 2 B $C)
50A=$(doit 1 A $B)
51G=$(doit 7 G $B $E)
52H=$(doit 8 H $A $F)
53
e3ae6bb9 54test_expect_success 'compute merge-base (single)' \
5be60078
JH
55 'MB=$(git merge-base G H) &&
56 expr "$(git name-rev "$MB")" : "[0-9a-f]* tags/B"'
e3ae6bb9
SV
57
58test_expect_success 'compute merge-base (all)' \
5be60078
JH
59 'MB=$(git merge-base --all G H) &&
60 expr "$(git name-rev "$MB")" : "[0-9a-f]* tags/B"'
e3ae6bb9
SV
61
62test_expect_success 'compute merge-base with show-branch' \
5be60078
JH
63 'MB=$(git show-branch --merge-base G H) &&
64 expr "$(git name-rev "$MB")" : "[0-9a-f]* tags/B"'
e3ae6bb9 65
cd6f207a
LAS
66# Setup for second test to demonstrate that relying on timestamps in a
67# distributed SCM to provide a _consistent_ partial ordering of commits
68# leads to insanity.
69#
70# Relative
71# Structure timestamps
72#
73# PL PR +4 +4
74# / \/ \ / \/ \
75# L2 C2 R2 +3 -1 +3
76# | | | | | |
77# L1 C1 R1 +2 -2 +2
78# | | | | | |
79# L0 C0 R0 +1 -3 +1
80# \ | / \ | /
81# S 0
82#
83# The left and right chains of commits can be of any length and complexity as
84# long as all of the timestamps are greater than that of S.
85
86S=$(doit 0 S)
87
88C0=$(doit -3 C0 $S)
89C1=$(doit -2 C1 $C0)
90C2=$(doit -1 C2 $C1)
91
92L0=$(doit 1 L0 $S)
93L1=$(doit 2 L1 $L0)
94L2=$(doit 3 L2 $L1)
95
96R0=$(doit 1 R0 $S)
97R1=$(doit 2 R1 $R0)
98R2=$(doit 3 R2 $R1)
99
100PL=$(doit 4 PL $L2 $C2)
101PR=$(doit 4 PR $C2 $R2)
102
cd6f207a 103test_expect_success 'compute merge-base (single)' \
5be60078
JH
104 'MB=$(git merge-base PL PR) &&
105 expr "$(git name-rev "$MB")" : "[0-9a-f]* tags/C2"'
cd6f207a
LAS
106
107test_expect_success 'compute merge-base (all)' \
5be60078
JH
108 'MB=$(git merge-base --all PL PR) &&
109 expr "$(git name-rev "$MB")" : "[0-9a-f]* tags/C2"'
cd6f207a 110
a7a66921
JH
111# Another set to demonstrate base between one commit and a merge
112# in the documentation.
30ca4ca7
MG
113#
114# * C (MMC) * B (MMB) * A (MMA)
115# * o * o * o
116# * o * o * o
117# * o * o * o
118# * o | _______/
119# | |/
120# | * 1 (MM1)
121# | _______/
122# |/
123# * root (MMR)
124
a7a66921
JH
125
126test_expect_success 'merge-base for octopus-step (setup)' '
127 test_tick && git commit --allow-empty -m root && git tag MMR &&
128 test_tick && git commit --allow-empty -m 1 && git tag MM1 &&
129 test_tick && git commit --allow-empty -m o &&
130 test_tick && git commit --allow-empty -m o &&
131 test_tick && git commit --allow-empty -m o &&
132 test_tick && git commit --allow-empty -m A && git tag MMA &&
133 git checkout MM1 &&
134 test_tick && git commit --allow-empty -m o &&
135 test_tick && git commit --allow-empty -m o &&
136 test_tick && git commit --allow-empty -m o &&
137 test_tick && git commit --allow-empty -m B && git tag MMB &&
138 git checkout MMR &&
139 test_tick && git commit --allow-empty -m o &&
140 test_tick && git commit --allow-empty -m o &&
141 test_tick && git commit --allow-empty -m o &&
142 test_tick && git commit --allow-empty -m o &&
143 test_tick && git commit --allow-empty -m C && git tag MMC
144'
145
146test_expect_success 'merge-base A B C' '
147 MB=$(git merge-base --all MMA MMB MMC) &&
148 MM1=$(git rev-parse --verify MM1) &&
149 test "$MM1" = "$MB"
150'
151
f621a845
MG
152test_expect_success 'merge-base A B C using show-branch' '
153 MB=$(git show-branch --merge-base MMA MMB MMC) &&
154 MMR=$(git rev-parse --verify MMR) &&
155 test "$MMR" = "$MB"
156'
157
a7a66921
JH
158test_expect_success 'criss-cross merge-base for octopus-step (setup)' '
159 git reset --hard MMR &&
160 test_tick && git commit --allow-empty -m 1 && git tag CC1 &&
161 git reset --hard E &&
162 test_tick && git commit --allow-empty -m 2 && git tag CC2 &&
163 test_tick && git merge -s ours CC1 &&
164 test_tick && git commit --allow-empty -m o &&
165 test_tick && git commit --allow-empty -m B && git tag CCB &&
166 git reset --hard CC1 &&
167 test_tick && git merge -s ours CC2 &&
168 test_tick && git commit --allow-empty -m A && git tag CCA
169'
170
171test_expect_success 'merge-base B A^^ A^^2' '
172 MB0=$(git merge-base --all CCB CCA^^ CCA^^2 | sort) &&
173 MB1=$(git rev-parse CC1 CC2 | sort) &&
174 test "$MB0" = "$MB1"
175'
176
53de71f8 177test_done