t / t5503-tagfollow.shon commit Merge branch 'lp/typofixes' (3241d4f)
   1#!/bin/sh
   2
   3test_description='test automatic tag following'
   4
   5. ./test-lib.sh
   6
   7# End state of the repository:
   8#
   9#         T - tag1          S - tag2
  10#        /                 /
  11#   L - A ------ O ------ B
  12#    \   \                 \
  13#     \   C - origin/cat    \
  14#      origin/master         master
  15
  16test_expect_success setup '
  17        test_tick &&
  18        echo ichi >file &&
  19        git add file &&
  20        git commit -m L &&
  21        L=$(git rev-parse --verify HEAD) &&
  22
  23        (
  24                mkdir cloned &&
  25                cd cloned &&
  26                git init-db &&
  27                git remote add -f origin ..
  28        ) &&
  29
  30        test_tick &&
  31        echo A >file &&
  32        git add file &&
  33        git commit -m A &&
  34        A=$(git rev-parse --verify HEAD)
  35'
  36
  37U=UPLOAD_LOG
  38UPATH="$(pwd)/$U"
  39
  40test_expect_success 'setup expect' '
  41cat - <<EOF >expect
  42want $A
  43EOF
  44'
  45
  46get_needs () {
  47        test -s "$1" &&
  48        perl -alne '
  49                next unless $F[1] eq "upload-pack<";
  50                last if $F[2] eq "0000";
  51                print $F[2], " ", $F[3];
  52        ' "$1"
  53}
  54
  55test_expect_success 'fetch A (new commit : 1 connection)' '
  56        rm -f $U &&
  57        (
  58                cd cloned &&
  59                GIT_TRACE_PACKET=$UPATH git fetch &&
  60                test $A = $(git rev-parse --verify origin/master)
  61        ) &&
  62        get_needs $U >actual &&
  63        test_cmp expect actual
  64'
  65
  66test_expect_success "create tag T on A, create C on branch cat" '
  67        git tag -a -m tag1 tag1 $A &&
  68        T=$(git rev-parse --verify tag1) &&
  69
  70        git checkout -b cat &&
  71        echo C >file &&
  72        git add file &&
  73        git commit -m C &&
  74        C=$(git rev-parse --verify HEAD) &&
  75        git checkout master
  76'
  77
  78test_expect_success 'setup expect' '
  79cat - <<EOF >expect
  80want $C
  81want $T
  82EOF
  83'
  84
  85test_expect_success 'fetch C, T (new branch, tag : 1 connection)' '
  86        rm -f $U &&
  87        (
  88                cd cloned &&
  89                GIT_TRACE_PACKET=$UPATH git fetch &&
  90                test $C = $(git rev-parse --verify origin/cat) &&
  91                test $T = $(git rev-parse --verify tag1) &&
  92                test $A = $(git rev-parse --verify tag1^0)
  93        ) &&
  94        get_needs $U >actual &&
  95        test_cmp expect actual
  96'
  97
  98test_expect_success "create commits O, B, tag S on B" '
  99        test_tick &&
 100        echo O >file &&
 101        git add file &&
 102        git commit -m O &&
 103
 104        test_tick &&
 105        echo B >file &&
 106        git add file &&
 107        git commit -m B &&
 108        B=$(git rev-parse --verify HEAD) &&
 109
 110        git tag -a -m tag2 tag2 $B &&
 111        S=$(git rev-parse --verify tag2)
 112'
 113
 114test_expect_success 'setup expect' '
 115cat - <<EOF >expect
 116want $B
 117want $S
 118EOF
 119'
 120
 121test_expect_success 'fetch B, S (commit and tag : 1 connection)' '
 122        rm -f $U &&
 123        (
 124                cd cloned &&
 125                GIT_TRACE_PACKET=$UPATH git fetch &&
 126                test $B = $(git rev-parse --verify origin/master) &&
 127                test $B = $(git rev-parse --verify tag2^0) &&
 128                test $S = $(git rev-parse --verify tag2)
 129        ) &&
 130        get_needs $U >actual &&
 131        test_cmp expect actual
 132'
 133
 134test_expect_success 'setup expect' '
 135cat - <<EOF >expect
 136want $B
 137want $S
 138EOF
 139'
 140
 141test_expect_success 'new clone fetch master and tags' '
 142        test_might_fail git branch -D cat &&
 143        rm -f $U &&
 144        (
 145                mkdir clone2 &&
 146                cd clone2 &&
 147                git init &&
 148                git remote add origin .. &&
 149                GIT_TRACE_PACKET=$UPATH git fetch &&
 150                test $B = $(git rev-parse --verify origin/master) &&
 151                test $S = $(git rev-parse --verify tag2) &&
 152                test $B = $(git rev-parse --verify tag2^0) &&
 153                test $T = $(git rev-parse --verify tag1) &&
 154                test $A = $(git rev-parse --verify tag1^0)
 155        ) &&
 156        get_needs $U >actual &&
 157        test_cmp expect actual
 158'
 159
 160test_done