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 <avarab@gmail.com> Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Dec 22, 2022 at 15:14 UTC 70b9c1037325ee82bc0832f4ca2d30c6ebf4808e
3 files changed +99
t/helper/test-bundle-uri.c
+46
@@ -3,6 +3,10 @@
3 #include "bundle-uri.h"
4 #include "strbuf.h"
5 #include "string-list.h"
6 +#include "transport.h"
7 +#include "ref-filter.h"
8 +#include "remote.h"
9 +#include "refs.h"
10
11 enum input_mode {
12 KEY_VALUE_PAIRS,
@@ -68,6 +72,46 @@ usage:
72 usage_with_options(usage, options);
73 }
74
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 +
115 int cmd__bundle_uri(int argc, const char **argv)
116 {
117 const char *usage[] = {
@@ -88,6 +132,8 @@ int cmd__bundle_uri(int argc, const char **argv)
132 return cmd__bundle_uri_parse(argc - 1, argv + 1, KEY_VALUE_PAIRS);
133 if (!strcmp(argv[1], "parse-config"))
134 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);
137 error("there is no test-tool bundle-uri tool '%s'", argv[1]);
138
139 usage:
t/lib-bundle-uri-protocol.sh
+46
@@ -119,3 +119,49 @@ test_expect_success "clone with $BUNDLE_URI_PROTOCOL:// using protocol v2: reque
119 # Client issued bundle-uri command
120 grep "> command=bundle-uri" log
121 '
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
+7
@@ -371,6 +371,13 @@ static int get_bundle_uri(struct transport *transport)
371 init_bundle_list(transport->bundles);
372 }
373
374 + if (!data->finished_handshake) {
375 + struct ref *refs = handshake(transport, 0, NULL, 0);
376 +
377 + if (refs)
378 + free_refs(refs);
379 + }
380 +
381 /*
382 * "Support" protocol v0 and v2 without bundle-uri support by
383 * silently degrading to a NOOP.