Browse Source

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>
maint
Jonathan Nieder 15 years ago committed by Junio C Hamano
parent
commit
99caeed05d
  1. 6
      builtin-log.c
  2. 8
      builtin-mv.c
  3. 4
      builtin-read-tree.c
  4. 3
      builtin-reflog.c
  5. 3
      builtin-rerere.c
  6. 7
      git.c
  7. 3
      index-pack.c
  8. 3
      pack-redundant.c

6
builtin-log.c

@ -50,6 +50,12 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix, @@ -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)

8
builtin-mv.c

@ -64,15 +64,15 @@ int cmd_mv(int argc, const char **argv, const char *prefix) @@ -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);

4
builtin-read-tree.c

@ -108,11 +108,11 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix) @@ -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?");

3
builtin-reflog.c

@ -698,6 +698,9 @@ static const char reflog_usage[] = @@ -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);

3
builtin-rerere.c

@ -106,6 +106,9 @@ int cmd_rerere(int argc, const char **argv, const char *prefix) @@ -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;

7
git.c

@ -229,11 +229,13 @@ struct cmd_struct { @@ -229,11 +229,13 @@ 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;
help = argc == 2 && !strcmp(argv[1], "-h");
if (!help) {
if (p->option & RUN_SETUP)
prefix = setup_git_directory();

@ -241,9 +243,10 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) @@ -241,9 +243,10 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
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");

3
index-pack.c

@ -882,6 +882,9 @@ int main(int argc, char **argv) @@ -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().

3
pack-redundant.c

@ -603,6 +603,9 @@ int main(int argc, char **argv) @@ -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++) {

Loading…
Cancel
Save