Skip to content

Commit 750054c

Browse files
committed
Merge branch 'jn/help-everywhere'
* jn/help-everywhere: (23 commits) diff --no-index: make the usage string less scary merge-{recursive,subtree}: use usagef() to print usage Introduce usagef() that takes a printf-style format Let 'git <command> -h' show usage without a git dir Show usage string for 'git http-push -h' Let 'git http-fetch -h' show usage outside any git repository Show usage string for 'git stripspace -h' Show usage string for 'git unpack-file -h' Show usage string for 'git show-index -h' Show usage string for 'git rev-parse -h' Show usage string for 'git merge-one-file -h' Show usage string for 'git mailsplit -h' Show usage string for 'git imap-send -h' Show usage string for 'git get-tar-commit-id -h' Show usage string for 'git fast-import -h' Show usage string for 'git check-ref-format -h' http-fetch: add missing initialization of argv0_path Show usage string for 'git show-ref -h' Show usage string for 'git merge-ours -h' Show usage string for 'git commit-tree -h' ... Conflicts: imap-send.c
2 parents 1b8dbdb + d74bb30 commit 750054c

32 files changed

Lines changed: 147 additions & 41 deletions

Documentation/git-show-ref.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ git-show-ref - List references in a local repository
88
SYNOPSIS
99
--------
1010
[verse]
11-
'git show-ref' [-q|--quiet] [--verify] [-h|--head] [-d|--dereference]
11+
'git show-ref' [-q|--quiet] [--verify] [--head] [-d|--dereference]
1212
[-s|--hash[=<n>]] [--abbrev[=<n>]] [--tags]
1313
[--heads] [--] <pattern>...
1414
'git show-ref' --exclude-existing[=<pattern>] < ref-list
@@ -30,7 +30,6 @@ the `.git` directory.
3030
OPTIONS
3131
-------
3232

33-
-h::
3433
--head::
3534

3635
Show the HEAD reference.

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,6 @@ BUILTIN_OBJS += builtin-diff-index.o
602602
BUILTIN_OBJS += builtin-diff-tree.o
603603
BUILTIN_OBJS += builtin-diff.o
604604
BUILTIN_OBJS += builtin-fast-export.o
605-
BUILTIN_OBJS += builtin-fetch--tool.o
606605
BUILTIN_OBJS += builtin-fetch-pack.o
607606
BUILTIN_OBJS += builtin-fetch.o
608607
BUILTIN_OBJS += builtin-fmt-merge-msg.o

builtin-check-ref-format.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ static void collapse_slashes(char *dst, const char *src)
3535

3636
int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
3737
{
38+
if (argc == 2 && !strcmp(argv[1], "-h"))
39+
usage(builtin_check_ref_format_usage);
40+
3841
if (argc == 3 && !strcmp(argv[1], "--branch")) {
3942
struct strbuf sb = STRBUF_INIT;
4043

builtin-commit-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
105105

106106
git_config(git_default_config, NULL);
107107

108-
if (argc < 2)
108+
if (argc < 2 || !strcmp(argv[1], "-h"))
109109
usage(commit_tree_usage);
110110
if (get_sha1(argv[1], tree_sha1))
111111
die("Not a valid object name %s", argv[1]);

builtin-grep.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,13 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
788788
OPT_END()
789789
};
790790

791+
/*
792+
* 'git grep -h', unlike 'git grep -h <pattern>', is a request
793+
* to show usage information and exit.
794+
*/
795+
if (argc == 2 && !strcmp(argv[1], "-h"))
796+
usage_with_options(grep_usage, options);
797+
791798
memset(&opt, 0, sizeof(opt));
792799
opt.prefix = prefix;
793800
opt.prefix_length = (prefix && *prefix) ? strlen(prefix) : 0;

builtin-log.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
5050
if (default_date_mode)
5151
rev->date_mode = parse_date_format(default_date_mode);
5252

53+
/*
54+
* Check for -h before setup_revisions(), or "git log -h" will
55+
* fail when run without a git directory.
56+
*/
57+
if (argc == 2 && !strcmp(argv[1], "-h"))
58+
usage(builtin_log_usage);
5359
argc = setup_revisions(argc, argv, rev, "HEAD");
5460

5561
if (rev->diffopt.pickaxe || rev->diffopt.filter)
@@ -1242,6 +1248,9 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
12421248
argv++;
12431249
}
12441250

1251+
if (argc > 1 && !strcmp(argv[1], "-h"))
1252+
usage(cherry_usage);
1253+
12451254
switch (argc) {
12461255
case 4:
12471256
limit = argv[3];

builtin-mailsplit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ int cmd_mailsplit(int argc, const char **argv, const char *prefix)
231231
continue;
232232
} else if ( arg[1] == 'f' ) {
233233
nr = strtol(arg+2, NULL, 10);
234+
} else if ( arg[1] == 'h' ) {
235+
usage(git_mailsplit_usage);
234236
} else if ( arg[1] == 'b' && !arg[2] ) {
235237
allow_bare = 1;
236238
} else if (!strcmp(arg, "--keep-cr")) {

builtin-merge-ours.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@
1010
#include "git-compat-util.h"
1111
#include "builtin.h"
1212

13+
static const char builtin_merge_ours_usage[] =
14+
"git merge-ours <base>... -- HEAD <remote>...";
15+
1316
static const char *diff_index_args[] = {
1417
"diff-index", "--quiet", "--cached", "HEAD", "--", NULL
1518
};
1619
#define NARGS (ARRAY_SIZE(diff_index_args) - 1)
1720

1821
int cmd_merge_ours(int argc, const char **argv, const char *prefix)
1922
{
23+
if (argc == 2 && !strcmp(argv[1], "-h"))
24+
usage(builtin_merge_ours_usage);
25+
2026
/*
2127
* We need to exit with 2 if the index does not match our HEAD tree,
2228
* because the current index is what we will be committing as the

builtin-merge-recursive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
3333
}
3434

3535
if (argc < 4)
36-
die("Usage: %s <base>... -- <head> <remote> ...", argv[0]);
36+
usagef("%s <base>... -- <head> <remote> ...", argv[0]);
3737

3838
for (i = 1; i < argc; ++i) {
3939
if (!strcmp(argv[i], "--"))

builtin-mv.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
6464

6565
git_config(git_default_config, NULL);
6666

67-
newfd = hold_locked_index(&lock_file, 1);
68-
if (read_cache() < 0)
69-
die("index file corrupt");
70-
7167
argc = parse_options(argc, argv, prefix, builtin_mv_options,
7268
builtin_mv_usage, 0);
7369
if (--argc < 1)
7470
usage_with_options(builtin_mv_usage, builtin_mv_options);
7571

72+
newfd = hold_locked_index(&lock_file, 1);
73+
if (read_cache() < 0)
74+
die("index file corrupt");
75+
7676
source = copy_pathspec(prefix, argv, argc, 0);
7777
modes = xcalloc(argc, sizeof(enum update_mode));
7878
dest_path = copy_pathspec(prefix, argv + argc, 1, 0);

0 commit comments

Comments
 (0)