tests: make scripts executable
[git] / t / t5500-fetch-pack.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Johannes Schindelin
4 #
5
6 test_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
15 function show_count () {
16         commit_count=$(($commit_count+1))
17         printf "      %d\r" $commit_count
18 }
19
20 function add () {
21         local name=$1
22         local text="$@"
23         local branch=${name:0:1}
24         local parents=""
25
26         shift
27         while test $1; do
28                 parents="$parents -p $1"
29                 shift
30         done
31
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 }
43
44 function count_objects () {
45         ls .git/objects/??/* 2>>log2.txt | wc -l | tr -d " "
46 }
47
48 function test_expect_object_count () {
49         local message=$1
50         local count=$2
51
52         output="$(count_objects)"
53         test_expect_success \
54                 "new object count $message" \
55                 "test $count = $output"
56 }
57
58 function test_repack () {
59         local rep=$1
60
61         test_expect_success "repack && prune-packed in $rep" \
62                 '(git-repack && git-prune-packed)2>>log.txt'
63 }
64
65 function pull_to_client () {
66         local number=$1
67         local heads=$2
68         local count=$3
69         local no_strict_count_check=$4
70
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 Packing 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 }
89
90 # Here begins the actual testing
91
92 # A1 - ... - A20 - A21
93 #    \
94 #      B1  -   B2 - .. - B70
95
96 # client pulls A20, B1. Then tracks only B. Then pulls A.
97
98 (
99         mkdir client &&
100         cd client &&
101         git-init-db 2>> log2.txt
102 )
103
104 add A1
105
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
111
112 add B1 $A1
113
114 echo $ATIP > .git/refs/heads/A
115 echo $BTIP > .git/refs/heads/B
116 git-symbolic-ref HEAD refs/heads/B
117
118 pull_to_client 1st "B A" $((11*3))
119
120 (cd client; test_repack client)
121
122 add A11 $A10
123
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
129
130 pull_to_client 2nd "B" $((64*3))
131
132 (cd client; test_repack client)
133
134 pull_to_client 3rd "A" $((1*3)) # old fails
135
136 test_done