Skip to content

Commit 70b9c10

Browse files
avargitster
authored andcommitted
bundle-uri client: add helper for testing server
Add a 'test-tool bundle-uri ls-remote' command. This is a thin wrapper for issuing protocol v2 "bundle-uri" commands to a server, and to the parsing routines in bundle-uri.c. In the "git clone" case we'll have already done the handshake(), but not here. Add an extra case to check for this handshake in get_bundle_uri() for ease of use for future callers. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1b759e0 commit 70b9c10

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

t/helper/test-bundle-uri.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include "bundle-uri.h"
44
#include "strbuf.h"
55
#include "string-list.h"
6+
#include "transport.h"
7+
#include "ref-filter.h"
8+
#include "remote.h"
9+
#include "refs.h"
610

711
enum input_mode {
812
KEY_VALUE_PAIRS,
@@ -68,6 +72,46 @@ static int cmd__bundle_uri_parse(int argc, const char **argv, enum input_mode mo
6872
usage_with_options(usage, options);
6973
}
7074

75+
static int cmd_ls_remote(int argc, const char **argv)
76+
{
77+
const char *uploadpack = NULL;
78+
struct string_list server_options = STRING_LIST_INIT_DUP;
79+
const char *dest;
80+
struct remote *remote;
81+
struct transport *transport;
82+
int status = 0;
83+
84+
dest = argc > 1 ? argv[1] : NULL;
85+
86+
remote = remote_get(dest);
87+
if (!remote) {
88+
if (dest)
89+
die(_("bad repository '%s'"), dest);
90+
die(_("no remote configured to get bundle URIs from"));
91+
}
92+
if (!remote->url_nr)
93+
die(_("remote '%s' has no configured URL"), dest);
94+
95+
transport = transport_get(remote, NULL);
96+
if (uploadpack)
97+
transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
98+
if (server_options.nr)
99+
transport->server_options = &server_options;
100+
101+
if (transport_get_remote_bundle_uri(transport) < 0) {
102+
error(_("could not get the bundle-uri list"));
103+
status = 1;
104+
goto cleanup;
105+
}
106+
107+
print_bundle_list(stdout, transport->bundles);
108+
109+
cleanup:
110+
if (transport_disconnect(transport))
111+
return 1;
112+
return status;
113+
}
114+
71115
int cmd__bundle_uri(int argc, const char **argv)
72116
{
73117
const char *usage[] = {
@@ -88,6 +132,8 @@ int cmd__bundle_uri(int argc, const char **argv)
88132
return cmd__bundle_uri_parse(argc - 1, argv + 1, KEY_VALUE_PAIRS);
89133
if (!strcmp(argv[1], "parse-config"))
90134
return cmd__bundle_uri_parse(argc - 1, argv + 1, CONFIG_FILE);
135+
if (!strcmp(argv[1], "ls-remote"))
136+
return cmd_ls_remote(argc - 1, argv + 1);
91137
error("there is no test-tool bundle-uri tool '%s'", argv[1]);
92138

93139
usage:

t/lib-bundle-uri-protocol.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,49 @@ test_expect_success "clone with $BUNDLE_URI_PROTOCOL:// using protocol v2: reque
119119
# Client issued bundle-uri command
120120
grep "> command=bundle-uri" log
121121
'
122+
123+
# The remaining tests will all assume transfer.bundleURI=true
124+
#
125+
# This test can be removed when transfer.bundleURI is enabled by default.
126+
test_expect_success 'enable transfer.bundleURI for remaining tests' '
127+
git config --global transfer.bundleURI true
128+
'
129+
130+
test_expect_success "test bundle-uri with $BUNDLE_URI_PROTOCOL:// using protocol v2" '
131+
test_config -C "$BUNDLE_URI_PARENT" \
132+
bundle.only.uri "$BUNDLE_URI_BUNDLE_URI_ESCAPED" &&
133+
134+
# All data about bundle URIs
135+
cat >expect <<-EOF &&
136+
[bundle]
137+
version = 1
138+
mode = all
139+
EOF
140+
141+
test-tool bundle-uri \
142+
ls-remote \
143+
"$BUNDLE_URI_REPO_URI" \
144+
>actual &&
145+
test_cmp_config_output expect actual
146+
'
147+
148+
test_expect_success "test bundle-uri with $BUNDLE_URI_PROTOCOL:// using protocol v2 and extra data" '
149+
test_config -C "$BUNDLE_URI_PARENT" \
150+
bundle.only.uri "$BUNDLE_URI_BUNDLE_URI_ESCAPED" &&
151+
152+
# Extra data should be ignored
153+
test_config -C "$BUNDLE_URI_PARENT" bundle.only.extra bogus &&
154+
155+
# All data about bundle URIs
156+
cat >expect <<-EOF &&
157+
[bundle]
158+
version = 1
159+
mode = all
160+
EOF
161+
162+
test-tool bundle-uri \
163+
ls-remote \
164+
"$BUNDLE_URI_REPO_URI" \
165+
>actual &&
166+
test_cmp_config_output expect actual
167+
'

transport.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,13 @@ static int get_bundle_uri(struct transport *transport)
371371
init_bundle_list(transport->bundles);
372372
}
373373

374+
if (!data->finished_handshake) {
375+
struct ref *refs = handshake(transport, 0, NULL, 0);
376+
377+
if (refs)
378+
free_refs(refs);
379+
}
380+
374381
/*
375382
* "Support" protocol v0 and v2 without bundle-uri support by
376383
* silently degrading to a NOOP.

0 commit comments

Comments
 (0)