]>
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 && | |
100 | git fetch && | |
101 | git for-each-ref refs/tags >../actual | |
102 | ) && | |
d3c6751b | 103 | test_must_be_empty actual |
31b808a0 RT |
104 | ' |
105 | ||
95cf2c01 | 106 | test_expect_success '--single-branch while HEAD pointing at main' ' |
31b808a0 | 107 | ( |
95cf2c01 | 108 | cd dir_main && |
0bc8d71b | 109 | git fetch --force && |
3d180973 | 110 | git for-each-ref refs/remotes/origin >refs && |
31b808a0 | 111 | sed -e "/HEAD$/d" \ |
3d180973 | 112 | -e "s|/remotes/origin/|/heads/|" refs >../actual |
31b808a0 | 113 | ) && |
95cf2c01 JS |
114 | # only follow main |
115 | git for-each-ref refs/heads/main >expect && | |
0dab2468 ÆAB |
116 | # get & check latest tags |
117 | test_cmp expect actual && | |
118 | ( | |
95cf2c01 | 119 | cd dir_main && |
0bc8d71b | 120 | git fetch --tags --force && |
0dab2468 ÆAB |
121 | git for-each-ref refs/tags >../actual |
122 | ) && | |
123 | git for-each-ref refs/tags >expect && | |
124 | test_cmp expect actual && | |
125 | test_line_count = 2 actual | |
126 | ' | |
127 | ||
95cf2c01 | 128 | test_expect_success '--single-branch while HEAD pointing at main and --no-tags' ' |
0dab2468 | 129 | ( |
95cf2c01 | 130 | cd dir_main_no_tags && |
0dab2468 | 131 | git fetch && |
3d180973 | 132 | git for-each-ref refs/remotes/origin >refs && |
0dab2468 | 133 | sed -e "/HEAD$/d" \ |
3d180973 | 134 | -e "s|/remotes/origin/|/heads/|" refs >../actual |
0dab2468 | 135 | ) && |
95cf2c01 JS |
136 | # only follow main |
137 | git for-each-ref refs/heads/main >expect && | |
0dab2468 ÆAB |
138 | test_cmp expect actual && |
139 | # get tags (noop) | |
140 | ( | |
95cf2c01 | 141 | cd dir_main_no_tags && |
0dab2468 ÆAB |
142 | git fetch && |
143 | git for-each-ref refs/tags >../actual | |
144 | ) && | |
d3c6751b | 145 | test_must_be_empty actual && |
0dab2468 ÆAB |
146 | test_line_count = 0 actual && |
147 | # get tags with --tags overrides tagOpt | |
148 | ( | |
95cf2c01 | 149 | cd dir_main_no_tags && |
0dab2468 ÆAB |
150 | git fetch --tags && |
151 | git for-each-ref refs/tags >../actual | |
152 | ) && | |
153 | git for-each-ref refs/tags >expect && | |
154 | test_cmp expect actual && | |
155 | test_line_count = 2 actual | |
31b808a0 RT |
156 | ' |
157 | ||
158 | test_expect_success '--single-branch while HEAD pointing at side' ' | |
159 | ( | |
28d67d9a ÆAB |
160 | cd dir_side && |
161 | git fetch && | |
3d180973 | 162 | git for-each-ref refs/remotes/origin >refs && |
31b808a0 | 163 | sed -e "/HEAD$/d" \ |
3d180973 | 164 | -e "s|/remotes/origin/|/heads/|" refs >../actual |
31b808a0 RT |
165 | ) && |
166 | # only follow side | |
167 | git for-each-ref refs/heads/side >expect && | |
168 | test_cmp expect actual | |
169 | ' | |
170 | ||
171 | test_expect_success '--single-branch with explicit --branch side' ' | |
172 | ( | |
28d67d9a ÆAB |
173 | cd dir_side2 && |
174 | git fetch && | |
3d180973 | 175 | git for-each-ref refs/remotes/origin >refs && |
31b808a0 | 176 | sed -e "/HEAD$/d" \ |
3d180973 | 177 | -e "s|/remotes/origin/|/heads/|" refs >../actual |
31b808a0 RT |
178 | ) && |
179 | # only follow side | |
180 | git for-each-ref refs/heads/side >expect && | |
181 | test_cmp expect actual | |
182 | ' | |
183 | ||
184 | test_expect_success '--single-branch with explicit --branch with tag fetches updated tag' ' | |
185 | ( | |
28d67d9a ÆAB |
186 | cd dir_tag && |
187 | git fetch && | |
31b808a0 RT |
188 | git for-each-ref refs/tags >../actual |
189 | ) && | |
190 | git for-each-ref refs/tags >expect && | |
191 | test_cmp expect actual | |
192 | ' | |
193 | ||
0dab2468 ÆAB |
194 | test_expect_success '--single-branch with explicit --branch with tag fetches updated tag despite --no-tags' ' |
195 | ( | |
196 | cd dir_tag_no_tags && | |
197 | git fetch && | |
198 | git for-each-ref refs/tags >../actual | |
199 | ) && | |
200 | git for-each-ref refs/tags/two >expect && | |
201 | test_cmp expect actual && | |
202 | test_line_count = 1 actual | |
203 | ' | |
204 | ||
31b808a0 RT |
205 | test_expect_success '--single-branch with --mirror' ' |
206 | ( | |
28d67d9a ÆAB |
207 | cd dir_mirror && |
208 | git fetch && | |
31b808a0 RT |
209 | git for-each-ref refs > ../actual |
210 | ) && | |
211 | git for-each-ref refs >expect && | |
212 | test_cmp expect actual | |
213 | ' | |
214 | ||
215 | test_expect_success '--single-branch with explicit --branch and --mirror' ' | |
216 | ( | |
28d67d9a ÆAB |
217 | cd dir_mirror_side && |
218 | git fetch && | |
31b808a0 RT |
219 | git for-each-ref refs > ../actual |
220 | ) && | |
221 | git for-each-ref refs >expect && | |
222 | test_cmp expect actual | |
223 | ' | |
224 | ||
225 | test_expect_success '--single-branch with detached' ' | |
226 | ( | |
28d67d9a ÆAB |
227 | cd dir_detached && |
228 | git fetch && | |
3d180973 | 229 | git for-each-ref refs/remotes/origin >refs && |
31b808a0 | 230 | sed -e "/HEAD$/d" \ |
3d180973 | 231 | -e "s|/remotes/origin/|/heads/|" refs >../actual |
60687de5 | 232 | ) && |
31b808a0 | 233 | # nothing |
d3c6751b | 234 | test_must_be_empty actual |
31b808a0 RT |
235 | ' |
236 | ||
237 | test_done |