3 test_description
='git ls-remote'
7 generate_references
() {
10 oid
=$
(git rev-parse
"$ref") &&
11 printf '%s\t%s\n' "$oid" "$ref" ||
return 1
15 test_expect_success setup
'
19 git commit -m initial &&
24 git show-ref --tags -d >expected.tag.raw &&
25 sed -e "s/ / /" expected.tag.raw >expected.tag &&
26 generate_references HEAD >expected.all &&
27 git show-ref -d >refs &&
28 sed -e "s/ / /" refs >>expected.all &&
30 git remote add self "$(pwd)/.git"
33 test_expect_success
'ls-remote --tags .git' '
34 git ls-remote --tags .git >actual &&
35 test_cmp expected.tag actual
38 test_expect_success
'ls-remote .git' '
39 git ls-remote .git >actual &&
40 test_cmp expected.all actual
43 test_expect_success
'ls-remote --tags self' '
44 git ls-remote --tags self >actual &&
45 test_cmp expected.tag actual
48 test_expect_success
'ls-remote self' '
49 git ls-remote self >actual &&
50 test_cmp expected.all actual
53 test_expect_success
'ls-remote --sort="version:refname" --tags self' '
58 refs/tags/mark1.10 >expect &&
59 git ls-remote --sort="version:refname" --tags self >actual &&
60 test_cmp expect actual
63 test_expect_success
'ls-remote --sort="-version:refname" --tags self' '
68 refs/tags/mark >expect &&
69 git ls-remote --sort="-version:refname" --tags self >actual &&
70 test_cmp expect actual
73 test_expect_success
'ls-remote --sort="-refname" --tags self' '
78 refs/tags/mark >expect &&
79 git ls-remote --sort="-refname" --tags self >actual &&
80 test_cmp expect actual
83 test_expect_success
'dies when no remote specified and no default remotes found' '
84 test_must_fail git ls-remote
87 test_expect_success
'use "origin" when no remote specified' '
89 echo "From $URL" >exp_err &&
91 git remote add origin "$URL" &&
92 git ls-remote 2>actual_err >actual &&
94 test_cmp exp_err actual_err &&
95 test_cmp expected.all actual
98 test_expect_success
'suppress "From <url>" with -q' '
99 git ls-remote -q 2>actual_err &&
100 ! test_cmp exp_err actual_err
103 test_expect_success
'use branch.<name>.remote if possible' '
105 # Test that we are indeed using branch.<name>.remote, not "origin", even
106 # though the "origin" remote has been set.
109 # setup a new remote to differentiate from "origin"
110 git clone . other.git &&
113 echo "$(git rev-parse HEAD) HEAD" &&
114 git show-ref | sed -e "s/ / /"
118 echo "From $URL" >exp_err &&
120 git remote add other $URL &&
121 git config branch.master.remote other &&
123 git ls-remote 2>actual_err >actual &&
124 test_cmp exp_err actual_err &&
128 test_expect_success
'confuses pattern as remote when no remote specified' '
129 if test_have_prereq MINGW
131 # Windows does not like asterisks in pathname
132 does_not_exist=master
134 does_not_exist="refs*master"
137 fatal: '\''$does_not_exist'\'' does not appear to be a git repository
138 fatal: Could not read from remote repository.
140 Please make sure you have the correct access rights
141 and the repository exists.
144 # Do not expect "git ls-remote <pattern>" to work; ls-remote needs
145 # <remote> if you want to feed <pattern>, just like you cannot say
147 # We could just as easily have used "master"; the "*" emphasizes its
149 test_must_fail git ls-remote "$does_not_exist" >actual 2>&1 &&
150 test_i18ncmp exp actual
153 test_expect_success
'die with non-2 for wrong repository even with --exit-code' '
155 git ls-remote --exit-code ./no-such-repository
158 test $status != 2 && test $status != 0
161 test_expect_success
'Report success even when nothing matches' '
162 git ls-remote other.git "refs/nsn/*" >actual &&
163 test_must_be_empty actual
166 test_expect_success
'Report no-match with --exit-code' '
167 test_expect_code 2 git ls-remote --exit-code other.git "refs/nsn/*" >actual &&
168 test_must_be_empty actual
171 test_expect_success
'Report match with --exit-code' '
172 git ls-remote --exit-code other.git "refs/tags/*" >actual &&
173 git ls-remote . tags/mark* >expect &&
174 test_cmp expect actual
177 test_expect_success
'set up some extra tags for ref hiding' '
182 for configsection
in transfer uploadpack
184 test_expect_success
"Hide some refs with $configsection.hiderefs" '
185 test_config $configsection.hiderefs refs/tags &&
186 git ls-remote . >actual &&
187 test_unconfig $configsection.hiderefs &&
188 git ls-remote . >expect.raw &&
189 sed -e "/ refs\/tags\//d" expect.raw >expect &&
190 test_cmp expect actual
193 test_expect_success
"Override hiding of $configsection.hiderefs" '
194 test_when_finished "test_unconfig $configsection.hiderefs" &&
195 git config --add $configsection.hiderefs refs/tags &&
196 git config --add $configsection.hiderefs "!refs/tags/magic" &&
197 git config --add $configsection.hiderefs refs/tags/magic/one &&
198 git ls-remote . >actual &&
199 grep refs/tags/magic/two actual &&
200 ! grep refs/tags/magic/one actual
205 test_expect_success
'overrides work between mixed transfer/upload-pack hideRefs' '
206 test_config uploadpack.hiderefs refs/tags &&
207 test_config transfer.hiderefs "!refs/tags/magic" &&
208 git ls-remote . >actual &&
209 grep refs/tags/magic actual
212 test_expect_success
'protocol v2 supports hiderefs' '
213 test_config uploadpack.hiderefs refs/tags &&
214 git -c protocol.version=2 ls-remote . >actual &&
215 ! grep refs/tags actual
218 test_expect_success
'ls-remote --symref' '
220 echo "ref: refs/heads/master HEAD" >expect &&
221 generate_references \
223 refs/heads/master >>expect &&
224 oid=$(git rev-parse HEAD) &&
225 echo "$oid refs/remotes/origin/HEAD" >>expect &&
226 generate_references \
227 refs/remotes/origin/master \
231 refs/tags/mark1.2 >>expect &&
232 # Protocol v2 supports sending symrefs for refs other than HEAD, so use
234 GIT_TEST_PROTOCOL_VERSION=0 git ls-remote --symref >actual &&
235 test_cmp expect actual
238 test_expect_success
'ls-remote with filtered symref (refname)' '
239 rev=$(git rev-parse HEAD) &&
240 cat >expect <<-EOF &&
241 ref: refs/heads/master HEAD
244 # Protocol v2 supports sending symrefs for refs other than HEAD, so use
246 GIT_TEST_PROTOCOL_VERSION=0 git ls-remote --symref . HEAD >actual &&
247 test_cmp expect actual
250 test_expect_failure
'ls-remote with filtered symref (--heads)' '
251 git symbolic-ref refs/heads/foo refs/tags/mark &&
252 cat >expect <<-EOF &&
253 ref: refs/tags/mark refs/heads/foo
255 $rev refs/heads/master
257 # Protocol v2 supports sending symrefs for refs other than HEAD, so use
259 GIT_TEST_PROTOCOL_VERSION=0 git ls-remote --symref --heads . >actual &&
260 test_cmp expect actual
263 test_expect_success
'ls-remote --symref omits filtered-out matches' '
264 cat >expect <<-EOF &&
266 $rev refs/heads/master
268 # Protocol v2 supports sending symrefs for refs other than HEAD, so use
270 GIT_TEST_PROTOCOL_VERSION=0 git ls-remote --symref --heads . >actual &&
271 test_cmp expect actual &&
272 GIT_TEST_PROTOCOL_VERSION=0 git ls-remote --symref . "refs/heads/*" >actual &&
273 test_cmp expect actual
276 test_lazy_prereq GIT_DAEMON
'
277 test_bool_env GIT_TEST_GIT_DAEMON true
280 # This test spawns a daemon, so run it only if the user would be OK with
281 # testing with git-daemon.
282 test_expect_success PIPE
,JGIT
,GIT_DAEMON
'indicate no refs in standards-compliant empty remote' '
283 test_set_port JGIT_DAEMON_PORT &&
285 git init --bare empty.git &&
286 >empty.git/git-daemon-export-ok &&
287 mkfifo jgit_daemon_output &&
289 jgit daemon --port="$JGIT_DAEMON_PORT" . >jgit_daemon_output &
292 test_when_finished kill "$JGIT_DAEMON_PID" &&
299 echo "Expected: Exporting" &&
307 echo "Expected: Listening on" &&
310 } <jgit_daemon_output &&
311 # --exit-code asks the command to exit with 2 when no
312 # matching refs are found.
313 test_expect_code 2 git ls-remote --exit-code git://localhost:$JGIT_DAEMON_PORT/empty.git
316 test_expect_success
'ls-remote works outside repository' '
317 # It is important for this repo to be inside the nongit
318 # area, as we want a repo name that does not include
319 # slashes (because those inhibit some of our configuration
321 nongit git init --bare dst.git &&
322 nongit git ls-remote dst.git
325 test_expect_success
'ls-remote --sort fails gracefully outside repository' '
326 # Use a sort key that requires access to the referenced objects.
327 nongit test_must_fail git ls-remote --sort=authordate "$TRASH_DIRECTORY" 2>err &&
328 test_i18ngrep "^fatal: not a git repository, but the field '\''authordate'\'' requires access to object data" err
331 test_expect_success
'ls-remote patterns work with all protocol versions' '
332 git for-each-ref --format="%(objectname) %(refname)" \
333 refs/heads/master refs/remotes/origin/master >expect &&
334 git -c protocol.version=1 ls-remote . master >actual.v1 &&
335 test_cmp expect actual.v1 &&
336 git -c protocol.version=2 ls-remote . master >actual.v2 &&
337 test_cmp expect actual.v2
340 test_expect_success
'ls-remote prefixes work with all protocol versions' '
341 git for-each-ref --format="%(objectname) %(refname)" \
342 refs/heads/ refs/tags/ >expect &&
343 git -c protocol.version=1 ls-remote --heads --tags . >actual.v1 &&
344 test_cmp expect actual.v1 &&
345 git -c protocol.version=2 ls-remote --heads --tags . >actual.v2 &&
346 test_cmp expect actual.v2