Merge branch 'tg/ls-remote-symref'
"ls-remote" learned an option to show which branch the remote repository advertises as its primary by pointing its HEAD at. * tg/ls-remote-symref: ls-remote: add support for showing symrefs ls-remote: use parse-options api ls-remote: fix synopsis ls-remote: document --refs option ls-remote: document --quiet option
This commit is contained in:
commit
bd6934af9b
@ -9,8 +9,9 @@ git-ls-remote - List references in a remote repository
|
|||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
--------
|
--------
|
||||||
[verse]
|
[verse]
|
||||||
'git ls-remote' [--heads] [--tags] [--upload-pack=<exec>]
|
'git ls-remote' [--heads] [--tags] [--refs] [--upload-pack=<exec>]
|
||||||
[--exit-code] <repository> [<refs>...]
|
[-q | --quiet] [--exit-code] [--get-url]
|
||||||
|
[--symref] [<repository> [<refs>...]]
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
@ -29,6 +30,13 @@ OPTIONS
|
|||||||
both, references stored in refs/heads and refs/tags are
|
both, references stored in refs/heads and refs/tags are
|
||||||
displayed.
|
displayed.
|
||||||
|
|
||||||
|
--refs::
|
||||||
|
Do not show peeled tags or pseudorefs like HEAD in the output.
|
||||||
|
|
||||||
|
-q::
|
||||||
|
--quiet::
|
||||||
|
Do not print remote URL to stderr.
|
||||||
|
|
||||||
--upload-pack=<exec>::
|
--upload-pack=<exec>::
|
||||||
Specify the full path of 'git-upload-pack' on the remote
|
Specify the full path of 'git-upload-pack' on the remote
|
||||||
host. This allows listing references from repositories accessed via
|
host. This allows listing references from repositories accessed via
|
||||||
@ -46,6 +54,12 @@ OPTIONS
|
|||||||
"url.<base>.insteadOf" config setting (See linkgit:git-config[1]) and
|
"url.<base>.insteadOf" config setting (See linkgit:git-config[1]) and
|
||||||
exit without talking to the remote.
|
exit without talking to the remote.
|
||||||
|
|
||||||
|
--symref::
|
||||||
|
In addition to the object pointed by it, show the underlying
|
||||||
|
ref pointed by it when showing a symbolic ref. Currently,
|
||||||
|
upload-pack only shows the symref HEAD, so it will be the only
|
||||||
|
one shown by ls-remote.
|
||||||
|
|
||||||
<repository>::
|
<repository>::
|
||||||
The "remote" repository to query. This parameter can be
|
The "remote" repository to query. This parameter can be
|
||||||
either a URL or the name of a remote (see the GIT URLS and
|
either a URL or the name of a remote (see the GIT URLS and
|
||||||
|
@ -3,9 +3,12 @@
|
|||||||
#include "transport.h"
|
#include "transport.h"
|
||||||
#include "remote.h"
|
#include "remote.h"
|
||||||
|
|
||||||
static const char ls_remote_usage[] =
|
static const char * const ls_remote_usage[] = {
|
||||||
"git ls-remote [--heads] [--tags] [--upload-pack=<exec>]\n"
|
N_("git ls-remote [--heads] [--tags] [--refs] [--upload-pack=<exec>]\n"
|
||||||
" [-q | --quiet] [--exit-code] [--get-url] [<repository> [<refs>...]]";
|
" [-q | --quiet] [--exit-code] [--get-url]\n"
|
||||||
|
" [--symref] [<repository> [<refs>...]]"),
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Is there one among the list of patterns that match the tail part
|
* Is there one among the list of patterns that match the tail part
|
||||||
@ -30,12 +33,12 @@ static int tail_match(const char **pattern, const char *path)
|
|||||||
|
|
||||||
int cmd_ls_remote(int argc, const char **argv, const char *prefix)
|
int cmd_ls_remote(int argc, const char **argv, const char *prefix)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
const char *dest = NULL;
|
const char *dest = NULL;
|
||||||
unsigned flags = 0;
|
unsigned flags = 0;
|
||||||
int get_url = 0;
|
int get_url = 0;
|
||||||
int quiet = 0;
|
int quiet = 0;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
int show_symref_target = 0;
|
||||||
const char *uploadpack = NULL;
|
const char *uploadpack = NULL;
|
||||||
const char **pattern = NULL;
|
const char **pattern = NULL;
|
||||||
|
|
||||||
@ -43,59 +46,36 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
|
|||||||
struct transport *transport;
|
struct transport *transport;
|
||||||
const struct ref *ref;
|
const struct ref *ref;
|
||||||
|
|
||||||
if (argc == 2 && !strcmp("-h", argv[1]))
|
struct option options[] = {
|
||||||
usage(ls_remote_usage);
|
OPT__QUIET(&quiet, N_("do not print remote URL")),
|
||||||
|
OPT_STRING(0, "upload-pack", &uploadpack, N_("exec"),
|
||||||
|
N_("path of git-upload-pack on the remote host")),
|
||||||
|
{ OPTION_STRING, 0, "exec", &uploadpack, N_("exec"),
|
||||||
|
N_("path of git-upload-pack on the remote host"),
|
||||||
|
PARSE_OPT_HIDDEN },
|
||||||
|
OPT_BIT('t', "tags", &flags, N_("limit to tags"), REF_TAGS),
|
||||||
|
OPT_BIT('h', "heads", &flags, N_("limit to heads"), REF_HEADS),
|
||||||
|
OPT_BIT(0, "refs", &flags, N_("do not show peeled tags"), REF_NORMAL),
|
||||||
|
OPT_BOOL(0, "get-url", &get_url,
|
||||||
|
N_("take url.<base>.insteadOf into account")),
|
||||||
|
OPT_SET_INT(0, "exit-code", &status,
|
||||||
|
N_("exit with exit code 2 if no matching refs are found"), 2),
|
||||||
|
OPT_BOOL(0, "symref", &show_symref_target,
|
||||||
|
N_("show underlying ref in addition to the object pointed by it")),
|
||||||
|
OPT_END()
|
||||||
|
};
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
argc = parse_options(argc, argv, prefix, options, ls_remote_usage,
|
||||||
const char *arg = argv[i];
|
PARSE_OPT_STOP_AT_NON_OPTION);
|
||||||
|
dest = argv[0];
|
||||||
|
|
||||||
if (*arg == '-') {
|
if (argc > 1) {
|
||||||
if (starts_with(arg, "--upload-pack=")) {
|
int i;
|
||||||
uploadpack = arg + 14;
|
pattern = xcalloc(argc, sizeof(const char *));
|
||||||
continue;
|
for (i = 1; i < argc; i++)
|
||||||
}
|
pattern[i - 1] = xstrfmt("*/%s", argv[i]);
|
||||||
if (starts_with(arg, "--exec=")) {
|
|
||||||
uploadpack = arg + 7;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!strcmp("--tags", arg) || !strcmp("-t", arg)) {
|
|
||||||
flags |= REF_TAGS;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!strcmp("--heads", arg) || !strcmp("-h", arg)) {
|
|
||||||
flags |= REF_HEADS;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!strcmp("--refs", arg)) {
|
|
||||||
flags |= REF_NORMAL;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!strcmp("--quiet", arg) || !strcmp("-q", arg)) {
|
|
||||||
quiet = 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!strcmp("--get-url", arg)) {
|
|
||||||
get_url = 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!strcmp("--exit-code", arg)) {
|
|
||||||
/* return this code if no refs are reported */
|
|
||||||
status = 2;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
usage(ls_remote_usage);
|
|
||||||
}
|
|
||||||
dest = arg;
|
|
||||||
i++;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv[i]) {
|
|
||||||
int j;
|
|
||||||
pattern = xcalloc(argc - i + 1, sizeof(const char *));
|
|
||||||
for (j = i; j < argc; j++)
|
|
||||||
pattern[j - i] = xstrfmt("*/%s", argv[j]);
|
|
||||||
}
|
|
||||||
remote = remote_get(dest);
|
remote = remote_get(dest);
|
||||||
if (!remote) {
|
if (!remote) {
|
||||||
if (dest)
|
if (dest)
|
||||||
@ -125,7 +105,9 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
|
|||||||
continue;
|
continue;
|
||||||
if (!tail_match(pattern, ref->name))
|
if (!tail_match(pattern, ref->name))
|
||||||
continue;
|
continue;
|
||||||
printf("%s %s\n", oid_to_hex(&ref->old_oid), ref->name);
|
if (show_symref_target && ref->symref)
|
||||||
|
printf("ref: %s\t%s\n", ref->symref, ref->name);
|
||||||
|
printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
|
||||||
status = 0; /* we found something */
|
status = 0; /* we found something */
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
|
@ -163,4 +163,49 @@ test_expect_success 'overrides work between mixed transfer/upload-pack hideRefs'
|
|||||||
grep refs/tags/magic actual
|
grep refs/tags/magic actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'ls-remote --symref' '
|
||||||
|
cat >expect <<-\EOF &&
|
||||||
|
ref: refs/heads/master HEAD
|
||||||
|
1bd44cb9d13204b0fe1958db0082f5028a16eb3a HEAD
|
||||||
|
1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/heads/master
|
||||||
|
1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/remotes/origin/HEAD
|
||||||
|
1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/remotes/origin/master
|
||||||
|
1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/tags/mark
|
||||||
|
EOF
|
||||||
|
git ls-remote --symref >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'ls-remote with filtered symref (refname)' '
|
||||||
|
cat >expect <<-\EOF &&
|
||||||
|
ref: refs/heads/master HEAD
|
||||||
|
1bd44cb9d13204b0fe1958db0082f5028a16eb3a HEAD
|
||||||
|
EOF
|
||||||
|
git ls-remote --symref . HEAD >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_failure 'ls-remote with filtered symref (--heads)' '
|
||||||
|
git symbolic-ref refs/heads/foo refs/tags/mark &&
|
||||||
|
cat >expect <<-\EOF &&
|
||||||
|
ref: refs/tags/mark refs/heads/foo
|
||||||
|
1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/heads/foo
|
||||||
|
1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/heads/master
|
||||||
|
EOF
|
||||||
|
git ls-remote --symref --heads . >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'ls-remote --symref omits filtered-out matches' '
|
||||||
|
cat >expect <<-\EOF &&
|
||||||
|
1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/heads/foo
|
||||||
|
1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/heads/master
|
||||||
|
EOF
|
||||||
|
git ls-remote --symref --heads . >actual &&
|
||||||
|
test_cmp expect actual &&
|
||||||
|
git ls-remote --symref . "refs/heads/*" >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user