6 static const char * const ls_remote_usage
[] = {
7 N_("git ls-remote [--heads] [--tags] [--refs] [--upload-pack=<exec>]\n"
8 " [-q | --quiet] [--exit-code] [--get-url]\n"
9 " [--symref] [<repository> [<refs>...]]"),
14 * Is there one among the list of patterns that match the tail part
17 static int tail_match(const char **pattern
, const char *path
)
23 return 1; /* no restriction */
25 pathbuf
= xstrfmt("/%s", path
);
26 while ((p
= *(pattern
++)) != NULL
) {
27 if (!wildmatch(p
, pathbuf
, 0)) {
36 int cmd_ls_remote(int argc
, const char **argv
, const char *prefix
)
38 const char *dest
= NULL
;
43 int show_symref_target
= 0;
44 const char *uploadpack
= NULL
;
45 const char **pattern
= NULL
;
47 struct remote
*remote
;
48 struct transport
*transport
;
49 const struct ref
*ref
;
51 struct option options
[] = {
52 OPT__QUIET(&quiet
, N_("do not print remote URL")),
53 OPT_STRING(0, "upload-pack", &uploadpack
, N_("exec"),
54 N_("path of git-upload-pack on the remote host")),
55 { OPTION_STRING
, 0, "exec", &uploadpack
, N_("exec"),
56 N_("path of git-upload-pack on the remote host"),
58 OPT_BIT('t', "tags", &flags
, N_("limit to tags"), REF_TAGS
),
59 OPT_BIT('h', "heads", &flags
, N_("limit to heads"), REF_HEADS
),
60 OPT_BIT(0, "refs", &flags
, N_("do not show peeled tags"), REF_NORMAL
),
61 OPT_BOOL(0, "get-url", &get_url
,
62 N_("take url.<base>.insteadOf into account")),
63 OPT_SET_INT_F(0, "exit-code", &status
,
64 N_("exit with exit code 2 if no matching refs are found"),
65 2, PARSE_OPT_NOCOMPLETE
),
66 OPT_BOOL(0, "symref", &show_symref_target
,
67 N_("show underlying ref in addition to the object pointed by it")),
71 argc
= parse_options(argc
, argv
, prefix
, options
, ls_remote_usage
,
72 PARSE_OPT_STOP_AT_NON_OPTION
);
77 pattern
= xcalloc(argc
, sizeof(const char *));
78 for (i
= 1; i
< argc
; i
++)
79 pattern
[i
- 1] = xstrfmt("*/%s", argv
[i
]);
82 remote
= remote_get(dest
);
85 die("bad repository '%s'", dest
);
86 die("No remote configured to list refs from.");
89 die("remote %s has no configured URL", dest
);
92 printf("%s\n", *remote
->url
);
96 transport
= transport_get(remote
, NULL
);
97 if (uploadpack
!= NULL
)
98 transport_set_option(transport
, TRANS_OPT_UPLOADPACK
, uploadpack
);
100 ref
= transport_get_remote_refs(transport
);
101 if (transport_disconnect(transport
))
105 fprintf(stderr
, "From %s\n", *remote
->url
);
106 for ( ; ref
; ref
= ref
->next
) {
107 if (!check_ref_type(ref
, flags
))
109 if (!tail_match(pattern
, ref
->name
))
111 if (show_symref_target
&& ref
->symref
)
112 printf("ref: %s\t%s\n", ref
->symref
, ref
->name
);
113 printf("%s\t%s\n", oid_to_hex(&ref
->old_oid
), ref
->name
);
114 status
= 0; /* we found something */