upload-archive: handle "-h" option early
authorJeff King <peff@peff.net>
Tue, 30 May 2017 05:13:43 +0000 (01:13 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 30 May 2017 05:45:04 +0000 (14:45 +0900)
Normally upload-archive forks off upload-archive--writer to
do the real work, and relays any errors back over the
sideband channel. This is a good thing when the command is
properly invoked remotely via ssh or git-daemon. But it's
confusing to curious users who try "git upload-archive -h".

Let's catch this invocation early and give a real usage
message, rather than spewing "-h does not appear to be a git
repository" amidst packet-lines. The chance of a false
positive due to a real client asking for the repo "-h" is
quite small.

Likewise, we'll catch "-h" in upload-archive--writer. People
shouldn't be invoking it manually, but it doesn't hurt to
give a sane message if they do.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/upload-archive.c
index cde06977b78b1475925e4b6722b5ecdd834847d5..84532ae9a93e7fb526a6fd28901875b3a10f3ffa 100644 (file)
@@ -22,7 +22,7 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
        struct argv_array sent_argv = ARGV_ARRAY_INIT;
        const char *arg_cmd = "argument ";
 
-       if (argc != 2)
+       if (argc != 2 || !strcmp(argv[1], "-h"))
                usage(upload_archive_usage);
 
        if (!enter_repo(argv[1], 0))
@@ -76,6 +76,9 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
 {
        struct child_process writer = { argv };
 
+       if (argc == 2 && !strcmp(argv[1], "-h"))
+               usage(upload_archive_usage);
+
        /*
         * Set up sideband subprocess.
         *