t / t5500-fetch-pack.shon commit Merge branch 'lt/logopt' into next (524765e)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Johannes Schindelin
   4#
   5
   6test_description='Testing multi_ack pack fetching
   7
   8'
   9. ./test-lib.sh
  10
  11# Test fetch-pack/upload-pack pair.
  12
  13# Some convenience functions
  14
  15function add () {
  16        local name=$1
  17        local text="$@"
  18        local branch=${name:0:1}
  19        local parents=""
  20
  21        shift
  22        while test $1; do
  23                parents="$parents -p $1"
  24                shift
  25        done
  26
  27        echo "$text" > test.txt
  28        git-update-index --add test.txt
  29        tree=$(git-write-tree)
  30        # make sure timestamps are in correct order
  31        sec=$(($sec+1))
  32        commit=$(echo "$text" | GIT_AUTHOR_DATE=$sec \
  33                git-commit-tree $tree $parents 2>>log2.txt)
  34        export $name=$commit
  35        echo $commit > .git/refs/heads/$branch
  36        eval ${branch}TIP=$commit
  37}
  38
  39function count_objects () {
  40        ls .git/objects/??/* 2>>log2.txt | wc -l | tr -d " "
  41}
  42
  43function test_expect_object_count () {
  44        local message=$1
  45        local count=$2
  46
  47        output="$(count_objects)"
  48        test_expect_success \
  49                "new object count $message" \
  50                "test $count = $output"
  51}
  52
  53function pull_to_client () {
  54        local number=$1
  55        local heads=$2
  56        local count=$3
  57        local no_strict_count_check=$4
  58
  59        cd client
  60        test_expect_success "$number pull" \
  61                "git-fetch-pack -k -v .. $heads"
  62        case "$heads" in *A*) echo $ATIP > .git/refs/heads/A;; esac
  63        case "$heads" in *B*) echo $BTIP > .git/refs/heads/B;; esac
  64        git-symbolic-ref HEAD refs/heads/${heads:0:1}
  65
  66        test_expect_success "fsck" 'git-fsck-objects --full > fsck.txt 2>&1'
  67
  68        test_expect_success 'check downloaded results' \
  69        'mv .git/objects/pack/pack-* . &&
  70         p=`ls -1 pack-*.pack` &&
  71         git-unpack-objects <$p &&
  72         git-fsck-objects --full'
  73
  74        test_expect_success "new object count after $number pull" \
  75        'idx=`echo pack-*.idx` &&
  76         pack_count=`git-show-index <$idx | wc -l` &&
  77         test $pack_count = $count'
  78        test -z "$pack_count" && pack_count=0
  79        if [ -z "$no_strict_count_check" ]; then
  80                test_expect_success "minimal count" "test $count = $pack_count"
  81        else
  82                test $count != $pack_count && \
  83                        echo "WARNING: $pack_count objects transmitted, only $count of which were needed"
  84        fi
  85        rm -f pack-*
  86        cd ..
  87}
  88
  89# Here begins the actual testing
  90
  91# A1 - ... - A20 - A21
  92#    \
  93#      B1  -   B2 - .. - B70
  94
  95# client pulls A20, B1. Then tracks only B. Then pulls A.
  96
  97(
  98        mkdir client &&
  99        cd client &&
 100        git-init-db 2>> log2.txt
 101)
 102
 103add A1
 104
 105prev=1; cur=2; while [ $cur -le 10 ]; do
 106        add A$cur $(eval echo \$A$prev)
 107        prev=$cur
 108        cur=$(($cur+1))
 109done
 110
 111add B1 $A1
 112
 113echo $ATIP > .git/refs/heads/A
 114echo $BTIP > .git/refs/heads/B
 115git-symbolic-ref HEAD refs/heads/B
 116
 117pull_to_client 1st "B A" $((11*3))
 118
 119add A11 $A10
 120
 121prev=1; cur=2; while [ $cur -le 65 ]; do
 122        add B$cur $(eval echo \$B$prev)
 123        prev=$cur
 124        cur=$(($cur+1))
 125done
 126
 127pull_to_client 2nd "B" $((64*3))
 128
 129pull_to_client 3rd "A" $((1*3)) # old fails
 130
 131test_done