[PATCH v2] Show usage string for 'git http-push -h'
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Nov 9, 2009, 10:47 UTC
- Message-ID
- <20091109104732.GA15519@progeny.tock>
- In-Reply-To
- <be6fef0d0911090052s158ac720ha1fac70da748106d@mail.gmail.com>
http-push already knows how to dump usage if it is given no options, but it interprets '-h' as the URL to a remote repository:
$ git http-push -h error: Cannot access URL -h/, return code 6
Dump usage instead. Humans wanting to pass the URL -h/ to curl for some reason can use 'git http-push -h/' explicitly. Scripts expecting to access an HTTP repository at URL '-h' will break, though.
Also delay finding a git directory until after option parsing, so "http-push -h" can be used outside any git repository.
Cc: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> --- Tay Ray Chuan wrote:
> just curious, I'm wondering why isn't the check for "-h" done in the > argv loop later on? I see this being done already in the builtins > diff, log, ls-remote and update-index.
Good question. :)
(I was making sure "git http-push -h" would work without a git directory by putting the check for -h before setup_git_directory(). But nothing in the argv loop requires a git repository, so it is better and simpler to move the setup_git_directory() call to after the loop. Thanks for the catch.)
> Also, unlike grep, -h <arg> is not an option we're looking out for, so > I'm not sure if we should allow the user to mix -h with a valid set of > arguments (which is what Johnathan's patch would allow).
Makes sense.
http-push.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/http-push.c b/http-push.c index 00e83dc..ad1a6c9 100644 --- a/http-push.c +++ b/http-push.c @@ -1792,8 +1792,6 @@ int main(int argc, char **argv) git_extract_argv0_path(argv[0]); - setup_git_directory(); - repo = xcalloc(sizeof(*repo), 1); argv++; @@ -1827,6 +1825,8 @@ int main(int argc, char **argv) force_delete = 1; continue; } + if (!strcmp(arg, "-h")) + usage(http_push_usage); } if (!repo->url) { char *path = strstr(arg, "//"); @@ -1854,6 +1854,8 @@ int main(int argc, char **argv) if (delete_branch && nr_refspec != 1) die("You must specify only one branch name when deleting a remote branch"); + setup_git_directory(); + memset(remote_dir_exists, -1, 256); /*
-- 1.6.5.2