# [PATCH] Reteach builtin-ls-remote to understand remotes

2 messages from 2007-11-07 to 2007-11-07. Participants: Shawn O. Pearce, Junio C Hamano.
Thread: https://gitlist.dev/t/10693

## Shawn O. Pearce, 2007-11-07 01:29

Subject: [PATCH] Reteach builtin-ls-remote to understand remotes
Message-ID: <20071107012920.GA9961@spearce.org>
URL: https://gitlist.dev/e/20071107012920.GA9961%40spearce.org

```
Prior to being made a builtin git-ls-remote understood that when
it was given a remote name we wanted it to resolve that to the
pre-configured URL and connect to that location.  That changed when
it was converted to a builtin and many of my automation tools broke.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 builtin-ls-remote.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/builtin-ls-remote.c b/builtin-ls-remote.c
index 003580c..56f3f88 100644
--- a/builtin-ls-remote.c
+++ b/builtin-ls-remote.c
@@ -14,6 +14,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	unsigned flags = 0;
 	const char *uploadpack = NULL;
 
+	struct remote *remote;
 	struct transport *transport;
 	const struct ref *ref;
 
@@ -52,7 +53,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	if (!dest || i != argc - 1)
 		usage(ls_remote_usage);
 
-	transport = transport_get(NULL, dest);
+	remote = nongit ? NULL : remote_get(dest);
+	if (remote && !remote->url_nr)
+		die("remote %s has no configured URL", dest);
+	transport = transport_get(remote, remote ? remote->url[0] : dest);
 	if (uploadpack != NULL)
 		transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
 
-- 
1.5.3.5.1590.gfadfad

```

## Junio C Hamano, 2007-11-07 06:24

Subject: Re: [PATCH] Reteach builtin-ls-remote to understand remotes
Message-ID: <7vtznyefp0.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vtznyefp0.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <20071107012920.GA9961@spearce.org>

```
"Shawn O. Pearce" <spearce@spearce.org> writes:

> Prior to being made a builtin git-ls-remote understood that when
> it was given a remote name we wanted it to resolve that to the
> pre-configured URL and connect to that location.  That changed when
> it was converted to a builtin and many of my automation tools broke.

Thanks.  I will squash this in.

---
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
new file mode 100755
index 0000000..6ec5f7c
--- /dev/null
+++ b/t/t5512-ls-remote.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+test_description='git ls-remote'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+
+	>file &&
+	git add file &&
+	test_tick &&
+	git commit -m initial &&
+	git tag mark &&
+	git show-ref --tags -d | sed -e "s/ /	/" >expected.tag &&
+	(
+		echo "$(git rev-parse HEAD)	HEAD"
+		git show-ref -d	| sed -e "s/ /	/"
+	) >expected.all &&
+
+	git remote add self $(pwd)/.git
+
+'
+
+test_expect_success 'ls-remote --tags .git' '
+
+	git ls-remote --tags .git >actual &&
+	diff -u expected.tag actual
+
+'
+
+test_expect_success 'ls-remote .git' '
+
+	git ls-remote .git >actual &&
+	diff -u expected.all actual
+
+'
+
+test_expect_success 'ls-remote --tags self' '
+
+	git ls-remote --tags self >actual &&
+	diff -u expected.tag actual
+
+'
+
+test_expect_success 'ls-remote self' '
+
+	git ls-remote self >actual &&
+	diff -u expected.all actual
+
+'
+
+test_done

```
