Merge branch 'ja/doc-synopsis-markup'
[git/gitster.git] / t / t5503-tagfollow.sh
blob5ebbaa489689dce28d1b47e16b73e19e25183c5f
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_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 # End state of the repository:
13 # T - tag1 S - tag2
14 # / /
15 # L - A ------ O ------ B
16 # \ \ \
17 # \ C - origin/cat \
18 # origin/main main
20 test_expect_success setup '
21 test_tick &&
22 echo ichi >file &&
23 git add file &&
24 git commit -m L &&
25 L=$(git rev-parse --verify HEAD) &&
28 mkdir cloned &&
29 cd cloned &&
30 git init-db &&
31 git remote add -f origin ..
32 ) &&
34 test_tick &&
35 echo A >file &&
36 git add file &&
37 git commit -m A &&
38 A=$(git rev-parse --verify HEAD)
41 U=UPLOAD_LOG
42 UPATH="$(pwd)/$U"
44 test_expect_success 'setup expect' '
45 cat - <<EOF >expect
46 want $A
47 EOF
50 get_needs () {
51 test -s "$1" &&
52 perl -alne '
53 next unless $F[1] eq "upload-pack<";
54 next unless $F[2] eq "want";
55 print $F[2], " ", $F[3];
56 ' "$1"
59 test_expect_success 'fetch A (new commit : 1 connection)' '
60 rm -f $U &&
62 cd cloned &&
63 GIT_TRACE_PACKET=$UPATH git fetch &&
64 test $A = $(git rev-parse --verify origin/main)
65 ) &&
66 get_needs $U >actual &&
67 test_cmp expect actual
70 test_expect_success "create tag T on A, create C on branch cat" '
71 git tag -a -m tag1 tag1 $A &&
72 T=$(git rev-parse --verify tag1) &&
74 git checkout -b cat &&
75 echo C >file &&
76 git add file &&
77 git commit -m C &&
78 C=$(git rev-parse --verify HEAD) &&
79 git checkout main
82 test_expect_success 'setup expect' '
83 cat - <<EOF >expect
84 want $C
85 want $T
86 EOF
89 test_expect_success 'fetch C, T (new branch, tag : 1 connection)' '
90 rm -f $U &&
92 cd cloned &&
93 GIT_TRACE_PACKET=$UPATH git fetch &&
94 test $C = $(git rev-parse --verify origin/cat) &&
95 test $T = $(git rev-parse --verify tag1) &&
96 test $A = $(git rev-parse --verify tag1^0)
97 ) &&
98 get_needs $U >actual &&
99 test_cmp expect actual
102 test_expect_success "create commits O, B, tag S on B" '
103 test_tick &&
104 echo O >file &&
105 git add file &&
106 git commit -m O &&
108 test_tick &&
109 echo B >file &&
110 git add file &&
111 git commit -m B &&
112 B=$(git rev-parse --verify HEAD) &&
114 git tag -a -m tag2 tag2 $B &&
115 S=$(git rev-parse --verify tag2)
118 test_expect_success 'setup expect' '
119 cat - <<EOF >expect
120 want $B
121 want $S
125 test_expect_success 'fetch B, S (commit and tag : 1 connection)' '
126 rm -f $U &&
128 cd cloned &&
129 GIT_TRACE_PACKET=$UPATH git fetch &&
130 test $B = $(git rev-parse --verify origin/main) &&
131 test $B = $(git rev-parse --verify tag2^0) &&
132 test $S = $(git rev-parse --verify tag2)
133 ) &&
134 get_needs $U >actual &&
135 test_cmp expect actual
138 test_expect_success 'setup expect' '
139 cat - <<EOF >expect
140 want $B
141 want $S
145 test_expect_success 'new clone fetch main and tags' '
146 test_might_fail git branch -D cat &&
147 rm -f $U &&
149 mkdir clone2 &&
150 cd clone2 &&
151 git init &&
152 git remote add origin .. &&
153 GIT_TRACE_PACKET=$UPATH git fetch &&
154 test $B = $(git rev-parse --verify origin/main) &&
155 test $S = $(git rev-parse --verify tag2) &&
156 test $B = $(git rev-parse --verify tag2^0) &&
157 test $T = $(git rev-parse --verify tag1) &&
158 test $A = $(git rev-parse --verify tag1^0)
159 ) &&
160 get_needs $U >actual &&
161 test_cmp expect actual
164 test_done