]>
Commit | Line | Data |
---|---|---|
18f7c51c | 1 | #include "builtin.h" |
18705953 | 2 | #include "cache.h" |
18f7c51c DB |
3 | #include "transport.h" |
4 | #include "remote.h" | |
18705953 | 5 | |
8951d7c1 DB |
6 | static const char ls_remote_usage[] = |
7 | "git-ls-remote [--upload-pack=<git-upload-pack>] [<host>:]<directory>"; | |
18705953 | 8 | |
8951d7c1 | 9 | int cmd_ls_remote(int argc, const char **argv, const char *prefix) |
18705953 | 10 | { |
18f7c51c DB |
11 | int i; |
12 | const char *dest = NULL; | |
e44eb3e4 | 13 | int nongit = 0; |
2718ff09 | 14 | unsigned flags = 0; |
18f7c51c DB |
15 | const char *uploadpack = NULL; |
16 | ||
7c2c6ee7 | 17 | struct remote *remote; |
18f7c51c DB |
18 | struct transport *transport; |
19 | const struct ref *ref; | |
e44eb3e4 JH |
20 | |
21 | setup_git_directory_gently(&nongit); | |
18705953 JH |
22 | |
23 | for (i = 1; i < argc; i++) { | |
18f7c51c | 24 | const char *arg = argv[i]; |
18705953 JH |
25 | |
26 | if (*arg == '-') { | |
599065a3 | 27 | if (!prefixcmp(arg, "--upload-pack=")) { |
27dca07f UKK |
28 | uploadpack = arg + 14; |
29 | continue; | |
30 | } | |
599065a3 | 31 | if (!prefixcmp(arg, "--exec=")) { |
27dca07f | 32 | uploadpack = arg + 7; |
2718ff09 LT |
33 | continue; |
34 | } | |
35 | if (!strcmp("--tags", arg)) { | |
36 | flags |= REF_TAGS; | |
37 | continue; | |
38 | } | |
39 | if (!strcmp("--heads", arg)) { | |
40 | flags |= REF_HEADS; | |
41 | continue; | |
42 | } | |
43 | if (!strcmp("--refs", arg)) { | |
44 | flags |= REF_NORMAL; | |
45 | continue; | |
46 | } | |
8951d7c1 | 47 | usage(ls_remote_usage); |
18705953 JH |
48 | } |
49 | dest = arg; | |
50 | break; | |
51 | } | |
2718ff09 | 52 | |
18705953 | 53 | if (!dest || i != argc - 1) |
8951d7c1 | 54 | usage(ls_remote_usage); |
18705953 | 55 | |
7c2c6ee7 SP |
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); | |
18f7c51c DB |
60 | if (uploadpack != NULL) |
61 | transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack); | |
62 | ||
63 | ref = transport_get_remote_refs(transport); | |
64 | ||
65 | if (!ref) | |
66 | return 1; | |
67 | ||
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; | |
72 | } | |
73 | return 0; | |
18705953 | 74 | } |