Skip to content

Commit f0a371a

Browse files
committed
Merge branch 'jc/show-usage-help'
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 5f8f708 + f66d142 commit f0a371a

Some content is hidden

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

41 files changed

+121
-64
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/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

0 commit comments

Comments
 (0)