Merge branch 'rc/ls-remote-default'
authorJunio C Hamano <gitster@pobox.com>
Sun, 9 May 2010 05:37:28 +0000 (22:37 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 9 May 2010 05:37:28 +0000 (22:37 -0700)
* rc/ls-remote-default:
ls-remote: fall-back to default remotes when no remote specified

builtin/ls-remote.c
t/t5512-ls-remote.sh
index 70f5622d9d49aae4080b38ee4487cc6e403a9d2c..8ee91eb547c2bafedd573045c977cc7d0469c95f 100644 (file)
@@ -4,7 +4,8 @@
 #include "remote.h"
 
 static const char ls_remote_usage[] =
-"git ls-remote [--heads] [--tags]  [-u <exec> | --upload-pack <exec>] <repository> <refs>...";
+"git ls-remote [--heads] [--tags]  [-u <exec> | --upload-pack <exec>]\n"
+"                     [<repository> [<refs>...]]";
 
 /*
  * 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);
index 1dd8eed5bb3cb0f320a8f0780452e52fa7d8da16..3cf1b3da40a8d99631fabaa2cce4ff2b6d1b52ac 100755 (executable)
@@ -49,4 +49,62 @@ test_expect_success 'ls-remote self' '
 
 '
 
+test_expect_success 'dies when no remote specified and no default remotes found' '
+
+       test_must_fail git ls-remote
+
+'
+
+test_expect_success 'use "origin" when no remote specified' '
+
+       git remote add origin "$(pwd)/.git" &&
+       git ls-remote >actual &&
+       test_cmp expected.all actual
+
+'
+
+test_expect_success 'use branch.<name>.remote if possible' '
+
+       #
+       # Test that we are indeed using branch.<name>.remote, not "origin", even
+       # though the "origin" remote has been set.
+       #
+
+       # setup a new remote to differentiate from "origin"
+       git clone . other.git &&
+       (
+               cd other.git &&
+               echo "$(git rev-parse HEAD)     HEAD"
+               git show-ref    | sed -e "s/ /  /"
+       ) >exp &&
+
+       git remote add other other.git &&
+       git config branch.master.remote other &&
+
+       git ls-remote >actual &&
+       test_cmp exp 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' '
+       #
+       # Do not expect "git ls-remote <pattern>" to work; ls-remote, correctly,
+       # confuses <pattern> for <remote>. 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.
+       test_must_fail git ls-remote refs*master >actual 2>&1 &&
+       test_cmp exp actual
+
+'
+
 test_done