From 9c00de5a3135c8f7273668d4013c225d48d47861 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Fri, 9 Apr 2010 01:21:13 +0800 Subject: ls-remote: fall-back to default remotes when no remote specified 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. This way, we are able to use the default remotes (eg. "origin", branch..remote), as git-fetch, git-push, and other users of remote_get(), do. If no suitable remote is found, exit with a message describing the issue, instead of just the usage text, as we do previously. Add several tests to check that git-ls-remote handles the no-remote-specified situation. Also add a test that "git ls-remote " does not work; we are unable to guess the remote in that situation, as are git-fetch and git-push. In that test, we are testing for messages coming from two separate processes, but we should be OK, because the second message is triggered by closing the fd which must happen after the first message is printed. (analysis by Jeff King.) Signed-off-by: Tay Ray Chuan Acked-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/ls-remote.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'builtin') diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c index 70f5622d9d..8ee91eb547 100644 --- a/builtin/ls-remote.c +++ b/builtin/ls-remote.c @@ -4,7 +4,8 @@ #include "remote.h" static const char ls_remote_usage[] = -"git ls-remote [--heads] [--tags] [-u | --upload-pack ] ..."; +"git ls-remote [--heads] [--tags] [-u | --upload-pack ]\n" +" [ [...]]"; /* * Is there one among the list of patterns that match the tail part @@ -73,9 +74,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 +85,11 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) } } remote = remote_get(dest); + if (!remote) { + if (dest) + die("bad repository '%s'", dest); + die("No remote configured to list refs from."); + } if (!remote->url_nr) die("remote %s has no configured URL", dest); transport = transport_get(remote, NULL); -- cgit v1.2.3