receive-pack: allow deletion of corrupt refs
[alt-git.git] / builtin-ls-remote.c
blob56f3f880238e79a92ac35b4112e425a05c3fe916
1 #include "builtin.h"
2 #include "cache.h"
3 #include "transport.h"
4 #include "remote.h"
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)
11 int i;
12 const char *dest = NULL;
13 int nongit = 0;
14 unsigned flags = 0;
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];
26 if (*arg == '-') {
27 if (!prefixcmp(arg, "--upload-pack=")) {
28 uploadpack = arg + 14;
29 continue;
31 if (!prefixcmp(arg, "--exec=")) {
32 uploadpack = arg + 7;
33 continue;
35 if (!strcmp("--tags", arg)) {
36 flags |= REF_TAGS;
37 continue;
39 if (!strcmp("--heads", arg)) {
40 flags |= REF_HEADS;
41 continue;
43 if (!strcmp("--refs", arg)) {
44 flags |= REF_NORMAL;
45 continue;
47 usage(ls_remote_usage);
49 dest = arg;
50 break;
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);
65 if (!ref)
66 return 1;
68 while (ref) {
69 if (check_ref_type(ref, flags))
70 printf("%s %s\n", sha1_to_hex(ref->old_sha1), ref->name);
71 ref = ref->next;
73 return 0;