All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ls-remote: default to 'origin' when no remote specified
@ 2010-04-08  3:58 Tay Ray Chuan
  2010-04-08  4:45 ` Jeff King
                   ` (3 more replies)
  0 siblings, 4 replies; 18+ messages in thread
From: Tay Ray Chuan @ 2010-04-08  3:58 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano, Jeff King

Instead of breaking execution when no remote (as specified in the
variable dest) is specified when git-ls-remote is invoked, continue on
and let remote_get() handle it.

That way, we are able to use the default remote (by default, "origin"),
as git-fetch, git-push, and others, do.

While we're at it, die with a more interesting message ("Where do you
want to..."), as git-fetch does, instead of the plain usage help.

Add several tests to check that git-ls-remote handles the
no-remote-specified situation.

Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---
 builtin/ls-remote.c  |    5 ++---
 t/t5512-ls-remote.sh |   37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 70f5622..dfada83 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -73,9 +73,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		break;
 	}
 
-	if (!dest)
-		usage(ls_remote_usage);
-
 	if (argv[i]) {
 		int j;
 		pattern = xcalloc(sizeof(const char *), argc - i + 1);
@@ -87,6 +84,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		}
 	}
 	remote = remote_get(dest);
+	if (!remote)
+		die("Where do you want to list from today?");
 	if (!remote->url_nr)
 		die("remote %s has no configured URL", dest);
 	transport = transport_get(remote, NULL);
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index 1dd8eed..e19429b 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -49,4 +49,41 @@ test_expect_success 'ls-remote self' '
 
 '
 
+cat >exp <<EOF
+fatal: Where do you want to list from today?
+EOF
+test_expect_success 'dies with message when no remote specified and no default remote found' '
+
+	!(git ls-remote >actual 2>&1) &&
+	test_cmp exp actual
+
+'
+
+test_expect_success 'defaults to "origin" when no remote specified' '
+
+	git remote add origin "$(pwd)/.git"
+	git ls-remote >actual &&
+	test_cmp expected.all actual
+
+'
+
+cat >exp <<EOF
+fatal: 'refs*master' does not appear to be a git repository
+fatal: The remote end hung up unexpectedly
+EOF
+test_expect_success 'confuses pattern as remote when no remote specified' '
+	#
+	# Although ugly, this behaviour is akin to the confusion of refspecs for
+	# remotes by git-fetch and git-push, eg:
+	#
+	#   $ git fetch branch
+	#
+
+	# We could just as easily have used "master"; the "*" emphasizes its
+	# role as a pattern.
+	!(git ls-remote refs*master >actual 2>&1) &&
+	test_cmp exp actual
+
+'
+
 test_done
-- 
1.7.0.97.g1372c

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2010-04-09  9:22 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-08  3:58 [PATCH] ls-remote: default to 'origin' when no remote specified Tay Ray Chuan
2010-04-08  4:45 ` Jeff King
2010-04-08  5:35   ` Junio C Hamano
2010-04-08  6:25     ` Jeff King
2010-04-08  6:07   ` Tay Ray Chuan
2010-04-08  6:34     ` Jeff King
2010-04-08  6:44       ` Junio C Hamano
2010-04-08  6:47         ` Jeff King
2010-04-08  5:05 ` Junio C Hamano
2010-04-08  5:58   ` Tay Ray Chuan
2010-04-08  7:05 ` [PATCH v2] ls-remote: fall-back to default remotes " Tay Ray Chuan
2010-04-08  7:07 ` [PATCH v2 (resend)] " Tay Ray Chuan
2010-04-08  7:16   ` Jeff King
2010-04-08 17:10     ` Tay Ray Chuan
2010-04-08 17:21   ` [PATCH v3] " Tay Ray Chuan
2010-04-08 19:19     ` Jeff King
2010-04-09  8:49     ` Peter Kjellerstedt
2010-04-09  9:15       ` Tay Ray Chuan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.