Code

git-commit --amend
[git.git] / t / t5500-fetch-pack.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Johannes Schindelin
4 #
6 test_description='Testing multi_ack pack fetching
8 '
9 . ./test-lib.sh
11 # Test fetch-pack/upload-pack pair.
13 # Some convenience functions
15 function show_count () {
16         commit_count=$(($commit_count+1))
17         printf "      %d\r" $commit_count
18 }
20 function add () {
21         local name=$1
22         local text="$@"
23         local branch=${name:0:1}
24         local parents=""
26         shift
27         while test $1; do
28                 parents="$parents -p $1"
29                 shift
30         done
32         echo "$text" > test.txt
33         git-update-index --add test.txt
34         tree=$(git-write-tree)
35         # make sure timestamps are in correct order
36         sec=$(($sec+1))
37         commit=$(echo "$text" | GIT_AUTHOR_DATE=$sec \
38                 git-commit-tree $tree $parents 2>>log2.txt)
39         export $name=$commit
40         echo $commit > .git/refs/heads/$branch
41         eval ${branch}TIP=$commit
42 }
44 function count_objects () {
45         ls .git/objects/??/* 2>>log2.txt | wc -l | tr -d " "
46 }
48 function test_expect_object_count () {
49         local message=$1
50         local count=$2
52         output="$(count_objects)"
53         test_expect_success \
54                 "new object count $message" \
55                 "test $count = $output"
56 }
58 function test_repack () {
59         local rep=$1
61         test_expect_success "repack && prune-packed in $rep" \
62                 '(git-repack && git-prune-packed)2>>log.txt'
63 }
65 function pull_to_client () {
66         local number=$1
67         local heads=$2
68         local count=$3
69         local no_strict_count_check=$4
71         cd client
72         test_expect_success "$number pull" \
73                 "git-fetch-pack -v .. $heads > log.txt 2>&1"
74         case "$heads" in *A*) echo $ATIP > .git/refs/heads/A;; esac
75         case "$heads" in *B*) echo $BTIP > .git/refs/heads/B;; esac
76         git-symbolic-ref HEAD refs/heads/${heads:0:1}
77         test_expect_success "fsck" 'git-fsck-objects --full > fsck.txt 2>&1'
78         test_expect_object_count "after $number pull" $count
79         pack_count=$(grep Unpacking log.txt|tr -dc "0-9")
80         test -z "$pack_count" && pack_count=0
81         if [ -z "$no_strict_count_check" ]; then
82                 test_expect_success "minimal count" "test $count = $pack_count"
83         else
84                 test $count != $pack_count && \
85                         echo "WARNING: $pack_count objects transmitted, only $count of which were needed"
86         fi
87         cd ..
88 }
90 # Here begins the actual testing
92 # A1 - ... - A20 - A21
93 #    \
94 #      B1  -   B2 - .. - B70
96 # client pulls A20, B1. Then tracks only B. Then pulls A.
98 (
99         mkdir client &&
100         cd client &&
101         git-init-db 2>> log2.txt
104 add A1
106 prev=1; cur=2; while [ $cur -le 10 ]; do
107         add A$cur $(eval echo \$A$prev)
108         prev=$cur
109         cur=$(($cur+1))
110 done
112 add B1 $A1
114 echo $ATIP > .git/refs/heads/A
115 echo $BTIP > .git/refs/heads/B
116 git-symbolic-ref HEAD refs/heads/B
118 pull_to_client 1st "B A" $((11*3))
120 (cd client; test_repack client)
122 add A11 $A10
124 prev=1; cur=2; while [ $cur -le 65 ]; do
125         add B$cur $(eval echo \$B$prev)
126         prev=$cur
127         cur=$(($cur+1))
128 done
130 pull_to_client 2nd "B" $((64*3))
132 (cd client; test_repack client)
134 pull_to_client 3rd "A" $((1*3)) # old fails
136 test_done