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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jan 16, 2025 at 13:35 UTC
b821c999ca5cb472160a2ebb33aeeac5efc2fddc
14 files changed
+31
-32
builtin/am.c
+1
-2
@@ -2427,8 +2427,7 @@ int cmd_am(int argc,
2427
OPT_END()
2428
};
2429
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);
2431
2432
git_config(git_default_config, NULL);
2433
builtin/branch.c
+2
-2
@@ -784,8 +784,8 @@ int cmd_branch(int argc,
784
filter.kind = FILTER_REFS_BRANCHES;
785
filter.abbrev = -1;
786
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);
789
790
/*
791
* Try to set sort keys from config. If config does not set any,
builtin/checkout--worker.c
+3
-3
@@ -128,9 +128,9 @@ int cmd_checkout__worker(int argc,
128
OPT_END()
129
};
130
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);
134
135
git_config(git_default_config, NULL);
136
argc = parse_options(argc, argv, prefix, checkout_worker_options,
builtin/checkout-index.c
+3
-3
@@ -250,9 +250,9 @@ int cmd_checkout_index(int argc,
250
OPT_END()
251
};
252
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);
256
git_config(git_default_config, NULL);
257
prefix_length = prefix ? strlen(prefix) : 0;
258
builtin/commit-tree.c
+2
-2
@@ -119,8 +119,8 @@ int cmd_commit_tree(int argc,
119
120
git_config(git_default_config, NULL);
121
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);
124
125
argc = parse_options(argc, argv, prefix, options, commit_tree_usage, 0);
126
builtin/commit.c
+4
-4
@@ -1559,8 +1559,8 @@ struct repository *repo UNUSED)
1559
OPT_END(),
1560
};
1561
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);
1564
1565
prepare_repo_settings(the_repository);
1566
the_repository->settings.command_requires_full_index = 0;
@@ -1736,8 +1736,8 @@ int cmd_commit(int argc,
1736
struct strbuf err = STRBUF_INIT;
1737
int ret = 0;
1738
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);
1741
1742
prepare_repo_settings(the_repository);
1743
the_repository->settings.command_requires_full_index = 0;
builtin/fsmonitor--daemon.c
+2
-2
@@ -1598,8 +1598,8 @@ int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix UNUSED
1598
OPT_END()
1599
};
1600
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);
1603
1604
die(_("fsmonitor--daemon not supported on this platform"));
1605
}
builtin/gc.c
+2
-2
@@ -710,8 +710,8 @@ struct repository *repo UNUSED)
710
OPT_END()
711
};
712
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);
715
716
strvec_pushl(&reflog, "reflog", "expire", "--all", NULL);
717
strvec_pushl(&repack, "repack", "-d", "-l", NULL);
builtin/ls-files.c
+2
-2
@@ -644,8 +644,8 @@ int cmd_ls_files(int argc,
644
};
645
int ret = 0;
646
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);
649
650
prepare_repo_settings(the_repository);
651
the_repository->settings.command_requires_full_index = 0;
builtin/merge.c
+2
-2
@@ -1300,8 +1300,8 @@ int cmd_merge(int argc,
1300
void *branch_to_free;
1301
int orig_argc = argc;
1302
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);
1305
1306
prepare_repo_settings(the_repository);
1307
the_repository->settings.command_requires_full_index = 0;
builtin/rebase.c
+3
-3
@@ -1223,9 +1223,9 @@ int cmd_rebase(int argc,
1223
};
1224
int i;
1225
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);
1229
1230
prepare_repo_settings(the_repository);
1231
the_repository->settings.command_requires_full_index = 0;
builtin/update-index.c
+2
-2
@@ -1045,8 +1045,8 @@ int cmd_update_index(int argc,
1045
OPT_END()
1046
};
1047
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);
1050
1051
git_config(git_default_config, NULL);
1052
t/helper/test-simple-ipc.c
+2
-2
@@ -612,8 +612,8 @@ int cmd__simple_ipc(int argc, const char **argv)
612
if (argc < 2)
613
usage_with_options(simple_ipc_usage, options);
614
615
- if (argc == 2 && !strcmp(argv[1], "-h"))
616
- usage_with_options(simple_ipc_usage, options);
615
+ show_usage_with_options_if_asked(argc, argv,
616
+ simple_ipc_usage, options);
617
618
if (argc == 2 && !strcmp(argv[1], "SUPPORTS_SIMPLE_IPC"))
619
return 0;
t/t7600-merge.sh
+1
-1
@@ -173,7 +173,7 @@ test_expect_success 'merge -h with invalid index' '
173
cd broken &&
174
git init &&
175
>.git/index &&
176
- test_expect_code 129 git merge -h 2>usage
176
+ test_expect_code 129 git merge -h >usage
177
) &&
178
test_grep "[Uu]sage: git merge" broken/usage
179
'