t / t6010-merge-base.shon commit git-gc --auto: run "repack -A -d -l" as necessary. (1781550)
   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
  11T=$(git write-tree)
  12
  13M=1130000000
  14Z=+0000
  15
  16export GIT_COMMITTER_EMAIL=git@comm.iter.xz
  17export GIT_COMMITTER_NAME='C O Mmiter'
  18export GIT_AUTHOR_NAME='A U Thor'
  19export GIT_AUTHOR_EMAIL=git@au.thor.xz
  20
  21doit() {
  22        OFFSET=$1; shift
  23        NAME=$1; shift
  24        PARENTS=
  25        for P
  26        do
  27                PARENTS="${PARENTS}-p $P "
  28        done
  29        GIT_COMMITTER_DATE="$(($M + $OFFSET)) $Z"
  30        GIT_AUTHOR_DATE=$GIT_COMMITTER_DATE
  31        export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
  32        commit=$(echo $NAME | git commit-tree $T $PARENTS)
  33        echo $commit >.git/refs/tags/$NAME
  34        echo $commit
  35}
  36
  37#  E---D---C---B---A
  38#  \'-_         \   \
  39#   \  `---------G   \
  40#    \                \
  41#     F----------------H
  42
  43# Setup...
  44E=$(doit 5 E)
  45D=$(doit 4 D $E)
  46F=$(doit 6 F $E)
  47C=$(doit 3 C $D)
  48B=$(doit 2 B $C)
  49A=$(doit 1 A $B)
  50G=$(doit 7 G $B $E)
  51H=$(doit 8 H $A $F)
  52
  53test_expect_success 'compute merge-base (single)' \
  54    'MB=$(git merge-base G H) &&
  55     expr "$(git name-rev "$MB")" : "[0-9a-f]* tags/B"'
  56
  57test_expect_success 'compute merge-base (all)' \
  58    'MB=$(git merge-base --all G H) &&
  59     expr "$(git name-rev "$MB")" : "[0-9a-f]* tags/B"'
  60
  61test_expect_success 'compute merge-base with show-branch' \
  62    'MB=$(git show-branch --merge-base G H) &&
  63     expr "$(git name-rev "$MB")" : "[0-9a-f]* tags/B"'
  64
  65# Setup for second test to demonstrate that relying on timestamps in a
  66# distributed SCM to provide a _consistent_ partial ordering of commits
  67# leads to insanity.
  68#
  69#               Relative
  70# Structure     timestamps
  71#
  72#   PL  PR        +4  +4
  73#  /  \/  \      /  \/  \
  74# L2  C2  R2    +3  -1  +3
  75# |   |   |     |   |   |
  76# L1  C1  R1    +2  -2  +2
  77# |   |   |     |   |   |
  78# L0  C0  R0    +1  -3  +1
  79#   \ |  /        \ |  /
  80#     S             0
  81#
  82# The left and right chains of commits can be of any length and complexity as
  83# long as all of the timestamps are greater than that of S.
  84
  85S=$(doit  0 S)
  86
  87C0=$(doit -3 C0 $S)
  88C1=$(doit -2 C1 $C0)
  89C2=$(doit -1 C2 $C1)
  90
  91L0=$(doit  1 L0 $S)
  92L1=$(doit  2 L1 $L0)
  93L2=$(doit  3 L2 $L1)
  94
  95R0=$(doit  1 R0 $S)
  96R1=$(doit  2 R1 $R0)
  97R2=$(doit  3 R2 $R1)
  98
  99PL=$(doit  4 PL $L2 $C2)
 100PR=$(doit  4 PR $C2 $R2)
 101
 102test_expect_success 'compute merge-base (single)' \
 103    'MB=$(git merge-base PL PR) &&
 104     expr "$(git name-rev "$MB")" : "[0-9a-f]* tags/C2"'
 105
 106test_expect_success 'compute merge-base (all)' \
 107    'MB=$(git merge-base --all PL PR) &&
 108     expr "$(git name-rev "$MB")" : "[0-9a-f]* tags/C2"'
 109
 110test_done