]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/ls-remote.c
Merge branch 'jn/unpack-lstat-failure-report'
[thirdparty/git.git] / builtin / ls-remote.c
index 70f5622d9d49aae4080b38ee4487cc6e403a9d2c..97eed4012ba23cfe7f13cf2b6c160ade54f6b2d1 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"
+"                     [-q|--quiet] [<repository> [<refs>...]]";
 
 /*
  * Is there one among the list of patterns that match the tail part
@@ -31,8 +32,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 {
        int i;
        const char *dest = NULL;
-       int nongit;
        unsigned flags = 0;
+       int quiet = 0;
        const char *uploadpack = NULL;
        const char **pattern = NULL;
 
@@ -40,8 +41,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
        struct transport *transport;
        const struct ref *ref;
 
-       setup_git_directory_gently(&nongit);
-
        for (i = 1; i < argc; i++) {
                const char *arg = argv[i];
 
@@ -66,6 +65,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
                                flags |= REF_NORMAL;
                                continue;
                        }
+                       if (!strcmp("--quiet", arg) || !strcmp("-q", arg)) {
+                               quiet = 1;
+                               continue;
+                       }
                        usage(ls_remote_usage);
                }
                dest = arg;
@@ -73,9 +76,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 +87,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);
@@ -96,6 +101,9 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
        ref = transport_get_remote_refs(transport);
        if (transport_disconnect(transport))
                return 1;
+
+       if (!dest && !quiet)
+               fprintf(stderr, "From %s\n", *remote->url);
        for ( ; ref; ref = ref->next) {
                if (!check_ref_type(ref, flags))
                        continue;