3 test_description
='test refspec written by clone-command'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 TEST_PASSES_SANITIZE_LEAK
=true
10 test_expect_success
'setup' '
11 # Make two branches, "main" and "side"
16 git commit -a -m two &&
19 git commit -a -m three &&
20 git checkout -b side &&
22 git commit -a -m four &&
27 git clone . dir_all &&
29 # default clone --no-tags
30 git clone --no-tags . dir_all_no_tags &&
32 # default --single that follows HEAD=main
33 git clone --single-branch . dir_main &&
35 # default --single that follows HEAD=main with no tags
36 git clone --single-branch --no-tags . dir_main_no_tags &&
38 # default --single that follows HEAD=side
40 git clone --single-branch . dir_side &&
42 # explicit --single that follows side
44 git clone --single-branch --branch side . dir_side2 &&
46 # default --single with --mirror
47 git clone --single-branch --mirror . dir_mirror &&
49 # default --single with --branch and --mirror
50 git clone --single-branch --mirror --branch side . dir_mirror_side &&
52 # --single that does not know what branch to follow
54 git clone --single-branch . dir_detached &&
56 # explicit --single with tag
57 git clone --single-branch --branch two . dir_tag &&
59 # explicit --single with tag and --no-tags
60 git clone --single-branch --no-tags --branch two . dir_tag_no_tags &&
62 # advance both "main" and "side" branches
65 git commit -a -m five &&
68 git commit -a -m six &&
71 git tag -d two && git tag two
74 test_expect_success
'by default all branches will be kept updated' '
78 git for-each-ref refs/remotes/origin >refs &&
80 -e "s|/remotes/origin/|/heads/|" refs >../actual
82 # follow both main and side
83 git for-each-ref refs/heads >expect &&
84 test_cmp expect actual
87 test_expect_success
'by default no tags will be kept updated' '
91 git for-each-ref refs/tags >../actual
93 git for-each-ref refs/tags >expect &&
94 ! test_cmp expect actual &&
95 test_line_count = 2 actual
98 test_expect_success
'clone with --no-tags' '
100 cd dir_all_no_tags &&
101 grep tagOpt .git/config &&
103 git for-each-ref refs/tags >../actual
105 test_must_be_empty actual
108 test_expect_success
'--single-branch while HEAD pointing at main' '
112 git for-each-ref refs/remotes/origin >refs &&
114 -e "s|/remotes/origin/|/heads/|" refs >../actual
117 git for-each-ref refs/heads/main >expect &&
118 # get & check latest tags
119 test_cmp expect actual &&
122 git fetch --tags --force &&
123 git for-each-ref refs/tags >../actual
125 git for-each-ref refs/tags >expect &&
126 test_cmp expect actual &&
127 test_line_count = 2 actual
130 test_expect_success
'--single-branch while HEAD pointing at main and --no-tags' '
132 cd dir_main_no_tags &&
134 git for-each-ref refs/remotes/origin >refs &&
136 -e "s|/remotes/origin/|/heads/|" refs >../actual
139 git for-each-ref refs/heads/main >expect &&
140 test_cmp expect actual &&
143 cd dir_main_no_tags &&
145 git for-each-ref refs/tags >../actual
147 test_must_be_empty actual &&
148 test_line_count = 0 actual &&
149 # get tags with --tags overrides tagOpt
151 cd dir_main_no_tags &&
153 git for-each-ref refs/tags >../actual
155 git for-each-ref refs/tags >expect &&
156 test_cmp expect actual &&
157 test_line_count = 2 actual
160 test_expect_success
'--single-branch while HEAD pointing at side' '
164 git for-each-ref refs/remotes/origin >refs &&
166 -e "s|/remotes/origin/|/heads/|" refs >../actual
169 git for-each-ref refs/heads/side >expect &&
170 test_cmp expect actual
173 test_expect_success
'--single-branch with explicit --branch side' '
177 git for-each-ref refs/remotes/origin >refs &&
179 -e "s|/remotes/origin/|/heads/|" refs >../actual
182 git for-each-ref refs/heads/side >expect &&
183 test_cmp expect actual
186 test_expect_success
'--single-branch with explicit --branch with tag fetches updated tag' '
190 git for-each-ref refs/tags >../actual
192 git for-each-ref refs/tags >expect &&
193 test_cmp expect actual
196 test_expect_success
'--single-branch with explicit --branch with tag fetches updated tag despite --no-tags' '
198 cd dir_tag_no_tags &&
200 git for-each-ref refs/tags >../actual
202 git for-each-ref refs/tags/two >expect &&
203 test_cmp expect actual &&
204 test_line_count = 1 actual
207 test_expect_success
'--single-branch with --mirror' '
211 git for-each-ref refs > ../actual
213 git for-each-ref refs >expect &&
214 test_cmp expect actual
217 test_expect_success
'--single-branch with explicit --branch and --mirror' '
219 cd dir_mirror_side &&
221 git for-each-ref refs > ../actual
223 git for-each-ref refs >expect &&
224 test_cmp expect actual
227 test_expect_success
'--single-branch with detached' '
231 git for-each-ref refs/remotes/origin >refs &&
233 -e "s|/remotes/origin/|/heads/|" refs >../actual
236 test_must_be_empty actual