[PATCH v2 5/5] ls-remote: add support for showing symrefs
From: Thomas Gummerer <hidden>
Date: 2016-06-15 23:07:48
Subsystem:
documentation, the rest · Maintainers:
Jonathan Corbet, Linus Torvalds
Sometimes it's useful to know the main branch of a git repository without actually downloading the repository. This can be done by looking at the symrefs stored in the remote repository. Currently git doesn't provide a simple way to show the symrefs stored on the remote repository, even though the information is available. Add a --symrefs command line argument to the ls-remote command, which shows the symrefs on the remote repository. The new argument works similar to the --heads and --tags arguments. When only --symrefs is given, only the symrefs are shown. It can however be combined with the --refs, --heads or --tags arguments, to show all refs, heads, or tags as well. While there, replace a literal tab in the format string with \t to make it more obvious to the reader. Suggested-by: pedro rijo <redacted> Signed-off-by: Thomas Gummerer <redacted> --- Documentation/git-ls-remote.txt | 6 +++++- builtin/ls-remote.c | 9 +++++++-- t/t5512-ls-remote.sh | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
index f7d1091..9356df2 100644
--- a/Documentation/git-ls-remote.txt
+++ b/Documentation/git-ls-remote.txt@@ -10,7 +10,8 @@ SYNOPSIS -------- [verse] 'git ls-remote' [--heads] [--tags] [--refs] [--upload-pack=<exec>] - [-q | --quiet] [--exit-code] [--get-url] [<repository> [<refs>...]] + [-q | --quiet] [--exit-code] [--get-url] + [--symrefs] [<repository> [<refs>...]] DESCRIPTION -----------
@@ -54,6 +55,9 @@ OPTIONS "url.<base>.insteadOf" config setting (See linkgit:git-config[1]) and exit without talking to the remote. +--symrefs:: + Show the symrefs in addition to the other refs. + <repository>:: The "remote" repository to query. This parameter can be either a URL or the name of a remote (see the GIT URLS and
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 3a20378..ea73d53 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c@@ -5,7 +5,8 @@ static const char * const ls_remote_usage[] = { 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" + " [--symrefs] [<repository> [<refs>...]]"), NULL };
@@ -37,6 +38,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) int get_url = 0; int quiet = 0; int status = 0; + int symrefs = 0; const char *uploadpack = NULL; const char **pattern = NULL;
@@ -58,6 +60,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) 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, "symrefs", &symrefs, N_("show symrefs")), OPT_END() };
@@ -101,7 +104,9 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) continue; if (!tail_match(pattern, ref->name)) continue; - printf("%s %s\n", oid_to_hex(&ref->old_oid), ref->name); + if (symrefs && 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 */ } return status;
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index aadaac5..3edbc9e 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh@@ -163,4 +163,26 @@ test_expect_success 'overrides work between mixed transfer/upload-pack hideRefs' grep refs/tags/magic actual ' +test_expect_success 'ls-remote --symrefs' ' + 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 --symrefs >actual && + test_cmp expect actual +' + +test_expect_success 'ls-remote with filtered symrefs' ' + cat >expect <<-EOF && + ref: refs/heads/master HEAD + 1bd44cb9d13204b0fe1958db0082f5028a16eb3a HEAD + EOF + git ls-remote --symrefs . HEAD >actual && + test_cmp expect actual +' + test_done
--
2.7.0.30.gd0a78e9.dirty