]>
Commit | Line | Data |
---|---|---|
31b808a0 RT |
1 | #!/bin/sh |
2 | ||
3 | test_description='test refspec written by clone-command' | |
95cf2c01 | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
6 | ||
31b808a0 RT |
7 | . ./test-lib.sh |
8 | ||
9 | test_expect_success 'setup' ' | |
95cf2c01 | 10 | # Make two branches, "main" and "side" |
31b808a0 RT |
11 | echo one >file && |
12 | git add file && | |
13 | git commit -m one && | |
14 | echo two >file && | |
15 | git commit -a -m two && | |
16 | git tag two && | |
17 | echo three >file && | |
18 | git commit -a -m three && | |
19 | git checkout -b side && | |
20 | echo four >file && | |
21 | git commit -a -m four && | |
95cf2c01 | 22 | git checkout main && |
0dab2468 | 23 | git tag five && |
31b808a0 RT |
24 | |
25 | # default clone | |
26 | git clone . dir_all && | |
27 | ||
0dab2468 ÆAB |
28 | # default clone --no-tags |
29 | git clone --no-tags . dir_all_no_tags && | |
30 | ||
95cf2c01 JS |
31 | # default --single that follows HEAD=main |
32 | git clone --single-branch . dir_main && | |
31b808a0 | 33 | |
95cf2c01 JS |
34 | # default --single that follows HEAD=main with no tags |
35 | git clone --single-branch --no-tags . dir_main_no_tags && | |
0dab2468 | 36 | |
31b808a0 RT |
37 | # default --single that follows HEAD=side |
38 | git checkout side && | |
39 | git clone --single-branch . dir_side && | |
40 | ||
41 | # explicit --single that follows side | |
95cf2c01 | 42 | git checkout main && |
31b808a0 RT |
43 | git clone --single-branch --branch side . dir_side2 && |
44 | ||
45 | # default --single with --mirror | |
46 | git clone --single-branch --mirror . dir_mirror && | |
47 | ||
48 | # default --single with --branch and --mirror | |
49 | git clone --single-branch --mirror --branch side . dir_mirror_side && | |
50 | ||
51 | # --single that does not know what branch to follow | |
52 | git checkout two^ && | |
53 | git clone --single-branch . dir_detached && | |
54 | ||
55 | # explicit --single with tag | |
56 | git clone --single-branch --branch two . dir_tag && | |
57 | ||
0dab2468 ÆAB |
58 | # explicit --single with tag and --no-tags |
59 | git clone --single-branch --no-tags --branch two . dir_tag_no_tags && | |
60 | ||
95cf2c01 | 61 | # advance both "main" and "side" branches |
31b808a0 RT |
62 | git checkout side && |
63 | echo five >file && | |
64 | git commit -a -m five && | |
95cf2c01 | 65 | git checkout main && |
31b808a0 RT |
66 | echo six >file && |
67 | git commit -a -m six && | |
68 | ||
69 | # update tag | |
70 | git tag -d two && git tag two | |
71 | ' | |
72 | ||
73 | test_expect_success 'by default all branches will be kept updated' ' | |
74 | ( | |
28d67d9a ÆAB |
75 | cd dir_all && |
76 | git fetch && | |
3d180973 | 77 | git for-each-ref refs/remotes/origin >refs && |
31b808a0 | 78 | sed -e "/HEAD$/d" \ |
3d180973 | 79 | -e "s|/remotes/origin/|/heads/|" refs >../actual |
31b808a0 | 80 | ) && |
95cf2c01 | 81 | # follow both main and side |
31b808a0 RT |
82 | git for-each-ref refs/heads >expect && |
83 | test_cmp expect actual | |
84 | ' | |
85 | ||
86 | test_expect_success 'by default no tags will be kept updated' ' | |
87 | ( | |
28d67d9a ÆAB |
88 | cd dir_all && |
89 | git fetch && | |
31b808a0 RT |
90 | git for-each-ref refs/tags >../actual |
91 | ) && | |
92 | git for-each-ref refs/tags >expect && | |
0813dd28 | 93 | ! test_cmp expect actual && |
0dab2468 ÆAB |
94 | test_line_count = 2 actual |
95 | ' | |
96 | ||
97 | test_expect_success 'clone with --no-tags' ' | |
98 | ( | |
99 | cd dir_all_no_tags && | |
bfa9148f | 100 | grep tagOpt .git/config && |
0dab2468 ÆAB |
101 | git fetch && |
102 | git for-each-ref refs/tags >../actual | |
103 | ) && | |
d3c6751b | 104 | test_must_be_empty actual |
31b808a0 RT |
105 | ' |
106 | ||
95cf2c01 | 107 | test_expect_success '--single-branch while HEAD pointing at main' ' |
31b808a0 | 108 | ( |
95cf2c01 | 109 | cd dir_main && |
0bc8d71b | 110 | git fetch --force && |
3d180973 | 111 | git for-each-ref refs/remotes/origin >refs && |
31b808a0 | 112 | sed -e "/HEAD$/d" \ |
3d180973 | 113 | -e "s|/remotes/origin/|/heads/|" refs >../actual |
31b808a0 | 114 | ) && |
95cf2c01 JS |
115 | # only follow main |
116 | git for-each-ref refs/heads/main >expect && | |
0dab2468 ÆAB |
117 | # get & check latest tags |
118 | test_cmp expect actual && | |
119 | ( | |
95cf2c01 | 120 | cd dir_main && |
0bc8d71b | 121 | git fetch --tags --force && |
0dab2468 ÆAB |
122 | git for-each-ref refs/tags >../actual |
123 | ) && | |
124 | git for-each-ref refs/tags >expect && | |
125 | test_cmp expect actual && | |
126 | test_line_count = 2 actual | |
127 | ' | |
128 | ||
95cf2c01 | 129 | test_expect_success '--single-branch while HEAD pointing at main and --no-tags' ' |
0dab2468 | 130 | ( |
95cf2c01 | 131 | cd dir_main_no_tags && |
0dab2468 | 132 | git fetch && |
3d180973 | 133 | git for-each-ref refs/remotes/origin >refs && |
0dab2468 | 134 | sed -e "/HEAD$/d" \ |
3d180973 | 135 | -e "s|/remotes/origin/|/heads/|" refs >../actual |
0dab2468 | 136 | ) && |
95cf2c01 JS |
137 | # only follow main |
138 | git for-each-ref refs/heads/main >expect && | |
0dab2468 ÆAB |
139 | test_cmp expect actual && |
140 | # get tags (noop) | |
141 | ( | |
95cf2c01 | 142 | cd dir_main_no_tags && |
0dab2468 ÆAB |
143 | git fetch && |
144 | git for-each-ref refs/tags >../actual | |
145 | ) && | |
d3c6751b | 146 | test_must_be_empty actual && |
0dab2468 ÆAB |
147 | test_line_count = 0 actual && |
148 | # get tags with --tags overrides tagOpt | |
149 | ( | |
95cf2c01 | 150 | cd dir_main_no_tags && |
0dab2468 ÆAB |
151 | git fetch --tags && |
152 | git for-each-ref refs/tags >../actual | |
153 | ) && | |
154 | git for-each-ref refs/tags >expect && | |
155 | test_cmp expect actual && | |
156 | test_line_count = 2 actual | |
31b808a0 RT |
157 | ' |
158 | ||
159 | test_expect_success '--single-branch while HEAD pointing at side' ' | |
160 | ( | |
28d67d9a ÆAB |
161 | cd dir_side && |
162 | git fetch && | |
3d180973 | 163 | git for-each-ref refs/remotes/origin >refs && |
31b808a0 | 164 | sed -e "/HEAD$/d" \ |
3d180973 | 165 | -e "s|/remotes/origin/|/heads/|" refs >../actual |
31b808a0 RT |
166 | ) && |
167 | # only follow side | |
168 | git for-each-ref refs/heads/side >expect && | |
169 | test_cmp expect actual | |
170 | ' | |
171 | ||
172 | test_expect_success '--single-branch with explicit --branch side' ' | |
173 | ( | |
28d67d9a ÆAB |
174 | cd dir_side2 && |
175 | git fetch && | |
3d180973 | 176 | git for-each-ref refs/remotes/origin >refs && |
31b808a0 | 177 | sed -e "/HEAD$/d" \ |
3d180973 | 178 | -e "s|/remotes/origin/|/heads/|" refs >../actual |
31b808a0 RT |
179 | ) && |
180 | # only follow side | |
181 | git for-each-ref refs/heads/side >expect && | |
182 | test_cmp expect actual | |
183 | ' | |
184 | ||
185 | test_expect_success '--single-branch with explicit --branch with tag fetches updated tag' ' | |
186 | ( | |
28d67d9a ÆAB |
187 | cd dir_tag && |
188 | git fetch && | |
31b808a0 RT |
189 | git for-each-ref refs/tags >../actual |
190 | ) && | |
191 | git for-each-ref refs/tags >expect && | |
192 | test_cmp expect actual | |
193 | ' | |
194 | ||
0dab2468 ÆAB |
195 | test_expect_success '--single-branch with explicit --branch with tag fetches updated tag despite --no-tags' ' |
196 | ( | |
197 | cd dir_tag_no_tags && | |
198 | git fetch && | |
199 | git for-each-ref refs/tags >../actual | |
200 | ) && | |
201 | git for-each-ref refs/tags/two >expect && | |
202 | test_cmp expect actual && | |
203 | test_line_count = 1 actual | |
204 | ' | |
205 | ||
31b808a0 RT |
206 | test_expect_success '--single-branch with --mirror' ' |
207 | ( | |
28d67d9a ÆAB |
208 | cd dir_mirror && |
209 | git fetch && | |
31b808a0 RT |
210 | git for-each-ref refs > ../actual |
211 | ) && | |
212 | git for-each-ref refs >expect && | |
213 | test_cmp expect actual | |
214 | ' | |
215 | ||
216 | test_expect_success '--single-branch with explicit --branch and --mirror' ' | |
217 | ( | |
28d67d9a ÆAB |
218 | cd dir_mirror_side && |
219 | git fetch && | |
31b808a0 RT |
220 | git for-each-ref refs > ../actual |
221 | ) && | |
222 | git for-each-ref refs >expect && | |
223 | test_cmp expect actual | |
224 | ' | |
225 | ||
226 | test_expect_success '--single-branch with detached' ' | |
227 | ( | |
28d67d9a ÆAB |
228 | cd dir_detached && |
229 | git fetch && | |
3d180973 | 230 | git for-each-ref refs/remotes/origin >refs && |
31b808a0 | 231 | sed -e "/HEAD$/d" \ |
3d180973 | 232 | -e "s|/remotes/origin/|/heads/|" refs >../actual |
60687de5 | 233 | ) && |
31b808a0 | 234 | # nothing |
d3c6751b | 235 | test_must_be_empty actual |
31b808a0 RT |
236 | ' |
237 | ||
238 | test_done |