Skip to content

Commit d33abef

Browse files
committed
Merge branch 'jc/show-usage-help' into seen
The help text from "git $cmd -h" appear on the standard output for some $cmd and the standard error for others. The built-in commands have been fixed to show them on the standard output consistently. * jc/show-usage-help: builtin: send usage() help text to standard output oddballs: send usage() help text to standard output builtins: send usage_with_options() help text to standard output usage: add show_usage_if_asked() parse-options: add show_usage_with_options_if_asked() t0012: optionally check that "-h" output goes to stdout
2 parents 165d80a + ef1a6cd commit d33abef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+123
-66
lines changed

builtin/am.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,8 +2427,7 @@ int cmd_am(int argc,
24272427
OPT_END()
24282428
};
24292429

2430-
if (argc == 2 && !strcmp(argv[1], "-h"))
2431-
usage_with_options(usage, options);
2430+
show_usage_with_options_if_asked(argc, argv, usage, options);
24322431

24332432
git_config(git_default_config, NULL);
24342433

builtin/backfill.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ int cmd_backfill(int argc, const char **argv, const char *prefix, struct reposit
136136
OPT_END(),
137137
};
138138

139-
if (argc == 2 && !strcmp(argv[1], "-h"))
140-
usage_with_options(builtin_backfill_usage, options);
139+
show_usage_with_options_if_asked(argc, argv,
140+
builtin_backfill_usage, options);
141141

142142
argc = parse_options(argc, argv, prefix, options, builtin_backfill_usage,
143143
0);

builtin/branch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,8 @@ int cmd_branch(int argc,
784784
filter.kind = FILTER_REFS_BRANCHES;
785785
filter.abbrev = -1;
786786

787-
if (argc == 2 && !strcmp(argv[1], "-h"))
788-
usage_with_options(builtin_branch_usage, options);
787+
show_usage_with_options_if_asked(argc, argv,
788+
builtin_branch_usage, options);
789789

790790
/*
791791
* Try to set sort keys from config. If config does not set any,

builtin/check-ref-format.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ int cmd_check_ref_format(int argc,
6464

6565
BUG_ON_NON_EMPTY_PREFIX(prefix);
6666

67-
if (argc == 2 && !strcmp(argv[1], "-h"))
68-
usage(builtin_check_ref_format_usage);
67+
show_usage_if_asked(argc, argv,
68+
builtin_check_ref_format_usage);
6969

7070
if (argc == 3 && !strcmp(argv[1], "--branch"))
7171
return check_ref_format_branch(argv[2]);

builtin/checkout--worker.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ int cmd_checkout__worker(int argc,
128128
OPT_END()
129129
};
130130

131-
if (argc == 2 && !strcmp(argv[1], "-h"))
132-
usage_with_options(checkout_worker_usage,
133-
checkout_worker_options);
131+
show_usage_with_options_if_asked(argc, argv,
132+
checkout_worker_usage,
133+
checkout_worker_options);
134134

135135
git_config(git_default_config, NULL);
136136
argc = parse_options(argc, argv, prefix, checkout_worker_options,

builtin/checkout-index.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ int cmd_checkout_index(int argc,
250250
OPT_END()
251251
};
252252

253-
if (argc == 2 && !strcmp(argv[1], "-h"))
254-
usage_with_options(builtin_checkout_index_usage,
255-
builtin_checkout_index_options);
253+
show_usage_with_options_if_asked(argc, argv,
254+
builtin_checkout_index_usage,
255+
builtin_checkout_index_options);
256256
git_config(git_default_config, NULL);
257257
prefix_length = prefix ? strlen(prefix) : 0;
258258

builtin/commit-tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ int cmd_commit_tree(int argc,
119119

120120
git_config(git_default_config, NULL);
121121

122-
if (argc < 2 || !strcmp(argv[1], "-h"))
123-
usage_with_options(commit_tree_usage, options);
122+
show_usage_with_options_if_asked(argc, argv,
123+
commit_tree_usage, options);
124124

125125
argc = parse_options(argc, argv, prefix, options, commit_tree_usage, 0);
126126

builtin/commit.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,8 +1559,8 @@ struct repository *repo UNUSED)
15591559
OPT_END(),
15601560
};
15611561

1562-
if (argc == 2 && !strcmp(argv[1], "-h"))
1563-
usage_with_options(builtin_status_usage, builtin_status_options);
1562+
show_usage_with_options_if_asked(argc, argv,
1563+
builtin_status_usage, builtin_status_options);
15641564

15651565
prepare_repo_settings(the_repository);
15661566
the_repository->settings.command_requires_full_index = 0;
@@ -1736,8 +1736,8 @@ int cmd_commit(int argc,
17361736
struct strbuf err = STRBUF_INIT;
17371737
int ret = 0;
17381738

1739-
if (argc == 2 && !strcmp(argv[1], "-h"))
1740-
usage_with_options(builtin_commit_usage, builtin_commit_options);
1739+
show_usage_with_options_if_asked(argc, argv,
1740+
builtin_commit_usage, builtin_commit_options);
17411741

17421742
prepare_repo_settings(the_repository);
17431743
the_repository->settings.command_requires_full_index = 0;

builtin/credential.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ int cmd_credential(int argc,
1818

1919
git_config(git_default_config, NULL);
2020

21-
if (argc != 2 || !strcmp(argv[1], "-h"))
21+
show_usage_if_asked(argc, argv, usage_msg);
22+
if (argc != 2)
2223
usage(usage_msg);
2324
op = argv[1];
2425

builtin/diff-files.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ int cmd_diff_files(int argc,
2929
int result;
3030
unsigned options = 0;
3131

32-
if (argc == 2 && !strcmp(argv[1], "-h"))
33-
usage(diff_files_usage);
32+
show_usage_if_asked(argc, argv, diff_files_usage);
3433

3534
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
3635

builtin/diff-index.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ int cmd_diff_index(int argc,
2626
int i;
2727
int result;
2828

29-
if (argc == 2 && !strcmp(argv[1], "-h"))
30-
usage(diff_cache_usage);
29+
show_usage_if_asked(argc, argv, diff_cache_usage);
3130

3231
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
3332

builtin/diff-tree.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ int cmd_diff_tree(int argc,
122122
int read_stdin = 0;
123123
int merge_base = 0;
124124

125-
if (argc == 2 && !strcmp(argv[1], "-h"))
126-
usage(diff_tree_usage);
125+
show_usage_if_asked(argc, argv, diff_tree_usage);
127126

128127
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
129128

builtin/fast-import.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3566,8 +3566,7 @@ int cmd_fast_import(int argc,
35663566
{
35673567
unsigned int i;
35683568

3569-
if (argc == 2 && !strcmp(argv[1], "-h"))
3570-
usage(fast_import_usage);
3569+
show_usage_if_asked(argc, argv, fast_import_usage);
35713570

35723571
reset_pack_idx_option(&pack_idx_opts);
35733572
git_pack_config();

builtin/fetch-pack.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ int cmd_fetch_pack(int argc,
7575
list_objects_filter_init(&args.filter_options);
7676
args.uploadpack = "git-upload-pack";
7777

78+
show_usage_if_asked(argc, argv, fetch_pack_usage);
79+
7880
for (i = 1; i < argc && *argv[i] == '-'; i++) {
7981
const char *arg = argv[i];
8082

builtin/fsmonitor--daemon.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,8 +1598,8 @@ int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix UNUSED
15981598
OPT_END()
15991599
};
16001600

1601-
if (argc == 2 && !strcmp(argv[1], "-h"))
1602-
usage_with_options(builtin_fsmonitor__daemon_usage, options);
1601+
show_usage_with_options_if_asked(argc, argv,
1602+
builtin_fsmonitor__daemon_usage, options);
16031603

16041604
die(_("fsmonitor--daemon not supported on this platform"));
16051605
}

builtin/gc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,8 @@ struct repository *repo UNUSED)
716716
OPT_END()
717717
};
718718

719-
if (argc == 2 && !strcmp(argv[1], "-h"))
720-
usage_with_options(builtin_gc_usage, builtin_gc_options);
719+
show_usage_with_options_if_asked(argc, argv,
720+
builtin_gc_usage, builtin_gc_options);
721721

722722
strvec_pushl(&reflog, "reflog", "expire", "--all", NULL);
723723
strvec_pushl(&repack, "repack", "-d", "-l", NULL);

builtin/get-tar-commit-id.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ static const char builtin_get_tar_commit_id_usage[] =
1313
#define HEADERSIZE (2 * RECORDSIZE)
1414

1515
int cmd_get_tar_commit_id(int argc,
16-
const char **argv UNUSED,
16+
const char **argv,
1717
const char *prefix,
1818
struct repository *repo UNUSED)
1919
{
@@ -27,6 +27,8 @@ int cmd_get_tar_commit_id(int argc,
2727

2828
BUG_ON_NON_EMPTY_PREFIX(prefix);
2929

30+
show_usage_if_asked(argc, argv, builtin_get_tar_commit_id_usage);
31+
3032
if (argc != 1)
3133
usage(builtin_get_tar_commit_id_usage);
3234

builtin/index-pack.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,8 +1900,7 @@ int cmd_index_pack(int argc,
19001900
*/
19011901
fetch_if_missing = 0;
19021902

1903-
if (argc == 2 && !strcmp(argv[1], "-h"))
1904-
usage(index_pack_usage);
1903+
show_usage_if_asked(argc, argv, index_pack_usage);
19051904

19061905
disable_replace_refs();
19071906
fsck_options.walk = mark_link;

builtin/ls-files.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,8 @@ int cmd_ls_files(int argc,
644644
};
645645
int ret = 0;
646646

647-
if (argc == 2 && !strcmp(argv[1], "-h"))
648-
usage_with_options(ls_files_usage, builtin_ls_files_options);
647+
show_usage_with_options_if_asked(argc, argv,
648+
ls_files_usage, builtin_ls_files_options);
649649

650650
prepare_repo_settings(the_repository);
651651
the_repository->settings.command_requires_full_index = 0;

builtin/mailsplit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ int cmd_mailsplit(int argc,
284284

285285
BUG_ON_NON_EMPTY_PREFIX(prefix);
286286

287+
show_usage_if_asked(argc, argv, git_mailsplit_usage);
288+
287289
for (argp = argv+1; *argp; argp++) {
288290
const char *arg = *argp;
289291

@@ -297,8 +299,6 @@ int cmd_mailsplit(int argc,
297299
continue;
298300
} else if ( arg[1] == 'f' ) {
299301
nr = strtol(arg+2, NULL, 10);
300-
} else if ( arg[1] == 'h' ) {
301-
usage(git_mailsplit_usage);
302302
} else if ( arg[1] == 'b' && !arg[2] ) {
303303
allow_bare = 1;
304304
} else if (!strcmp(arg, "--keep-cr")) {

builtin/merge-index.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ static void merge_all(void)
7575
}
7676
}
7777

78+
static const char usage_string[] =
79+
"git merge-index [-o] [-q] <merge-program> (-a | [--] [<filename>...])";
80+
7881
int cmd_merge_index(int argc,
7982
const char **argv,
8083
const char *prefix UNUSED,
@@ -87,8 +90,10 @@ int cmd_merge_index(int argc,
8790
*/
8891
signal(SIGCHLD, SIG_DFL);
8992

93+
show_usage_if_asked(argc, argv, usage_string);
94+
9095
if (argc < 3)
91-
usage("git merge-index [-o] [-q] <merge-program> (-a | [--] [<filename>...])");
96+
usage(usage_string);
9297

9398
repo_read_index(the_repository);
9499

builtin/merge-ours.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ int cmd_merge_ours(int argc,
2323
const char *prefix UNUSED,
2424
struct repository *repo UNUSED)
2525
{
26-
if (argc == 2 && !strcmp(argv[1], "-h"))
27-
usage(builtin_merge_ours_usage);
26+
show_usage_if_asked(argc, argv, builtin_merge_ours_usage);
2827

2928
/*
3029
* The contents of the current index becomes the tree we

builtin/merge-recursive.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ int cmd_merge_recursive(int argc,
3838
if (argv[0] && ends_with(argv[0], "-subtree"))
3939
o.subtree_shift = "";
4040

41+
if (argc == 2 && !strcmp(argv[1], "-h")) {
42+
struct strbuf msg = STRBUF_INIT;
43+
strbuf_addf(&msg, builtin_merge_recursive_usage, argv[0]);
44+
show_usage_if_asked(argc, argv, msg.buf);
45+
}
46+
4147
if (argc < 4)
4248
usagef(builtin_merge_recursive_usage, argv[0]);
4349

builtin/merge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,8 +1300,8 @@ int cmd_merge(int argc,
13001300
void *branch_to_free;
13011301
int orig_argc = argc;
13021302

1303-
if (argc == 2 && !strcmp(argv[1], "-h"))
1304-
usage_with_options(builtin_merge_usage, builtin_merge_options);
1303+
show_usage_with_options_if_asked(argc, argv,
1304+
builtin_merge_usage, builtin_merge_options);
13051305

13061306
prepare_repo_settings(the_repository);
13071307
the_repository->settings.command_requires_full_index = 0;

builtin/pack-redundant.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, s
595595
struct strbuf idx_name = STRBUF_INIT;
596596
char buf[GIT_MAX_HEXSZ + 2]; /* hex hash + \n + \0 */
597597

598-
if (argc == 2 && !strcmp(argv[1], "-h"))
599-
usage(pack_redundant_usage);
598+
show_usage_if_asked(argc, argv, pack_redundant_usage);
600599

601600
for (i = 1; i < argc; i++) {
602601
const char *arg = argv[i];

builtin/rebase.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,9 +1223,9 @@ int cmd_rebase(int argc,
12231223
};
12241224
int i;
12251225

1226-
if (argc == 2 && !strcmp(argv[1], "-h"))
1227-
usage_with_options(builtin_rebase_usage,
1228-
builtin_rebase_options);
1226+
show_usage_with_options_if_asked(argc, argv,
1227+
builtin_rebase_usage,
1228+
builtin_rebase_options);
12291229

12301230
prepare_repo_settings(the_repository);
12311231
the_repository->settings.command_requires_full_index = 0;

builtin/remote-ext.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ int cmd_remote_ext(int argc,
202202
{
203203
BUG_ON_NON_EMPTY_PREFIX(prefix);
204204

205+
show_usage_if_asked(argc, argv, usage_msg);
206+
205207
if (argc != 3)
206208
usage(usage_msg);
207209

builtin/remote-fd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ int cmd_remote_fd(int argc,
6464

6565
BUG_ON_NON_EMPTY_PREFIX(prefix);
6666

67+
show_usage_if_asked(argc, argv, usage_msg);
6768
if (argc != 3)
6869
usage(usage_msg);
6970

builtin/rev-list.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,7 @@ int cmd_rev_list(int argc,
542542
const char *show_progress = NULL;
543543
int ret = 0;
544544

545-
if (argc == 2 && !strcmp(argv[1], "-h"))
546-
usage(rev_list_usage);
545+
show_usage_if_asked(argc, argv, rev_list_usage);
547546

548547
git_config(git_default_config, NULL);
549548
repo_init_revisions(the_repository, &revs, prefix);

builtin/rev-parse.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,8 @@ int cmd_rev_parse(int argc,
713713
int seen_end_of_options = 0;
714714
enum format_type format = FORMAT_DEFAULT;
715715

716+
show_usage_if_asked(argc, argv, builtin_rev_parse_usage);
717+
716718
if (argc > 1 && !strcmp("--parseopt", argv[1]))
717719
return cmd_parseopt(argc - 1, argv + 1, prefix);
718720

builtin/unpack-file.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,19 @@ static char *create_temp_file(struct object_id *oid)
2626
return path;
2727
}
2828

29+
static const char usage_msg[] =
30+
"git unpack-file <blob>";
31+
2932
int cmd_unpack_file(int argc,
3033
const char **argv,
3134
const char *prefix UNUSED,
3235
struct repository *repo UNUSED)
3336
{
3437
struct object_id oid;
3538

36-
if (argc != 2 || !strcmp(argv[1], "-h"))
37-
usage("git unpack-file <blob>");
39+
show_usage_if_asked(argc, argv, usage_msg);
40+
if (argc != 2)
41+
usage(usage_msg);
3842
if (repo_get_oid(the_repository, argv[1], &oid))
3943
die("Not a valid object name %s", argv[1]);
4044

builtin/unpack-objects.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,8 @@ int cmd_unpack_objects(int argc,
620620

621621
quiet = !isatty(2);
622622

623+
show_usage_if_asked(argc, argv, unpack_usage);
624+
623625
for (i = 1 ; i < argc; i++) {
624626
const char *arg = argv[i];
625627

builtin/update-index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,8 +1045,8 @@ int cmd_update_index(int argc,
10451045
OPT_END()
10461046
};
10471047

1048-
if (argc == 2 && !strcmp(argv[1], "-h"))
1049-
usage_with_options(update_index_usage, options);
1048+
show_usage_with_options_if_asked(argc, argv,
1049+
update_index_usage, options);
10501050

10511051
git_config(git_default_config, NULL);
10521052

0 commit comments

Comments
 (0)