6 static const char ls_remote_usage[] =
7 "git-ls-remote [--upload-pack=<git-upload-pack>] [<host>:]<directory>";
10 * pattern is a list of tail-part of accepted refnames. Is there one
11 * among them that is a suffix of the path? Directory boundary must
12 * be honored when checking this match. IOW, patterns "master" and
13 * "sa/master" both match path "refs/hold/sa/master". On the other
14 * hand, path "refs/hold/foosa/master" is matched by "master" but not
18 static int tail_match(const char **pattern, const char *path)
24 return 1; /* no restriction */
26 for (pathlen = strlen(path); (p = *pattern); pattern++) {
27 int pfxlen = pathlen - strlen(p);
29 continue; /* pattern is longer, will never match */
30 if (strcmp(path + pfxlen, p))
31 continue; /* no tail match */
32 if (!pfxlen || path[pfxlen - 1] == '/')
33 return 1; /* fully match at directory boundary */
38 int cmd_ls_remote(int argc, const char **argv, const char *prefix)
41 const char *dest = NULL;
44 const char *uploadpack = NULL;
45 const char **pattern = NULL;
47 struct remote *remote;
48 struct transport *transport;
49 const struct ref *ref;
51 setup_git_directory_gently(&nongit);
53 for (i = 1; i < argc; i++) {
54 const char *arg = argv[i];
57 if (!prefixcmp(arg, "--upload-pack=")) {
58 uploadpack = arg + 14;
61 if (!prefixcmp(arg, "--exec=")) {
65 if (!strcmp("--tags", arg)) {
69 if (!strcmp("--heads", arg)) {
73 if (!strcmp("--refs", arg)) {
77 usage(ls_remote_usage);
84 usage(ls_remote_usage);
85 pattern = argv + i + 1;
86 remote = nongit ? NULL : remote_get(dest);
87 if (remote && !remote->url_nr)
88 die("remote %s has no configured URL", dest);
89 transport = transport_get(remote, remote ? remote->url[0] : dest);
90 if (uploadpack != NULL)
91 transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
93 ref = transport_get_remote_refs(transport);
98 for ( ; ref; ref = ref->next) {
99 if (!check_ref_type(ref, flags))
101 if (!tail_match(pattern, ref->name))
103 printf("%s %s\n", sha1_to_hex(ref->old_sha1), ref->name);