@@ -15,6 +15,19 @@ generate_references () {
15
15
done
16
16
}
17
17
18
+ test_expect_success ' set up fake upload-pack' '
19
+ # This can be used to simulate an upload-pack that just shows the
20
+ # contents of the "input" file (prepared with the test-tool pkt-line
21
+ # helper), and does not do any negotiation (since ls-remote does not
22
+ # need it).
23
+ write_script cat-input <<-\EOF
24
+ # send our initial advertisement/response
25
+ cat input
26
+ # soak up the flush packet from the client
27
+ cat
28
+ EOF
29
+ '
30
+
18
31
test_expect_success ' dies when no remote found' '
19
32
test_must_fail git ls-remote
20
33
'
@@ -231,22 +244,25 @@ test_expect_success 'protocol v2 supports hiderefs' '
231
244
232
245
test_expect_success ' ls-remote --symref' '
233
246
git fetch origin &&
234
- echo "ref: refs/heads/main HEAD" >expect &&
247
+ echo "ref: refs/heads/main HEAD" >expect.v2 &&
235
248
generate_references \
236
249
HEAD \
237
- refs/heads/main >>expect &&
250
+ refs/heads/main >>expect.v2 &&
251
+ echo "ref: refs/remotes/origin/main refs/remotes/origin/HEAD" >>expect.v2 &&
238
252
oid=$(git rev-parse HEAD) &&
239
- echo "$oid refs/remotes/origin/HEAD" >>expect &&
253
+ echo "$oid refs/remotes/origin/HEAD" >>expect.v2 &&
240
254
generate_references \
241
255
refs/remotes/origin/main \
242
256
refs/tags/mark \
243
257
refs/tags/mark1.1 \
244
258
refs/tags/mark1.10 \
245
- refs/tags/mark1.2 >>expect &&
246
- # Protocol v2 supports sending symrefs for refs other than HEAD, so use
247
- # protocol v0 here.
248
- GIT_TEST_PROTOCOL_VERSION=0 git ls-remote --symref >actual &&
249
- test_cmp expect actual
259
+ refs/tags/mark1.2 >>expect.v2 &&
260
+ # v0 does not show non-HEAD symrefs
261
+ grep -v "ref: refs/remotes" <expect.v2 >expect.v0 &&
262
+ git -c protocol.version=0 ls-remote --symref >actual.v0 &&
263
+ test_cmp expect.v0 actual.v0 &&
264
+ git -c protocol.version=2 ls-remote --symref >actual.v2 &&
265
+ test_cmp expect.v2 actual.v2
250
266
'
251
267
252
268
test_expect_success ' ls-remote with filtered symref (refname)' '
@@ -255,76 +271,41 @@ test_expect_success 'ls-remote with filtered symref (refname)' '
255
271
ref: refs/heads/main HEAD
256
272
$rev HEAD
257
273
EOF
258
- # Protocol v2 supports sending symrefs for refs other than HEAD, so use
259
- # protocol v0 here.
260
- GIT_TEST_PROTOCOL_VERSION=0 git ls-remote --symref . HEAD >actual &&
274
+ git ls-remote --symref . HEAD >actual &&
261
275
test_cmp expect actual
262
276
'
263
277
264
- test_expect_failure ' ls-remote with filtered symref (--heads)' '
278
+ test_expect_success ' ls-remote with filtered symref (--heads)' '
265
279
git symbolic-ref refs/heads/foo refs/tags/mark &&
266
- cat >expect <<-EOF &&
280
+ cat >expect.v2 <<-EOF &&
267
281
ref: refs/tags/mark refs/heads/foo
268
282
$rev refs/heads/foo
269
283
$rev refs/heads/main
270
284
EOF
271
- # Protocol v2 supports sending symrefs for refs other than HEAD, so use
272
- # protocol v0 here.
273
- GIT_TEST_PROTOCOL_VERSION=0 git ls-remote --symref --heads . >actual &&
274
- test_cmp expect actual
285
+ grep -v "^ref: refs/tags/" <expect.v2 >expect.v0 &&
286
+ git -c protocol.version=0 ls-remote --symref --heads . >actual.v0 &&
287
+ test_cmp expect.v0 actual.v0 &&
288
+ git -c protocol.version=2 ls-remote --symref --heads . >actual.v2 &&
289
+ test_cmp expect.v2 actual.v2
275
290
'
276
291
277
- test_expect_success ' ls-remote --symref omits filtered-out matches' '
278
- cat >expect <<-EOF &&
279
- $rev refs/heads/foo
280
- $rev refs/heads/main
292
+ test_expect_success ' indicate no refs in v0 standards-compliant empty remote' '
293
+ # Git does not produce an output like this, but it does match the
294
+ # standard and is produced by other implementations like JGit. So
295
+ # hard-code the case we care about.
296
+ #
297
+ # The actual capabilities do not matter; there are none that would
298
+ # change how ls-remote behaves.
299
+ oid=0000000000000000000000000000000000000000 &&
300
+ test-tool pkt-line pack >input.q <<-EOF &&
301
+ $oid capabilities^{}Qcaps-go-here
302
+ 0000
281
303
EOF
282
- # Protocol v2 supports sending symrefs for refs other than HEAD, so use
283
- # protocol v0 here.
284
- GIT_TEST_PROTOCOL_VERSION=0 git ls-remote --symref --heads . >actual &&
285
- test_cmp expect actual &&
286
- GIT_TEST_PROTOCOL_VERSION=0 git ls-remote --symref . "refs/heads/*" >actual &&
287
- test_cmp expect actual
288
- '
289
-
290
- test_lazy_prereq GIT_DAEMON '
291
- test_bool_env GIT_TEST_GIT_DAEMON true
292
- '
304
+ q_to_nul <input.q >input &&
293
305
294
- # This test spawns a daemon, so run it only if the user would be OK with
295
- # testing with git-daemon.
296
- test_expect_success PIPE,JGIT,GIT_DAEMON ' indicate no refs in standards-compliant empty remote' '
297
- test_set_port JGIT_DAEMON_PORT &&
298
- JGIT_DAEMON_PID= &&
299
- git init --bare empty.git &&
300
- >empty.git/git-daemon-export-ok &&
301
- mkfifo jgit_daemon_output &&
302
- {
303
- jgit daemon --port="$JGIT_DAEMON_PORT" . >jgit_daemon_output &
304
- JGIT_DAEMON_PID=$!
305
- } &&
306
- test_when_finished kill "$JGIT_DAEMON_PID" &&
307
- {
308
- read line &&
309
- case $line in
310
- Exporting*)
311
- ;;
312
- *)
313
- echo "Expected: Exporting" &&
314
- false;;
315
- esac &&
316
- read line &&
317
- case $line in
318
- "Listening on"*)
319
- ;;
320
- *)
321
- echo "Expected: Listening on" &&
322
- false;;
323
- esac
324
- } <jgit_daemon_output &&
325
306
# --exit-code asks the command to exit with 2 when no
326
307
# matching refs are found.
327
- test_expect_code 2 git ls-remote --exit-code git://localhost:$JGIT_DAEMON_PORT/empty.git
308
+ test_expect_code 2 git ls-remote --exit-code --upload-pack=./cat-input .
328
309
'
329
310
330
311
test_expect_success ' ls-remote works outside repository' '
@@ -345,19 +326,58 @@ test_expect_success 'ls-remote --sort fails gracefully outside repository' '
345
326
test_expect_success ' ls-remote patterns work with all protocol versions' '
346
327
git for-each-ref --format="%(objectname) %(refname)" \
347
328
refs/heads/main refs/remotes/origin/main >expect &&
348
- git -c protocol.version=1 ls-remote . main >actual.v1 &&
349
- test_cmp expect actual.v1 &&
329
+ git -c protocol.version=0 ls-remote . main >actual.v0 &&
330
+ test_cmp expect actual.v0 &&
350
331
git -c protocol.version=2 ls-remote . main >actual.v2 &&
351
332
test_cmp expect actual.v2
352
333
'
353
334
354
335
test_expect_success ' ls-remote prefixes work with all protocol versions' '
355
336
git for-each-ref --format="%(objectname) %(refname)" \
356
337
refs/heads/ refs/tags/ >expect &&
357
- git -c protocol.version=1 ls-remote --heads --tags . >actual.v1 &&
358
- test_cmp expect actual.v1 &&
338
+ git -c protocol.version=0 ls-remote --heads --tags . >actual.v0 &&
339
+ test_cmp expect actual.v0 &&
359
340
git -c protocol.version=2 ls-remote --heads --tags . >actual.v2 &&
360
341
test_cmp expect actual.v2
361
342
'
362
343
344
+ test_expect_success ' v0 clients can handle multiple symrefs' '
345
+ # Modern versions of Git will not return multiple symref capabilities
346
+ # for v0, so we have to hard-code the response. Note that we will
347
+ # always use both v0 and object-format=sha1 here, as the hard-coded
348
+ # response reflects a server that only supports those.
349
+ oid=1234567890123456789012345678901234567890 &&
350
+ symrefs="symref=refs/remotes/origin/HEAD:refs/remotes/origin/main" &&
351
+ symrefs="$symrefs symref=HEAD:refs/heads/main" &&
352
+
353
+ # Likewise we want to make sure our parser is not fooled by the string
354
+ # "symref" appearing as part of an earlier cap. But there is no way to
355
+ # do that via upload-pack, as arbitrary strings can appear only in a
356
+ # "symref" value itself (where we skip past the values as a whole)
357
+ # and "agent" (which always appears after "symref", so putting our
358
+ # parser in a confused state is less interesting).
359
+ caps="some other caps including a-fake-symref-cap" &&
360
+
361
+ test-tool pkt-line pack >input.q <<-EOF &&
362
+ $oid HEADQ$caps $symrefs
363
+ $oid refs/heads/main
364
+ $oid refs/remotes/origin/HEAD
365
+ $oid refs/remotes/origin/main
366
+ 0000
367
+ EOF
368
+ q_to_nul <input.q >input &&
369
+
370
+ cat >expect <<-EOF &&
371
+ ref: refs/heads/main HEAD
372
+ $oid HEAD
373
+ $oid refs/heads/main
374
+ ref: refs/remotes/origin/main refs/remotes/origin/HEAD
375
+ $oid refs/remotes/origin/HEAD
376
+ $oid refs/remotes/origin/main
377
+ EOF
378
+
379
+ git ls-remote --symref --upload-pack=./cat-input . >actual &&
380
+ test_cmp expect actual
381
+ '
382
+
363
383
test_done
0 commit comments