]> git.ipfire.org Git - thirdparty/git.git/blob - builtin-ls-remote.c
Build in ls-remote
[thirdparty/git.git] / builtin-ls-remote.c
1 #include "builtin.h"
2 #include "cache.h"
3 #include "transport.h"
4 #include "remote.h"
5
6 static const char ls_remote_usage[] =
7 "git-ls-remote [--upload-pack=<git-upload-pack>] [<host>:]<directory>";
8
9 int cmd_ls_remote(int argc, const char **argv, const char *prefix)
10 {
11 int i;
12 const char *dest = NULL;
13 int nongit = 0;
14 unsigned flags = 0;
15 const char *uploadpack = NULL;
16
17 struct transport *transport;
18 const struct ref *ref;
19
20 setup_git_directory_gently(&nongit);
21
22 for (i = 1; i < argc; i++) {
23 const char *arg = argv[i];
24
25 if (*arg == '-') {
26 if (!prefixcmp(arg, "--upload-pack=")) {
27 uploadpack = arg + 14;
28 continue;
29 }
30 if (!prefixcmp(arg, "--exec=")) {
31 uploadpack = arg + 7;
32 continue;
33 }
34 if (!strcmp("--tags", arg)) {
35 flags |= REF_TAGS;
36 continue;
37 }
38 if (!strcmp("--heads", arg)) {
39 flags |= REF_HEADS;
40 continue;
41 }
42 if (!strcmp("--refs", arg)) {
43 flags |= REF_NORMAL;
44 continue;
45 }
46 usage(ls_remote_usage);
47 }
48 dest = arg;
49 break;
50 }
51
52 if (!dest || i != argc - 1)
53 usage(ls_remote_usage);
54
55 transport = transport_get(NULL, dest);
56 if (uploadpack != NULL)
57 transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
58
59 ref = transport_get_remote_refs(transport);
60
61 if (!ref)
62 return 1;
63
64 while (ref) {
65 if (check_ref_type(ref, flags))
66 printf("%s %s\n", sha1_to_hex(ref->old_sha1), ref->name);
67 ref = ref->next;
68 }
69 return 0;
70 }