Code

Merge branch 'jc/ls-remote-short-help'
authorJunio C Hamano <gitster@pobox.com>
Wed, 5 Oct 2011 19:36:26 +0000 (12:36 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 5 Oct 2011 19:36:26 +0000 (12:36 -0700)
* jc/ls-remote-short-help:
  ls-remote: a lone "-h" is asking for help

1  2 
builtin/ls-remote.c

diff --combined builtin/ls-remote.c
index 10223092a9ebfed4092db680529a42ca8886a9f2,87d44bc62512cb014a7410fc2ad4e9559fffb608..41c88a98a2de1ce817351243f9aa9e2811604097
@@@ -5,7 -5,7 +5,7 @@@
  
  static const char ls_remote_usage[] =
  "git ls-remote [--heads] [--tags]  [-u <exec> | --upload-pack <exec>]\n"
 -"                     [-q|--quiet] [<repository> [<refs>...]]";
 +"                     [-q|--quiet] [--exit-code] [<repository> [<refs>...]]";
  
  /*
   * Is there one among the list of patterns that match the tail part
@@@ -33,9 -33,7 +33,9 @@@ int cmd_ls_remote(int argc, const char 
        int i;
        const char *dest = NULL;
        unsigned flags = 0;
 +      int get_url = 0;
        int quiet = 0;
 +      int status = 0;
        const char *uploadpack = NULL;
        const char **pattern = NULL;
  
@@@ -43,6 -41,9 +43,9 @@@
        struct transport *transport;
        const struct ref *ref;
  
+       if (argc == 2 && !strcmp("-h", argv[1]))
+               usage(ls_remote_usage);
        for (i = 1; i < argc; i++) {
                const char *arg = argv[i];
  
                                quiet = 1;
                                continue;
                        }
 +                      if (!strcmp("--get-url", arg)) {
 +                              get_url = 1;
 +                              continue;
 +                      }
 +                      if (!strcmp("--exit-code", arg)) {
 +                              /* return this code if no refs are reported */
 +                              status = 2;
 +                              continue;
 +                      }
                        usage(ls_remote_usage);
                }
                dest = arg;
        }
        if (!remote->url_nr)
                die("remote %s has no configured URL", dest);
 +
 +      if (get_url) {
 +              printf("%s\n", *remote->url);
 +              return 0;
 +      }
 +
        transport = transport_get(remote, NULL);
        if (uploadpack != NULL)
                transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
                if (!tail_match(pattern, ref->name))
                        continue;
                printf("%s      %s\n", sha1_to_hex(ref->old_sha1), ref->name);
 +              status = 0; /* we found something */
        }
 -      return 0;
 +      return status;
  }