upload-archive: handle "-h" option early

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>

Jeff King committed May 30, 2017 at 01:13 UTC 619b6c1710f726866f62e34b01cc57c03b390299
1 file changed +4 -1
builtin/upload-archive.c
+4 -1
@@ -22,7 +22,7 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
22 struct argv_array sent_argv = ARGV_ARRAY_INIT;
23 const char *arg_cmd = "argument ";
24
25 - if (argc != 2)
25 + if (argc != 2 || !strcmp(argv[1], "-h"))
26 usage(upload_archive_usage);
27
28 if (!enter_repo(argv[1], 0))
@@ -76,6 +76,9 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
76 {
77 struct child_process writer = { argv };
78
79 + if (argc == 2 && !strcmp(argv[1], "-h"))
80 + usage(upload_archive_usage);
81 +
82 /*
83 * Set up sideband subprocess.
84 *