]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtins: send usage_with_options() help text to standard output
authorJunio C Hamano <gitster@pobox.com>
Thu, 16 Jan 2025 21:35:51 +0000 (13:35 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 17 Jan 2025 21:30:03 +0000 (13:30 -0800)
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>
14 files changed:
builtin/am.c
builtin/branch.c
builtin/checkout--worker.c
builtin/checkout-index.c
builtin/commit-tree.c
builtin/commit.c
builtin/fsmonitor--daemon.c
builtin/gc.c
builtin/ls-files.c
builtin/merge.c
builtin/rebase.c
builtin/update-index.c
t/helper/test-simple-ipc.c
t/t7600-merge.sh

index 1338b606febdde6700c573b45f89aa70785f54e8..8d8f38fa1d0789d73bb36c9190c88092e48e7de4 100644 (file)
@@ -2427,8 +2427,7 @@ int cmd_am(int argc,
                OPT_END()
        };
 
-       if (argc == 2 && !strcmp(argv[1], "-h"))
-               usage_with_options(usage, options);
+       show_usage_with_options_if_asked(argc, argv, usage, options);
 
        git_config(git_default_config, NULL);
 
index 6e7b0cfddbd6075d6692317d030f8d50472ad84e..7c8b4b65b666e8c4681a312234993aab5cb7922b 100644 (file)
@@ -784,8 +784,8 @@ int cmd_branch(int argc,
        filter.kind = FILTER_REFS_BRANCHES;
        filter.abbrev = -1;
 
-       if (argc == 2 && !strcmp(argv[1], "-h"))
-               usage_with_options(builtin_branch_usage, options);
+       show_usage_with_options_if_asked(argc, argv,
+                                        builtin_branch_usage, options);
 
        /*
         * Try to set sort keys from config. If config does not set any,
index b81002a1dfb4bbb05d2386ae9f03140bced1c82a..da9345a44b84de14743e28d947510afad8247c06 100644 (file)
@@ -128,9 +128,9 @@ int cmd_checkout__worker(int argc,
                OPT_END()
        };
 
-       if (argc == 2 && !strcmp(argv[1], "-h"))
-               usage_with_options(checkout_worker_usage,
-                                  checkout_worker_options);
+       show_usage_with_options_if_asked(argc, argv,
+                                        checkout_worker_usage,
+                                        checkout_worker_options);
 
        git_config(git_default_config, NULL);
        argc = parse_options(argc, argv, prefix, checkout_worker_options,
index a81501098d9fdbfd117ec9dcb76e9108b86b0ea3..e30086c7d471897cc81670eac387b4d99fa10668 100644 (file)
@@ -250,9 +250,9 @@ int cmd_checkout_index(int argc,
                OPT_END()
        };
 
-       if (argc == 2 && !strcmp(argv[1], "-h"))
-               usage_with_options(builtin_checkout_index_usage,
-                                  builtin_checkout_index_options);
+       show_usage_with_options_if_asked(argc, argv,
+                                        builtin_checkout_index_usage,
+                                        builtin_checkout_index_options);
        git_config(git_default_config, NULL);
        prefix_length = prefix ? strlen(prefix) : 0;
 
index 2ca1a57ebbb23096ba8bee25d999cacb7c62f901..38457600a4e4228d24b14e5e390896eedc3509e1 100644 (file)
@@ -119,8 +119,8 @@ int cmd_commit_tree(int argc,
 
        git_config(git_default_config, NULL);
 
-       if (argc < 2 || !strcmp(argv[1], "-h"))
-               usage_with_options(commit_tree_usage, options);
+       show_usage_with_options_if_asked(argc, argv,
+                                        commit_tree_usage, options);
 
        argc = parse_options(argc, argv, prefix, options, commit_tree_usage, 0);
 
index ef5e622c07746f86bb6d2fb2b909361bef1d1b10..c84062bfc13fd2b43eae21ec5dca6ce3ca4ba747 100644 (file)
@@ -1559,8 +1559,8 @@ struct repository *repo UNUSED)
                OPT_END(),
        };
 
-       if (argc == 2 && !strcmp(argv[1], "-h"))
-               usage_with_options(builtin_status_usage, builtin_status_options);
+       show_usage_with_options_if_asked(argc, argv,
+                                        builtin_status_usage, builtin_status_options);
 
        prepare_repo_settings(the_repository);
        the_repository->settings.command_requires_full_index = 0;
@@ -1736,8 +1736,8 @@ int cmd_commit(int argc,
        struct strbuf err = STRBUF_INIT;
        int ret = 0;
 
-       if (argc == 2 && !strcmp(argv[1], "-h"))
-               usage_with_options(builtin_commit_usage, builtin_commit_options);
+       show_usage_with_options_if_asked(argc, argv,
+                                        builtin_commit_usage, builtin_commit_options);
 
        prepare_repo_settings(the_repository);
        the_repository->settings.command_requires_full_index = 0;
index 029dc64d6c70fdc52b420053004729b794f4b322..0820e524f1a51717f962b0855ac616b2be0a8156 100644 (file)
@@ -1598,8 +1598,8 @@ int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix UNUSED
                OPT_END()
        };
 
-       if (argc == 2 && !strcmp(argv[1], "-h"))
-               usage_with_options(builtin_fsmonitor__daemon_usage, options);
+       show_usage_with_options_if_asked(argc, argv,
+                                        builtin_fsmonitor__daemon_usage, options);
 
        die(_("fsmonitor--daemon not supported on this platform"));
 }
index a9b1c36de27da2ffb16aaa45e979cbaeec18bfa1..ea007c8e7e5efe96676012d9975ac674980c0192 100644 (file)
@@ -710,8 +710,8 @@ struct repository *repo UNUSED)
                OPT_END()
        };
 
-       if (argc == 2 && !strcmp(argv[1], "-h"))
-               usage_with_options(builtin_gc_usage, builtin_gc_options);
+       show_usage_with_options_if_asked(argc, argv,
+                                        builtin_gc_usage, builtin_gc_options);
 
        strvec_pushl(&reflog, "reflog", "expire", "--all", NULL);
        strvec_pushl(&repack, "repack", "-d", "-l", NULL);
index 15499cd12b6bd5f97e24e3ca63f313fcc7f14e23..a4431429b7de42bab02c05db2d4b0d5ef65c1c3f 100644 (file)
@@ -644,8 +644,8 @@ int cmd_ls_files(int argc,
        };
        int ret = 0;
 
-       if (argc == 2 && !strcmp(argv[1], "-h"))
-               usage_with_options(ls_files_usage, builtin_ls_files_options);
+       show_usage_with_options_if_asked(argc, argv,
+                                        ls_files_usage, builtin_ls_files_options);
 
        prepare_repo_settings(the_repository);
        the_repository->settings.command_requires_full_index = 0;
index 5f67007bbad83389ea6d0c76d6c53ddf84b939ca..ba9faf126aa7a4430fb30d7407836ad280025537 100644 (file)
@@ -1300,8 +1300,8 @@ int cmd_merge(int argc,
        void *branch_to_free;
        int orig_argc = argc;
 
-       if (argc == 2 && !strcmp(argv[1], "-h"))
-               usage_with_options(builtin_merge_usage, builtin_merge_options);
+       show_usage_with_options_if_asked(argc, argv,
+                                        builtin_merge_usage, builtin_merge_options);
 
        prepare_repo_settings(the_repository);
        the_repository->settings.command_requires_full_index = 0;
index 0498fff3c96d5756fe01bdc0547e470fd6bfb2bd..6c9eaf3788c900fb52cb15255ae02b65abb711e3 100644 (file)
@@ -1223,9 +1223,9 @@ int cmd_rebase(int argc,
        };
        int i;
 
-       if (argc == 2 && !strcmp(argv[1], "-h"))
-               usage_with_options(builtin_rebase_usage,
-                                  builtin_rebase_options);
+       show_usage_with_options_if_asked(argc, argv,
+                                        builtin_rebase_usage,
+                                        builtin_rebase_options);
 
        prepare_repo_settings(the_repository);
        the_repository->settings.command_requires_full_index = 0;
index 74bbad9f87d86da0ae5520c39718bbe91098d5e0..b2f6b1a3fbb6cd1c914fe44ed0c6411a3de75330 100644 (file)
@@ -1045,8 +1045,8 @@ int cmd_update_index(int argc,
                OPT_END()
        };
 
-       if (argc == 2 && !strcmp(argv[1], "-h"))
-               usage_with_options(update_index_usage, options);
+       show_usage_with_options_if_asked(argc, argv,
+                                        update_index_usage, options);
 
        git_config(git_default_config, NULL);
 
index fb5927775daef80040ea9675742aa2cb47d46d4e..03cc5eea2c2944677548151446786f30db782332 100644 (file)
@@ -612,8 +612,8 @@ int cmd__simple_ipc(int argc, const char **argv)
        if (argc < 2)
                usage_with_options(simple_ipc_usage, options);
 
-       if (argc == 2 && !strcmp(argv[1], "-h"))
-               usage_with_options(simple_ipc_usage, options);
+       show_usage_with_options_if_asked(argc, argv,
+                                        simple_ipc_usage, options);
 
        if (argc == 2 && !strcmp(argv[1], "SUPPORTS_SIMPLE_IPC"))
                return 0;
index ef54cff4faa8d3916111a47fae48aee847323d46..2a8df292196468296a437152f242d4e0e5b0a4e1 100755 (executable)
@@ -173,7 +173,7 @@ test_expect_success 'merge -h with invalid index' '
                cd broken &&
                git init &&
                >.git/index &&
-               test_expect_code 129 git merge -h 2>usage
+               test_expect_code 129 git merge -h >usage
        ) &&
        test_grep "[Uu]sage: git merge" broken/usage
 '