Merge branch 'tb/commit-graph-genv2-upgrade-fix' into maint
[git/debian.git] / t / t5503-tagfollow.sh
blob195fc64dd44ae74c1546698e111f1a19c07dbb04
1 #!/bin/sh
3 test_description='test automatic tag following'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 . ./test-lib.sh
10 # End state of the repository:
12 # T - tag1 S - tag2
13 # / /
14 # L - A ------ O ------ B
15 # \ \ \
16 # \ C - origin/cat \
17 # origin/main main
19 test_expect_success setup '
20 test_tick &&
21 echo ichi >file &&
22 git add file &&
23 git commit -m L &&
24 L=$(git rev-parse --verify HEAD) &&
27 mkdir cloned &&
28 cd cloned &&
29 git init-db &&
30 git remote add -f origin ..
31 ) &&
33 test_tick &&
34 echo A >file &&
35 git add file &&
36 git commit -m A &&
37 A=$(git rev-parse --verify HEAD)
40 U=UPLOAD_LOG
41 UPATH="$(pwd)/$U"
43 test_expect_success 'setup expect' '
44 cat - <<EOF >expect
45 want $A
46 EOF
49 get_needs () {
50 test -s "$1" &&
51 perl -alne '
52 next unless $F[1] eq "upload-pack<";
53 next unless $F[2] eq "want";
54 print $F[2], " ", $F[3];
55 ' "$1"
58 test_expect_success 'fetch A (new commit : 1 connection)' '
59 rm -f $U &&
61 cd cloned &&
62 GIT_TRACE_PACKET=$UPATH git fetch &&
63 test $A = $(git rev-parse --verify origin/main)
64 ) &&
65 get_needs $U >actual &&
66 test_cmp expect actual
69 test_expect_success "create tag T on A, create C on branch cat" '
70 git tag -a -m tag1 tag1 $A &&
71 T=$(git rev-parse --verify tag1) &&
73 git checkout -b cat &&
74 echo C >file &&
75 git add file &&
76 git commit -m C &&
77 C=$(git rev-parse --verify HEAD) &&
78 git checkout main
81 test_expect_success 'setup expect' '
82 cat - <<EOF >expect
83 want $C
84 want $T
85 EOF
88 test_expect_success 'fetch C, T (new branch, tag : 1 connection)' '
89 rm -f $U &&
91 cd cloned &&
92 GIT_TRACE_PACKET=$UPATH git fetch &&
93 test $C = $(git rev-parse --verify origin/cat) &&
94 test $T = $(git rev-parse --verify tag1) &&
95 test $A = $(git rev-parse --verify tag1^0)
96 ) &&
97 get_needs $U >actual &&
98 test_cmp expect actual
101 test_expect_success "create commits O, B, tag S on B" '
102 test_tick &&
103 echo O >file &&
104 git add file &&
105 git commit -m O &&
107 test_tick &&
108 echo B >file &&
109 git add file &&
110 git commit -m B &&
111 B=$(git rev-parse --verify HEAD) &&
113 git tag -a -m tag2 tag2 $B &&
114 S=$(git rev-parse --verify tag2)
117 test_expect_success 'setup expect' '
118 cat - <<EOF >expect
119 want $B
120 want $S
124 test_expect_success 'fetch B, S (commit and tag : 1 connection)' '
125 rm -f $U &&
127 cd cloned &&
128 GIT_TRACE_PACKET=$UPATH git fetch &&
129 test $B = $(git rev-parse --verify origin/main) &&
130 test $B = $(git rev-parse --verify tag2^0) &&
131 test $S = $(git rev-parse --verify tag2)
132 ) &&
133 get_needs $U >actual &&
134 test_cmp expect actual
137 test_expect_success 'setup expect' '
138 cat - <<EOF >expect
139 want $B
140 want $S
144 test_expect_success 'new clone fetch main and tags' '
145 test_might_fail git branch -D cat &&
146 rm -f $U &&
148 mkdir clone2 &&
149 cd clone2 &&
150 git init &&
151 git remote add origin .. &&
152 GIT_TRACE_PACKET=$UPATH git fetch &&
153 test $B = $(git rev-parse --verify origin/main) &&
154 test $S = $(git rev-parse --verify tag2) &&
155 test $B = $(git rev-parse --verify tag2^0) &&
156 test $T = $(git rev-parse --verify tag1) &&
157 test $A = $(git rev-parse --verify tag1^0)
158 ) &&
159 get_needs $U >actual &&
160 test_cmp expect actual
163 test_done