git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Gummerer <t.gummerer@gmail.com>
To: git@vger.kernel.org
Cc: peff@peff.net, bturner@atlassian.com, gitster@pobox.com,
	pedrorijo91@gmail.com, Thomas Gummerer <t.gummerer@gmail.com>
Subject: [PATCH v2 5/5] ls-remote: add support for showing symrefs
Date: Mon, 18 Jan 2016 17:57:18 +0100	[thread overview]
Message-ID: <1453136238-19448-6-git-send-email-t.gummerer@gmail.com> (raw)
In-Reply-To: <1453136238-19448-1-git-send-email-t.gummerer@gmail.com>

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 <pedrorijo91@gmail.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
---
 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

  parent reply	other threads:[~2016-01-18 16:57 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-17 11:03 [PATCH 0/4] ls-remote: introduce symref argument Thomas Gummerer
2016-01-17 11:03 ` [PATCH 1/4] ls-remote: document --quiet option Thomas Gummerer
2016-01-17 14:47   ` Jeff King
2016-01-17 17:13     ` Thomas Gummerer
2016-01-17 11:04 ` [PATCH 2/4] ls-remote: fix synopsis Thomas Gummerer
2016-01-17 11:04 ` [PATCH 3/4] ls-remote: use parse-options api Thomas Gummerer
2016-01-17 14:44   ` Jeff King
2016-01-17 17:27     ` Thomas Gummerer
2016-01-17 11:04 ` [PATCH 4/4] builtin/ls-remote: add support for showing symrefs Thomas Gummerer
2016-01-17 11:16   ` Thomas Gummerer
2016-01-17 11:04 ` [PATCH 4/4] ls-remote: " Thomas Gummerer
2016-01-17 15:15   ` Jeff King
2016-01-17 17:38     ` Thomas Gummerer
2016-01-17 22:14     ` Junio C Hamano
2016-01-17 11:14 ` [PATCH 0/4] ls-remote: introduce symref argument Thomas Gummerer
2016-01-17 15:16 ` Jeff King
2016-01-17 17:39   ` Thomas Gummerer
2016-01-17 22:15   ` Junio C Hamano
2016-01-18 16:57 ` [PATCH v2 0/5] ls-remote: introduce symrefs argument Thomas Gummerer
2016-01-18 16:57   ` [PATCH v2 1/5] ls-remote: document --quiet option Thomas Gummerer
2016-01-18 16:57   ` [PATCH v2 2/5] ls-remote: document --refs option Thomas Gummerer
2016-01-18 19:31     ` Jeff King
2016-01-18 20:01       ` Junio C Hamano
2016-01-18 21:39         ` Thomas Gummerer
2016-01-18 16:57   ` [PATCH v2 3/5] ls-remote: fix synopsis Thomas Gummerer
2016-01-18 16:57   ` [PATCH v2 4/5] ls-remote: use parse-options api Thomas Gummerer
2016-01-18 19:33     ` Jeff King
2016-01-18 16:57   ` Thomas Gummerer [this message]
2016-01-18 19:52     ` [PATCH v2 5/5] ls-remote: add support for showing symrefs Jeff King
2016-01-18 19:53       ` Jeff King
2016-01-18 22:09         ` Thomas Gummerer
2016-01-18 22:09       ` Thomas Gummerer
2016-01-18 22:20         ` Jeff King
2016-01-18 22:35           ` Thomas Gummerer
2016-01-18 20:09     ` Junio C Hamano
2016-01-18 21:48       ` Thomas Gummerer
2016-01-18 19:53   ` [PATCH v2 0/5] ls-remote: introduce symrefs argument Jeff King
2016-01-18 23:20   ` [PATCH v3 0/5] ls-remote: introduce symref argument Thomas Gummerer
2016-01-18 23:20     ` [PATCH v3 1/5] ls-remote: document --quiet option Thomas Gummerer
2016-01-18 23:20     ` [PATCH v3 2/5] ls-remote: document --refs option Thomas Gummerer
2016-01-18 23:20     ` [PATCH v3 3/5] ls-remote: fix synopsis Thomas Gummerer
2016-01-18 23:20     ` [PATCH v3 4/5] ls-remote: use parse-options api Thomas Gummerer
2016-01-18 23:20     ` [PATCH v3 5/5] ls-remote: add support for showing symrefs Thomas Gummerer
2016-01-19 18:14     ` [PATCH v3 0/5] ls-remote: introduce symref argument Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1453136238-19448-6-git-send-email-t.gummerer@gmail.com \
    --to=t.gummerer@gmail.com \
    --cc=bturner@atlassian.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pedrorijo91@gmail.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).