1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-09 12:36:08 +02:00

Let 'git <command> -h' show usage without a git dir

There is no need for "git <command> -h" to depend on being inside
a repository.

Reported by Gerfried Fuchs through http://bugs.debian.org/462557

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jonathan Nieder 2009-11-09 09:05:01 -06:00 committed by Junio C Hamano
parent 548d3464dc
commit 99caeed05d
8 changed files with 35 additions and 14 deletions

View File

@ -50,6 +50,12 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
if (default_date_mode)
rev->date_mode = parse_date_format(default_date_mode);
/*
* Check for -h before setup_revisions(), or "git log -h" will
* fail when run without a git directory.
*/
if (argc == 2 && !strcmp(argv[1], "-h"))
usage(builtin_log_usage);
argc = setup_revisions(argc, argv, rev, "HEAD");
if (rev->diffopt.pickaxe || rev->diffopt.filter)

View File

@ -64,15 +64,15 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
git_config(git_default_config, NULL);
newfd = hold_locked_index(&lock_file, 1);
if (read_cache() < 0)
die("index file corrupt");
argc = parse_options(argc, argv, prefix, builtin_mv_options,
builtin_mv_usage, 0);
if (--argc < 1)
usage_with_options(builtin_mv_usage, builtin_mv_options);
newfd = hold_locked_index(&lock_file, 1);
if (read_cache() < 0)
die("index file corrupt");
source = copy_pathspec(prefix, argv, argc, 0);
modes = xcalloc(argc, sizeof(enum update_mode));
dest_path = copy_pathspec(prefix, argv + argc, 1, 0);

View File

@ -108,11 +108,11 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
git_config(git_default_config, NULL);
newfd = hold_locked_index(&lock_file, 1);
argc = parse_options(argc, argv, unused_prefix, read_tree_options,
read_tree_usage, 0);
newfd = hold_locked_index(&lock_file, 1);
prefix_set = opts.prefix ? 1 : 0;
if (1 < opts.merge + opts.reset + prefix_set)
die("Which one? -m, --reset, or --prefix?");

View File

@ -698,6 +698,9 @@ static const char reflog_usage[] =
int cmd_reflog(int argc, const char **argv, const char *prefix)
{
if (argc > 1 && !strcmp(argv[1], "-h"))
usage(reflog_usage);
/* With no command, we default to showing it. */
if (argc < 2 || *argv[1] == '-')
return cmd_log_reflog(argc, argv, prefix);

View File

@ -106,6 +106,9 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
if (argc < 2)
return rerere();
if (!strcmp(argv[1], "-h"))
usage(git_rerere_usage);
fd = setup_rerere(&merge_rr);
if (fd < 0)
return 0;

19
git.c
View File

@ -229,21 +229,24 @@ struct cmd_struct {
static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
{
int status;
int status, help;
struct stat st;
const char *prefix;
prefix = NULL;
if (p->option & RUN_SETUP)
prefix = setup_git_directory();
help = argc == 2 && !strcmp(argv[1], "-h");
if (!help) {
if (p->option & RUN_SETUP)
prefix = setup_git_directory();
if (use_pager == -1 && p->option & RUN_SETUP)
use_pager = check_pager_config(p->cmd);
if (use_pager == -1 && p->option & USE_PAGER)
use_pager = 1;
if (use_pager == -1 && p->option & RUN_SETUP)
use_pager = check_pager_config(p->cmd);
if (use_pager == -1 && p->option & USE_PAGER)
use_pager = 1;
}
commit_pager_choice();
if (p->option & NEED_WORK_TREE)
if (!help && p->option & NEED_WORK_TREE)
setup_work_tree();
trace_argv_printf(argv, "trace: built-in: git");

View File

@ -882,6 +882,9 @@ int main(int argc, char **argv)
git_extract_argv0_path(argv[0]);
if (argc == 2 && !strcmp(argv[1], "-h"))
usage(index_pack_usage);
/*
* We wish to read the repository's config file if any, and
* for that it is necessary to call setup_git_directory_gently().

View File

@ -603,6 +603,9 @@ int main(int argc, char **argv)
git_extract_argv0_path(argv[0]);
if (argc == 2 && !strcmp(argv[1], "-h"))
usage(pack_redundant_usage);
setup_git_directory();
for (i = 1; i < argc; i++) {