Let 'git http-fetch -h' show usage outside any git repository
Delay search for a git directory until option parsing has finished. None of the functions used in option parsing look for or read any files other than stdin, so this is safe. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
1a507b9cf7
commit
616f86d713
18
http-fetch.c
18
http-fetch.c
@ -2,6 +2,9 @@
|
|||||||
#include "exec_cmd.h"
|
#include "exec_cmd.h"
|
||||||
#include "walker.h"
|
#include "walker.h"
|
||||||
|
|
||||||
|
static const char http_fetch_usage[] = "git http-fetch "
|
||||||
|
"[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url";
|
||||||
|
|
||||||
int main(int argc, const char **argv)
|
int main(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
const char *prefix;
|
const char *prefix;
|
||||||
@ -21,8 +24,6 @@ int main(int argc, const char **argv)
|
|||||||
int get_recover = 0;
|
int get_recover = 0;
|
||||||
|
|
||||||
git_extract_argv0_path(argv[0]);
|
git_extract_argv0_path(argv[0]);
|
||||||
prefix = setup_git_directory();
|
|
||||||
git_config(git_default_config, NULL);
|
|
||||||
|
|
||||||
while (arg < argc && argv[arg][0] == '-') {
|
while (arg < argc && argv[arg][0] == '-') {
|
||||||
if (argv[arg][1] == 't') {
|
if (argv[arg][1] == 't') {
|
||||||
@ -38,6 +39,8 @@ int main(int argc, const char **argv)
|
|||||||
} else if (argv[arg][1] == 'w') {
|
} else if (argv[arg][1] == 'w') {
|
||||||
write_ref = &argv[arg + 1];
|
write_ref = &argv[arg + 1];
|
||||||
arg++;
|
arg++;
|
||||||
|
} else if (argv[arg][1] == 'h') {
|
||||||
|
usage(http_fetch_usage);
|
||||||
} else if (!strcmp(argv[arg], "--recover")) {
|
} else if (!strcmp(argv[arg], "--recover")) {
|
||||||
get_recover = 1;
|
get_recover = 1;
|
||||||
} else if (!strcmp(argv[arg], "--stdin")) {
|
} else if (!strcmp(argv[arg], "--stdin")) {
|
||||||
@ -45,10 +48,8 @@ int main(int argc, const char **argv)
|
|||||||
}
|
}
|
||||||
arg++;
|
arg++;
|
||||||
}
|
}
|
||||||
if (argc < arg + 2 - commits_on_stdin) {
|
if (argc != arg + 2 - commits_on_stdin)
|
||||||
usage("git http-fetch [-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url");
|
usage(http_fetch_usage);
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (commits_on_stdin) {
|
if (commits_on_stdin) {
|
||||||
commits = walker_targets_stdin(&commit_id, &write_ref);
|
commits = walker_targets_stdin(&commit_id, &write_ref);
|
||||||
} else {
|
} else {
|
||||||
@ -56,6 +57,11 @@ int main(int argc, const char **argv)
|
|||||||
commits = 1;
|
commits = 1;
|
||||||
}
|
}
|
||||||
url = argv[arg];
|
url = argv[arg];
|
||||||
|
|
||||||
|
prefix = setup_git_directory();
|
||||||
|
|
||||||
|
git_config(git_default_config, NULL);
|
||||||
|
|
||||||
if (url && url[strlen(url)-1] != '/') {
|
if (url && url[strlen(url)-1] != '/') {
|
||||||
rewritten_url = xmalloc(strlen(url)+2);
|
rewritten_url = xmalloc(strlen(url)+2);
|
||||||
strcpy(rewritten_url, url);
|
strcpy(rewritten_url, url);
|
||||||
|
Loading…
Reference in New Issue
Block a user