Skip to content

Commit b821c99

Browse files
committed
builtins: send usage_with_options() help text to standard output
Using the show_usage_with_options_if_asked() helper we introduced earlier, fix callers of usage_with_options() that want to show the help text when explicitly asked by the end-user. The help text now goes to the standard output stream for them. The test in t7600 for "git merge -h" may want to be retired, as the same is covered by t0012 already, but it is specifically testing that the "-h" option gets a response even with a corrupt index file, so for now let's leave it there. Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0148fd8 commit b821c99

14 files changed

+31
-32
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/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/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
@@ -710,8 +710,8 @@ struct repository *repo UNUSED)
710710
OPT_END()
711711
};
712712

713-
if (argc == 2 && !strcmp(argv[1], "-h"))
714-
usage_with_options(builtin_gc_usage, builtin_gc_options);
713+
show_usage_with_options_if_asked(argc, argv,
714+
builtin_gc_usage, builtin_gc_options);
715715

716716
strvec_pushl(&reflog, "reflog", "expire", "--all", NULL);
717717
strvec_pushl(&repack, "repack", "-d", "-l", NULL);

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/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;

0 commit comments

Comments
 (0)