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

[PATCH] ls-remote: add --get-push-url option

From
Ben Boeckel <mathstuf@gmail.com>
Date
Jul 31, 2015, 17:38 UTC
Message-ID
<1438364321-14646-2-git-send-email-mathstuf@gmail.com>
In-Reply-To
<1438364321-14646-1-git-send-email-mathstuf@gmail.com>

With pushInsteadOf and triangle workflows, a flag to have git fully expand the push URL is also useful since it can be very different from the --get-url output.

Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
---
 Documentation/git-ls-remote.txt |  7 ++++++-
 builtin/ls-remote.c             | 15 +++++++++++++--
 2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
index 2e22915..66cda0e 100644
--- a/Documentation/git-ls-remote.txt
+++ b/Documentation/git-ls-remote.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git ls-remote' [--heads] [--tags]  [-u <exec> | --upload-pack <exec>]
-	      [--exit-code] <repository> [<refs>...]
+	      [--exit-code] [--get-url | --get-push-url] <repository> [<refs>...]
 
 DESCRIPTION
 -----------
@@ -47,6 +47,11 @@ OPTIONS
 	"url.<base>.insteadOf" config setting (See linkgit:git-config[1]) and
 	exit without talking to the remote.
 
+--get-push-url::
+	Expand the URL of the given remote repository taking into account any
+	"url.<base>.pushInsteadOf" config setting (See linkgit:git-config[1])
+	and exit without talking to the remote.
+
 <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 4554dbc..25c6f79 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -5,7 +5,7 @@
 
 static const char ls_remote_usage[] =
 "git ls-remote [--heads] [--tags]  [-u <exec> | --upload-pack <exec>]\n"
-"                     [-q | --quiet] [--exit-code] [--get-url] [<repository> [<refs>...]]";
+"                     [-q | --quiet] [--exit-code] [--get-url | --get-push-url] [<repository> [<refs>...]]";
 
 /*
  * Is there one among the list of patterns that match the tail part
@@ -40,6 +40,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	const char **pattern = NULL;
 
 	struct remote *remote;
+	struct remote *pushremote;
 	struct transport *transport;
 	const struct ref *ref;
 
@@ -78,6 +79,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 				get_url = 1;
 				continue;
 			}
+			if (!strcmp("--get-push-url", arg)) {
+				get_url = 2;
+				continue;
+			}
 			if (!strcmp("--exit-code", arg)) {
 				/* return this code if no refs are reported */
 				status = 2;
@@ -109,9 +114,15 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	if (!remote->url_nr)
 		die("remote %s has no configured URL", dest);
 
-	if (get_url) {
+	if (get_url == 1) {
 		printf("%s\n", *remote->url);
 		return 0;
+	} else if (get_url == 2) {
+		pushremote = pushremote_get(dest);
+		if (!pushremote->url_nr)
+			die("remote %s has no configured push URL", dest);
+		printf("%s\n", *pushremote->url);
+		return 0;
 	}
 
 	transport = transport_get(remote, NULL);
-- 
2.1.0
Previous: Ben BoeckelNext: Junio C Hamano
Message 2 of 22 in “add ls-remote --get-push-url option”
  1. add ls-remote --get-push-url optionBen Boeckel, Jul 31, 2015
  2. ls-remote: add --get-push-url optionBen Boeckel, Jul 31, 2015
  3. Junio C HamanoJul 31, 2015
  4. Ben BoeckelJul 31, 2015
  5. Junio C HamanoJul 31, 2015
  6. Ben BoeckelJul 31, 2015
  7. Junio C HamanoJul 31, 2015
  8. Ben BoeckelJul 31, 2015
  9. add git-url subcommandBen Boeckel, Aug 3, 2015
  10. remote: add get-url subcommandBen Boeckel, Aug 3, 2015
  11. Eric SunshineAug 3, 2015
  12. Ben BoeckelAug 4, 2015
  13. Eric SunshineAug 4, 2015
  14. remote: add get-url subcommandBen Boeckel, Aug 4, 2015
  15. Junio C HamanoAug 5, 2015
  16. Ben BoeckelAug 5, 2015
  17. Junio C HamanoAug 5, 2015
  18. remote: add get-url subcommandBen Boeckel, Sep 4, 2015
  19. Junio C HamanoSep 4, 2015
  20. remote: add get-url subcommandBen Boeckel, Sep 16, 2015
  21. Junio C HamanoSep 16, 2015
  22. remote: add get-url subcommandBen Boeckel, Sep 17, 2015

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.