t3400-rebase: Move detached HEAD check earlier
[git/git-bigfiles.git] / t / t6010-merge-base.sh
blob04e4b7c5c2aa4f7c6922ebc5c9236962ab5d175c
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='Merge base computation.
9 . ./test-lib.sh
11 T=$(git write-tree)
13 M=1130000000
14 Z=+0000
16 GIT_COMMITTER_EMAIL=git@comm.iter.xz
17 GIT_COMMITTER_NAME='C O Mmiter'
18 GIT_AUTHOR_NAME='A U Thor'
19 GIT_AUTHOR_EMAIL=git@au.thor.xz
20 export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
22 doit() {
23 OFFSET=$1; shift
24 NAME=$1; shift
25 PARENTS=
26 for P
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
33 commit=$(echo $NAME | git commit-tree $T $PARENTS)
34 echo $commit >.git/refs/tags/$NAME
35 echo $commit
38 # E---D---C---B---A
39 # \'-_ \ \
40 # \ `---------G \
41 # \ \
42 # F----------------H
44 # Setup...
45 E=$(doit 5 E)
46 D=$(doit 4 D $E)
47 F=$(doit 6 F $E)
48 C=$(doit 3 C $D)
49 B=$(doit 2 B $C)
50 A=$(doit 1 A $B)
51 G=$(doit 7 G $B $E)
52 H=$(doit 8 H $A $F)
54 test_expect_success 'compute merge-base (single)' \
55 'MB=$(git merge-base G H) &&
56 expr "$(git name-rev "$MB")" : "[0-9a-f]* tags/B"'
58 test_expect_success 'compute merge-base (all)' \
59 'MB=$(git merge-base --all G H) &&
60 expr "$(git name-rev "$MB")" : "[0-9a-f]* tags/B"'
62 test_expect_success 'compute merge-base with show-branch' \
63 'MB=$(git show-branch --merge-base G H) &&
64 expr "$(git name-rev "$MB")" : "[0-9a-f]* tags/B"'
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.
70 # Relative
71 # Structure timestamps
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
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.
86 S=$(doit 0 S)
88 C0=$(doit -3 C0 $S)
89 C1=$(doit -2 C1 $C0)
90 C2=$(doit -1 C2 $C1)
92 L0=$(doit 1 L0 $S)
93 L1=$(doit 2 L1 $L0)
94 L2=$(doit 3 L2 $L1)
96 R0=$(doit 1 R0 $S)
97 R1=$(doit 2 R1 $R0)
98 R2=$(doit 3 R2 $R1)
100 PL=$(doit 4 PL $L2 $C2)
101 PR=$(doit 4 PR $C2 $R2)
103 test_expect_success 'compute merge-base (single)' \
104 'MB=$(git merge-base PL PR) &&
105 expr "$(git name-rev "$MB")" : "[0-9a-f]* tags/C2"'
107 test_expect_success 'compute merge-base (all)' \
108 'MB=$(git merge-base --all PL PR) &&
109 expr "$(git name-rev "$MB")" : "[0-9a-f]* tags/C2"'
111 # Another set to demonstrate base between one commit and a merge
112 # in the documentation.
114 test_expect_success 'merge-base for octopus-step (setup)' '
115 test_tick && git commit --allow-empty -m root && git tag MMR &&
116 test_tick && git commit --allow-empty -m 1 && git tag MM1 &&
117 test_tick && git commit --allow-empty -m o &&
118 test_tick && git commit --allow-empty -m o &&
119 test_tick && git commit --allow-empty -m o &&
120 test_tick && git commit --allow-empty -m A && git tag MMA &&
121 git checkout MM1 &&
122 test_tick && git commit --allow-empty -m o &&
123 test_tick && git commit --allow-empty -m o &&
124 test_tick && git commit --allow-empty -m o &&
125 test_tick && git commit --allow-empty -m B && git tag MMB &&
126 git checkout MMR &&
127 test_tick && git commit --allow-empty -m o &&
128 test_tick && git commit --allow-empty -m o &&
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 C && git tag MMC
134 test_expect_success 'merge-base A B C' '
135 MB=$(git merge-base --all MMA MMB MMC) &&
136 MM1=$(git rev-parse --verify MM1) &&
137 test "$MM1" = "$MB"
140 test_expect_success 'criss-cross merge-base for octopus-step (setup)' '
141 git reset --hard MMR &&
142 test_tick && git commit --allow-empty -m 1 && git tag CC1 &&
143 git reset --hard E &&
144 test_tick && git commit --allow-empty -m 2 && git tag CC2 &&
145 test_tick && git merge -s ours CC1 &&
146 test_tick && git commit --allow-empty -m o &&
147 test_tick && git commit --allow-empty -m B && git tag CCB &&
148 git reset --hard CC1 &&
149 test_tick && git merge -s ours CC2 &&
150 test_tick && git commit --allow-empty -m A && git tag CCA
153 test_expect_success 'merge-base B A^^ A^^2' '
154 MB0=$(git merge-base --all CCB CCA^^ CCA^^2 | sort) &&
155 MB1=$(git rev-parse CC1 CC2 | sort) &&
156 test "$MB0" = "$MB1"
159 test_done