@@ -91,6 +91,7 @@
/git-log
/git-ls-files
/git-ls-remote
+/git-ls-remote-bundle-uri
/git-ls-tree
/git-mailinfo
/git-mailsplit
new file mode 100644
@@ -0,0 +1,62 @@
+git-ls-remote-bundle-uri(1)
+===========================
+
+NAME
+----
+git-ls-remote-bundle-uri - List 'bundle-uri' in a remote repository
+
+SYNOPSIS
+--------
+[verse]
+'git ls-remote-bundle-uri' [-q |--quiet] [--uri] [--upload-pack=<exec>]
+ [[-o | --server-option=]<option>] <repository>
+
+
+DESCRIPTION
+-----------
+
+Displays the `bundle-uri`s advertised by a remote repository. See
+`bundle-uri` in link:technical/protocol-v2.html[the Git Wire Protocol,
+Version 2] documentation for what the output format looks like.
+
+OPTIONS
+-------
+
+-q::
+--quiet::
+ Do not print remote URL to stderr in cases where the remote
+ name is inferred from config.
++
+When the remote name is not inferred (e.g. `git ls-remote-bundle-uri
+origin`, or `git ls-remote-bundle-uri https://[...]`) the remote URL
+is not printed in any case.
+
+--uri::
+ Print only the URIs, and not any of their optional attributes.
+
+--upload-pack=<exec>::
+ Specify the full path of 'git-upload-pack' on the remote
+ host. This allows listing references from repositories accessed via
+ SSH and where the SSH daemon does not use the PATH configured by the
+ user.
+
+-o <option>::
+--server-option=<option>::
+ Transmit the given string to the server when communicating using
+ protocol version 2. The given string must not contain a NUL or LF
+ character.
+ When multiple `--server-option=<option>` are given, they are all
+ sent to the other side in the order listed on the command line.
+
+<repository>::
+ The "remote" repository to query. This parameter can be
+ either a URL or the name of a remote (see the GIT URLS and
+ REMOTES sections of linkgit:git-fetch[1]).
+
+SEE ALSO
+--------
+linkgit:git-ls-remote[1].
+
+GIT
+---
+Part of the linkgit:git[1] suite
@@ -114,6 +114,7 @@ c5db5456ae3b0873fc659c19fafdde22313cc441 refs/tags/v0.99.2
SEE ALSO
--------
+linkgit:git-ls-remote-bundle-uri[1].
linkgit:git-check-ref-format[1].
GIT
@@ -1161,6 +1161,7 @@ BUILTIN_OBJS += builtin/init-db.o
BUILTIN_OBJS += builtin/interpret-trailers.o
BUILTIN_OBJS += builtin/log.o
BUILTIN_OBJS += builtin/ls-files.o
+BUILTIN_OBJS += builtin/ls-remote-bundle-uri.o
BUILTIN_OBJS += builtin/ls-remote.o
BUILTIN_OBJS += builtin/ls-tree.o
BUILTIN_OBJS += builtin/mailinfo.o
@@ -173,6 +173,7 @@ int cmd_log(int argc, const char **argv, const char *prefix);
int cmd_log_reflog(int argc, const char **argv, const char *prefix);
int cmd_ls_files(int argc, const char **argv, const char *prefix);
int cmd_ls_tree(int argc, const char **argv, const char *prefix);
+int cmd_ls_remote_bundle_uri(int argc, const char **argv, const char *prefix);
int cmd_ls_remote(int argc, const char **argv, const char *prefix);
int cmd_mailinfo(int argc, const char **argv, const char *prefix);
int cmd_mailsplit(int argc, const char **argv, const char *prefix);
@@ -1267,7 +1267,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
* Populate transport->got_remote_bundle_uri and
* transport->bundle_uri. We might get nothing.
*/
- transport_get_remote_bundle_uri(transport);
+ transport_get_remote_bundle_uri(transport, 1);
if (mapped_refs) {
int hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));
new file mode 100644
@@ -0,0 +1,71 @@
+#include "builtin.h"
+#include "cache.h"
+#include "bundle-uri.h"
+#include "transport.h"
+#include "ref-filter.h"
+#include "remote.h"
+#include "refs.h"
+
+static const char * const ls_remote_bundle_uri_usage[] = {
+ N_("git ls-remote-bundle-uri <repository>"),
+ NULL
+};
+
+int cmd_ls_remote_bundle_uri(int argc, const char **argv, const char *prefix)
+{
+ int quiet = 0;
+ int uri = 0;
+ const char *uploadpack = NULL;
+ struct string_list server_options = STRING_LIST_INIT_DUP;
+ struct option options[] = {
+ OPT__QUIET(&quiet, N_("do not print remote URL")),
+ OPT_BOOL(0, "uri", &uri, N_("limit to showing uri field")),
+ OPT_STRING(0, "upload-pack", &uploadpack, N_("exec"),
+ N_("path of git-upload-pack on the remote host")),
+ OPT_STRING_LIST('o', "server-option", &server_options,
+ N_("server-specific"),
+ N_("option to transmit")),
+ OPT_END()
+ };
+ const char *dest = NULL;
+ struct remote *remote;
+ struct transport *transport;
+ int status = 0;
+
+ argc = parse_options(argc, argv, prefix, options, ls_remote_bundle_uri_usage,
+ PARSE_OPT_STOP_AT_NON_OPTION);
+ dest = argv[0];
+
+ packet_trace_identity("ls-remote-bundle-uri");
+
+ remote = remote_get(dest);
+ if (!remote) {
+ if (dest)
+ die(_("bad repository '%s'"), dest);
+ die(_("no remote configured to get bundle URIs from"));
+ }
+ if (!remote->url_nr)
+ die(_("remote '%s' has no configured URL"), dest);
+
+ transport = transport_get(remote, NULL);
+ if (uploadpack)
+ transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
+ if (server_options.nr)
+ transport->server_options = &server_options;
+
+ if (!dest && !quiet)
+ fprintf(stderr, "From %s\n", *remote->url);
+
+ if (transport_get_remote_bundle_uri(transport, 0) < 0) {
+ error(_("could not get the bundle-uri list"));
+ status = 1;
+ goto cleanup;
+ }
+
+ print_bundle_list(stdout, transport->bundles);
+
+cleanup:
+ if (transport_disconnect(transport))
+ return 1;
+ return status;
+}
@@ -115,6 +115,7 @@ git-interpret-trailers purehelpers
git-log mainporcelain info
git-ls-files plumbinginterrogators
git-ls-remote plumbinginterrogators
+git-ls-remote-bundle-uri plumbinginterrogators
git-ls-tree plumbinginterrogators
git-mailinfo purehelpers
git-mailsplit purehelpers
@@ -551,6 +551,7 @@ static struct cmd_struct commands[] = {
{ "log", cmd_log, RUN_SETUP },
{ "ls-files", cmd_ls_files, RUN_SETUP },
{ "ls-remote", cmd_ls_remote, RUN_SETUP_GENTLY },
+ { "ls-remote-bundle-uri", cmd_ls_remote_bundle_uri, RUN_SETUP_GENTLY },
{ "ls-tree", cmd_ls_tree, RUN_SETUP },
{ "mailinfo", cmd_mailinfo, RUN_SETUP_GENTLY | NO_PARSEOPT },
{ "mailsplit", cmd_mailsplit, NO_PARSEOPT },
@@ -34,7 +34,9 @@ esac
test_expect_success "setup protocol v2 $T5730_PROTOCOL:// tests" '
git init "$T5730_PARENT" &&
test_commit -C "$T5730_PARENT" one &&
- git -C "$T5730_PARENT" config uploadpack.advertiseBundleURIs true
+ git -C "$T5730_PARENT" config uploadpack.advertiseBundleURIs true &&
+ git -C "$T5730_PARENT" config bundle.list.version 1 &&
+ git -C "$T5730_PARENT" config bundle.list.mode all
'
# Poor man's URI escaping. Good enough for the test suite whose trash
@@ -94,7 +96,7 @@ test_expect_success "connect with $T5730_PROTOCOL:// using protocol v2: have bun
test_expect_success !T5730_HTTP "bad client with $T5730_PROTOCOL:// using protocol v2" '
test_when_finished "rm -f log" &&
- test_config -C "$T5730_PARENT" uploadpack.bundleURI \
+ test_config -C "$T5730_PARENT" bundle.only.uri \
"$T5730_BUNDLE_URI_ESCAPED" &&
cat >err.expect <<-\EOF &&
@@ -146,3 +148,144 @@ test_expect_success !T5730_HTTP "bad client with $T5730_PROTOCOL:// using protoc
grep "clone> test-bad-client$" log >sent-bad-request &&
test_file_not_empty sent-bad-request
'
+
+test_expect_success "ls-remote-bundle-uri with $T5730_PROTOCOL:// using protocol v2" '
+ test_when_finished "rm -f log" &&
+
+ test_config -C "$T5730_PARENT" bundle.only.uri \
+ "$T5730_BUNDLE_URI_ESCAPED" &&
+
+ # All data about bundle URIs
+ cat >expect <<-EOF &&
+ [bundle "list"]
+ version = 1
+ mode = all
+ [bundle "only"]
+ uri = $T5730_BUNDLE_URI_ESCAPED
+ EOF
+ GIT_TRACE_PACKET="$PWD/log" \
+ git \
+ -c protocol.version=2 \
+ ls-remote-bundle-uri \
+ "$T5730_URI" \
+ >actual &&
+ test_cmp_config_output expect actual &&
+
+ # Only the URIs
+ git \
+ -c protocol.version=2 \
+ ls-remote-bundle-uri --uri \
+ "$T5730_URI" \
+ >actual2 &&
+ test_cmp actual actual2
+'
+
+test_expect_success "ls-remote-bundle-uri with $T5730_PROTOCOL:// using protocol v2" '
+ test_when_finished "rm -f log" &&
+
+ test_config -C "$T5730_PARENT" bundle.only.uri \
+ "$T5730_BUNDLE_URI_ESCAPED" &&
+
+ # Extra data should be ignored
+ test_config -C "$T5730_PARENT" bundle.only.extra bogus &&
+
+ # All data about bundle URIs
+ cat >expect <<-EOF &&
+ [bundle "list"]
+ version = 1
+ mode = all
+ [bundle "only"]
+ uri = $T5730_BUNDLE_URI_ESCAPED
+ EOF
+ GIT_TRACE_PACKET="$PWD/log" \
+ git \
+ -c protocol.version=2 \
+ ls-remote-bundle-uri \
+ "$T5730_URI" \
+ >actual &&
+ test_cmp_config_output expect actual
+'
+
+test_expect_success "ls-remote-bundle-uri with $T5730_PROTOCOL:// using protocol v2: --uri" '
+ test_when_finished "rm -f log" &&
+
+ test_config -C "$T5730_PARENT" bundle.only.uri \
+ "$T5730_BUNDLE_URI_ESCAPED" &&
+
+ # All data about bundle URIs
+ cat >expect <<-EOF &&
+ [bundle "list"]
+ version = 1
+ mode = all
+ [bundle "only"]
+ uri = $T5730_BUNDLE_URI_ESCAPED
+ EOF
+ GIT_TRACE_PACKET="$PWD/log" \
+ git \
+ -c protocol.version=2 \
+ ls-remote-bundle-uri \
+ --uri \
+ "$T5730_URI" \
+ >actual &&
+ test_cmp_config_output expect actual
+'
+
+test_expect_success "ls-remote-bundle-uri --[no-]quiet with $T5730_PROTOCOL:// using protocol v2" '
+ test_when_finished "rm -f log" &&
+ test_when_finished "rm -rf child" &&
+ env GIT_TRACE_PACKET="$PWD/log" \
+ git \
+ -c protocol.version=2 \
+ clone "$T5730_URI" child &&
+
+ test_config -C "$T5730_PARENT" bundle.only.uri \
+ "$T5730_BUNDLE_URI_ESCAPED" &&
+
+ # Without --[no-]quiet
+ cat >out.expect <<-EOF &&
+ [bundle "list"]
+ version = 1
+ mode = all
+ [bundle "only"]
+ uri = $T5730_BUNDLE_URI_ESCAPED
+ EOF
+ cat >err.expect <<-EOF &&
+ From $T5730_URI
+ EOF
+ git \
+ -C child \
+ -c protocol.version=2 \
+ ls-remote-bundle-uri \
+ >out.actual 2>err.actual &&
+ test_cmp err.expect err.actual &&
+ test_cmp_config_output out.expect out.actual &&
+
+ # --no-quiet is the default
+ git \
+ -C child \
+ -c protocol.version=2 \
+ ls-remote-bundle-uri \
+ --no-quiet \
+ >out.actual 2>err.actual &&
+ test_cmp err.expect err.actual &&
+ test_cmp_config_output out.expect out.actual &&
+
+ # --quiet quiets the "From" line
+ git \
+ -C child \
+ -c protocol.version=2 \
+ ls-remote-bundle-uri \
+ --quiet \
+ >out.actual 2>err &&
+ test_must_be_empty err &&
+ test_cmp_config_output out.expect out.actual &&
+
+ # --quiet is implicit if the remote is not implicit
+ git \
+ -c protocol.version=2 \
+ ls-remote-bundle-uri \
+ "$T5730_URI" \
+ >out.actual 2>err &&
+ test_must_be_empty err &&
+ test_cmp_config_output out.expect out.actual
+'
@@ -198,6 +198,7 @@ struct git_transport_data {
struct git_transport_options options;
struct child_process *conn;
int fd[2];
+ unsigned got_advertisement : 1;
unsigned got_remote_heads : 1;
enum protocol_version version;
struct oid_array extra_have;
@@ -346,6 +347,7 @@ static struct ref *handshake(struct transport *transport, int for_push,
BUG("unknown protocol version");
}
data->got_remote_heads = 1;
+ data->got_advertisement = 1;
transport->hash_algo = reader.hash_algo;
if (reader.line_peeked)
@@ -371,6 +373,33 @@ static int get_bundle_uri(struct transport *transport)
init_bundle_list(transport->bundles);
}
+ if (!data->got_advertisement) {
+ struct ref *refs;
+ struct git_transport_data *data = transport->data;
+ enum protocol_version version;
+
+ refs = handshake(transport, 0, NULL, 0);
+ version = data->version;
+
+ switch (version) {
+ case protocol_v2:
+ assert(!refs);
+ break;
+ case protocol_v0:
+ case protocol_v1:
+ case protocol_unknown_version:
+ assert(refs);
+ break;
+ }
+ }
+
+ /*
+ * "Support" protocol v0 and v2 without bundle-uri support by
+ * silently degrading to a NOOP.
+ */
+ if (!server_supports_v2("bundle-uri", 0))
+ return 0;
+
packet_reader_init(&reader, data->fd[0], NULL, 0,
PACKET_READ_CHOMP_NEWLINE |
PACKET_READ_GENTLE_ON_EOF);
@@ -1498,7 +1527,7 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)
return rc;
}
-int transport_get_remote_bundle_uri(struct transport *transport)
+int transport_get_remote_bundle_uri(struct transport *transport, int quiet)
{
const struct transport_vtable *vtable = transport->vtable;
@@ -1506,20 +1535,16 @@ int transport_get_remote_bundle_uri(struct transport *transport)
if (transport->got_remote_bundle_uri++)
return 0;
- /*
- * "Support" protocol v0 and v2 without bundle-uri support by
- * silently degrading to a NOOP.
- */
- if (!server_supports_v2("bundle-uri", 0))
- return 0;
-
/*
* This is intentionally below the transport.injectBundleURI,
* we want to be able to inject into protocol v0, or into the
* dialog of a server who doesn't support this.
*/
- if (!vtable->get_bundle_uri)
+ if (!vtable->get_bundle_uri) {
+ if (quiet)
+ return -1;
return error(_("bundle-uri operation not supported by protocol"));
+ }
if (vtable->get_bundle_uri(transport) < 0)
return error(_("could not retrieve server-advertised bundle-uri list"));
@@ -296,8 +296,12 @@ const struct ref *transport_get_remote_refs(struct transport *transport,
/**
* Retrieve bundle URI(s) from a remote. Populates "struct
* transport"'s "bundle_uri" and "got_remote_bundle_uri".
+ *
+ * With `quiet=1` it will not complain if the serve doesn't support
+ * the protocol, but only if we discover the server uses it, and
+ * encounter issues then.
*/
-int transport_get_remote_bundle_uri(struct transport *transport);
+int transport_get_remote_bundle_uri(struct transport *transport, int quiet);
/*
* Fetch the hash algorithm used by a remote.