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