]>
Commit | Line | Data |
---|---|---|
18f7c51c | 1 | #include "builtin.h" |
18705953 | 2 | #include "cache.h" |
18f7c51c DB |
3 | #include "transport.h" |
4 | #include "remote.h" | |
18705953 JH |
5 | |
6 | static const char peek_remote_usage[] = | |
27dca07f | 7 | "git-peek-remote [--upload-pack=<git-upload-pack>] [<host>:]<directory>"; |
18705953 | 8 | |
18f7c51c | 9 | int cmd_peek_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 | ||
17 | struct transport *transport; | |
18 | const struct ref *ref; | |
e44eb3e4 JH |
19 | |
20 | setup_git_directory_gently(&nongit); | |
18705953 JH |
21 | |
22 | for (i = 1; i < argc; i++) { | |
18f7c51c | 23 | const char *arg = argv[i]; |
18705953 JH |
24 | |
25 | if (*arg == '-') { | |
599065a3 | 26 | if (!prefixcmp(arg, "--upload-pack=")) { |
27dca07f UKK |
27 | uploadpack = arg + 14; |
28 | continue; | |
29 | } | |
599065a3 | 30 | if (!prefixcmp(arg, "--exec=")) { |
27dca07f | 31 | uploadpack = arg + 7; |
2718ff09 LT |
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(peek_remote_usage); | |
18705953 JH |
47 | } |
48 | dest = arg; | |
49 | break; | |
50 | } | |
2718ff09 | 51 | |
18705953 JH |
52 | if (!dest || i != argc - 1) |
53 | usage(peek_remote_usage); | |
54 | ||
18f7c51c DB |
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; | |
18705953 | 70 | } |