6 static const char ls_remote_usage[] =
7 "git-ls-remote [--upload-pack=<git-upload-pack>] [<host>:]<directory>";
9 int cmd_ls_remote(int argc, const char **argv, const char *prefix)
12 const char *dest = NULL;
15 const char *uploadpack = NULL;
17 struct remote *remote;
18 struct transport *transport;
19 const struct ref *ref;
21 setup_git_directory_gently(&nongit);
23 for (i = 1; i < argc; i++) {
24 const char *arg = argv[i];
27 if (!prefixcmp(arg, "--upload-pack=")) {
28 uploadpack = arg + 14;
31 if (!prefixcmp(arg, "--exec=")) {
35 if (!strcmp("--tags", arg)) {
39 if (!strcmp("--heads", arg)) {
43 if (!strcmp("--refs", arg)) {
47 usage(ls_remote_usage);
53 if (!dest || i != argc - 1)
54 usage(ls_remote_usage);
56 remote = nongit ? NULL : remote_get(dest);
57 if (remote && !remote->url_nr)
58 die("remote %s has no configured URL", dest);
59 transport = transport_get(remote, remote ? remote->url[0] : dest);
60 if (uploadpack != NULL)
61 transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
63 ref = transport_get_remote_refs(transport);
69 if (check_ref_type(ref, flags))
70 printf("%s %s\n", sha1_to_hex(ref->old_sha1), ref->name);