git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 0/5] ls-remote: introduce symref argument

From
Thomas Gummerer <t.gummerer@gmail.com>
Date
Jan 18, 2016, 23:20 UTC
Message-ID
<1453159250-21298-1-git-send-email-t.gummerer@gmail.com>
In-Reply-To
<1453136238-19448-1-git-send-email-t.gummerer@gmail.com>

The previous rounds are at $gmane/284248. Thanks to Peff and Junio for reviewing and suggestions on the previous round.

Changes from the previous round:
 - Slightly reworded the documentation for the --refs option
 - Small fix in the commit message of patch 4.
 - use <<-\EOF instead of <<-EOF in the tests
 - added a note about upload-pack only showing the HEAD symref
 - squashed in tests by peff
 - changed --symrefs option to --symref
 - reworded description and documentation of the option according to
   comments from junio.
Interdiff below:
diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
index 9356df2..5f2628c 100644
--- a/Documentation/git-ls-remote.txt
+++ b/Documentation/git-ls-remote.txt
@@ -11,7 +11,7 @@ SYNOPSIS
 [verse]
 'git ls-remote' [--heads] [--tags] [--refs] [--upload-pack=<exec>]
 	      [-q | --quiet] [--exit-code] [--get-url]
-	      [--symrefs] [<repository> [<refs>...]]
+	      [--symref] [<repository> [<refs>...]]
 
 DESCRIPTION
 -----------
@@ -31,8 +31,7 @@ OPTIONS
 	displayed.
 
 --refs::
-	Do not show peeled tags or pseudo-refs like HEAD or MERGE_HEAD
-	in the output.
+	Do not show peeled tags or pseudorefs like HEAD	in the output.
 
 -q::
 --quiet::
@@ -55,8 +54,11 @@ 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.
+--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>::
 	The "remote" repository to query.  This parameter can be
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index ea73d53..66cdd45 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -6,7 +6,7 @@
 static const char * const ls_remote_usage[] = {
 	N_("git ls-remote [--heads] [--tags] [--refs] [--upload-pack=<exec>]\n"
 	   "                     [-q | --quiet] [--exit-code] [--get-url]\n"
-	   "                     [--symrefs] [<repository> [<refs>...]]"),
+	   "                     [--symref] [<repository> [<refs>...]]"),
 	NULL
 };
 
@@ -38,7 +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;
+	int show_symref_target = 0;
 	const char *uploadpack = NULL;
 	const char **pattern = NULL;
 
@@ -60,7 +60,8 @@ 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_BOOL(0, "symref", &show_symref_target,
+			 N_("show underlying ref in addition to the object pointed by it")),
 		OPT_END()
 	};
 
@@ -104,7 +105,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 			continue;
 		if (!tail_match(pattern, ref->name))
 			continue;
-		if (symrefs && ref->symref)
+		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 */
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index 3edbc9e..819b9dd 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -163,8 +163,8 @@ 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 &&
+test_expect_success 'ls-remote --symref' '
+	cat >expect <<-\EOF &&
 	ref: refs/heads/master	HEAD
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	HEAD
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/heads/master
@@ -172,17 +172,40 @@ test_expect_success 'ls-remote --symrefs' '
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/master
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
 	EOF
-	git ls-remote --symrefs >actual &&
+	git ls-remote --symref >actual &&
 	test_cmp expect actual
 '
 
-test_expect_success 'ls-remote with filtered symrefs' '
-	cat >expect <<-EOF &&
+test_expect_success 'ls-remote with filtered symref (refname)' '
+	cat >expect <<-\EOF &&
 	ref: refs/heads/master	HEAD
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	HEAD
 	EOF
-	git ls-remote --symrefs . HEAD >actual &&
+	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

Thomas Gummerer (5):
  ls-remote: document --quiet option
  ls-remote: document --refs option
  ls-remote: fix synopsis
  ls-remote: use parse-options api
  ls-remote: add support for showing symrefs

 Documentation/git-ls-remote.txt | 16 +++++++-
 builtin/ls-remote.c             | 90 +++++++++++++++++------------------------
 t/t5512-ls-remote.sh            | 45 +++++++++++++++++++++
 3 files changed, 95 insertions(+), 56 deletions(-)
-- 
2.7.0.30.g56a8654.dirty
Previous: Jeff KingNext: Thomas Gummerer
Message 38 of 44 in “ls-remote: introduce symref argument”
  1. 0/4 ls-remote: introduce symref argumentThomas Gummerer, Jan 17, 2016
  2. 1/4 ls-remote: document --quiet optionThomas Gummerer, Jan 17, 2016
  3. Jeff KingJan 17, 2016
  4. Thomas GummererJan 17, 2016
  5. 2/4 ls-remote: fix synopsisThomas Gummerer, Jan 17, 2016
  6. 3/4 ls-remote: use parse-options apiThomas Gummerer, Jan 17, 2016
  7. Jeff KingJan 17, 2016
  8. Thomas GummererJan 17, 2016
  9. 4/4 builtin/ls-remote: add support for showing symrefsThomas Gummerer, Jan 17, 2016
  10. Thomas GummererJan 17, 2016
  11. 4/4 ls-remote: add support for showing symrefsThomas Gummerer, Jan 17, 2016
  12. Jeff KingJan 17, 2016
  13. Thomas GummererJan 17, 2016
  14. Junio C HamanoJan 17, 2016
  15. Thomas GummererJan 17, 2016
  16. Jeff KingJan 17, 2016
  17. Thomas GummererJan 17, 2016
  18. Junio C HamanoJan 17, 2016
  19. 0/5 ls-remote: introduce symrefs argumentThomas Gummerer, Jan 18, 2016
  20. 1/5 ls-remote: document --quiet optionThomas Gummerer, Jan 18, 2016
  21. 2/5 ls-remote: document --refs optionThomas Gummerer, Jan 18, 2016
  22. Jeff KingJan 18, 2016
  23. Junio C HamanoJan 18, 2016
  24. Thomas GummererJan 18, 2016
  25. 3/5 ls-remote: fix synopsisThomas Gummerer, Jan 18, 2016
  26. 4/5 ls-remote: use parse-options apiThomas Gummerer, Jan 18, 2016
  27. Jeff KingJan 18, 2016
  28. 5/5 ls-remote: add support for showing symrefsThomas Gummerer, Jan 18, 2016
  29. Jeff KingJan 18, 2016
  30. Jeff KingJan 18, 2016
  31. Thomas GummererJan 18, 2016
  32. Thomas GummererJan 18, 2016
  33. Jeff KingJan 18, 2016
  34. Thomas GummererJan 18, 2016
  35. Junio C HamanoJan 18, 2016
  36. Thomas GummererJan 18, 2016
  37. Jeff KingJan 18, 2016
  38. 0/5 ls-remote: introduce symref argumentThomas Gummerer, Jan 18, 2016
  39. 1/5 ls-remote: document --quiet optionThomas Gummerer, Jan 18, 2016
  40. 2/5 ls-remote: document --refs optionThomas Gummerer, Jan 18, 2016
  41. 3/5 ls-remote: fix synopsisThomas Gummerer, Jan 18, 2016
  42. 4/5 ls-remote: use parse-options apiThomas Gummerer, Jan 18, 2016
  43. 5/5 ls-remote: add support for showing symrefsThomas Gummerer, Jan 18, 2016
  44. Junio C HamanoJan 19, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.