]> git.ipfire.org Git - thirdparty/git.git/blame - t/helper/test-tool.c
Merge branch 'jk/clone-allow-bare-and-o-together'
[thirdparty/git.git] / t / helper / test-tool.c
CommitLineData
efd71f89
NTND
1#include "git-compat-util.h"
2#include "test-tool.h"
9fb2a970 3#include "test-tool-utils.h"
ee4512ed 4#include "trace2.h"
6ea18fff
JS
5#include "parse-options.h"
6
7static const char * const test_tool_usage[] = {
8 "test-tool [-C <directory>] <command [<arguments>...]]",
9 NULL
10};
efd71f89 11
efd71f89 12static struct test_cmd cmds[] = {
b3b18d16 13 { "advise", cmd__advise_if_enabled },
483fa7f4 14 { "bitmap", cmd__bitmap },
f52207a4 15 { "bloom", cmd__bloom },
0e496492 16 { "chmtime", cmd__chmtime },
0e2678af 17 { "config", cmd__config },
2fec604f 18 { "crontab", cmd__crontab },
05cd988d 19 { "csprng", cmd__csprng },
e4998944 20 { "ctype", cmd__ctype },
a801a7cf 21 { "date", cmd__date },
9153dde5 22 { "delta", cmd__delta },
150791ad 23 { "dir-iterator", cmd__dir_iterator },
1c854745 24 { "drop-caches", cmd__drop_caches },
06ccb29e 25 { "dump-cache-tree", cmd__dump_cache_tree },
f1ef0b02 26 { "dump-fsmonitor", cmd__dump_fsmonitor },
8133061e 27 { "dump-split-index", cmd__dump_split_index },
cd780f0b 28 { "dump-untracked-cache", cmd__dump_untracked_cache },
dbceb3ec 29 { "example-decorate", cmd__example_decorate },
fe1a21d5 30 { "fast-rebase", cmd__fast_rebase },
148405fb 31 { "fsmonitor-client", cmd__fsmonitor_client },
c680668d 32 { "genrandom", cmd__genrandom },
d5cfd142 33 { "genzeros", cmd__genzeros },
482e1488 34 { "getcwd", cmd__getcwd },
7c18cbd5 35 { "hashmap", cmd__hashmap },
37649b7f 36 { "hash-speed", cmd__hash_speed },
9915e08f 37 { "hexdump", cmd__hexdump },
cc6f663d 38 { "index-version", cmd__index_version },
75459410 39 { "json-writer", cmd__json_writer },
64eb82fe 40 { "lazy-init-name-hash", cmd__lazy_init_name_hash },
9080e75f 41 { "match-trees", cmd__match_trees },
34889d3c 42 { "mergesort", cmd__mergesort },
d9cc2c87 43 { "mktemp", cmd__mktemp },
ed4b804e 44 { "oid-array", cmd__oid_array },
11510dec 45 { "oidmap", cmd__oidmap },
92d8ed8a 46 { "oidtree", cmd__oidtree },
c033cc15 47 { "online-cpus", cmd__online_cpus },
2bd44278 48 { "pack-mtimes", cmd__pack_mtimes },
2f17c78c 49 { "parse-options", cmd__parse_options },
c1b117d3 50 { "parse-options-flags", cmd__parse_options_flags },
d0d0a357 51 { "parse-pathspec-file", cmd__parse_pathspec_file },
fa83cc83 52 { "parse-subcommand", cmd__parse_subcommand },
ef830cc4 53 { "partial-clone", cmd__partial_clone },
b8d5cf4f 54 { "path-utils", cmd__path_utils },
95ca1f98 55 { "pcre2-config", cmd__pcre2_config },
8ea40cc5 56 { "pkt-line", cmd__pkt_line },
15b75817 57 { "prio-queue", cmd__prio_queue },
ef8a6c62 58 { "proc-receive", cmd__proc_receive },
2bb74b53 59 { "progress", cmd__progress },
ab176ac4 60 { "reach", cmd__reach },
5fbe600c 61 { "read-cache", cmd__read_cache },
4bd0593e 62 { "read-graph", cmd__read_graph },
4d80560c 63 { "read-midx", cmd__read_midx },
65370d81 64 { "ref-store", cmd__ref_store },
ef8a6c62 65 { "reftable", cmd__reftable },
52917a99 66 { "rot13-filter", cmd__rot13_filter },
d860c86b 67 { "dump-reftable", cmd__dump_reftable },
9038531f 68 { "regex", cmd__regex },
dade47c0 69 { "repository", cmd__repository },
77d4b8c8 70 { "revision-walking", cmd__revision_walking },
ae6a51f5 71 { "run-command", cmd__run_command },
ff5fb8b0 72 { "scrap-cache-tree", cmd__scrap_cache_tree },
b7ce24d0 73 { "serve-v2", cmd__serve_v2 },
dae2ff9b 74 { "sha1", cmd__sha1 },
13eeedb5 75 { "sha256", cmd__sha256 },
e154a6f3 76 { "sigchain", cmd__sigchain },
36a7eb68 77 { "simple-ipc", cmd__simple_ipc },
1a5f3d70 78 { "strcmp-offset", cmd__strcmp_offset },
c932a5ff 79 { "string-list", cmd__string_list },
9fb2a970 80 { "submodule", cmd__submodule },
b6188213 81 { "submodule-config", cmd__submodule_config },
2b1257e4 82 { "submodule-nested-repo-config", cmd__submodule_nested_repo_config },
112edd6a 83 { "subprocess", cmd__subprocess },
a15860dc 84 { "trace2", cmd__trace2 },
28e8f0d5 85 { "userdiff", cmd__userdiff },
599fbd87 86 { "urlmatch-normalization", cmd__urlmatch_normalization },
22231908 87 { "xml-encode", cmd__xml_encode },
0489289d 88 { "wildmatch", cmd__wildmatch },
06ba9d03
JH
89#ifdef GIT_WINDOWS_NATIVE
90 { "windows-named-pipe", cmd__windows_named_pipe },
91#endif
c81f843d 92 { "write-cache", cmd__write_cache },
efd71f89
NTND
93};
94
4e26569d
JK
95static NORETURN void die_usage(void)
96{
97 size_t i;
98
99 fprintf(stderr, "usage: test-tool <toolname> [args]\n");
100 for (i = 0; i < ARRAY_SIZE(cmds); i++)
101 fprintf(stderr, " %s\n", cmds[i].name);
102 exit(128);
103}
104
efd71f89
NTND
105int cmd_main(int argc, const char **argv)
106{
107 int i;
6ea18fff
JS
108 const char *working_directory = NULL;
109 struct option options[] = {
110 OPT_STRING('C', NULL, &working_directory, "directory",
111 "change the working directory"),
112 OPT_END()
113 };
efd71f89 114
a86303cb 115 BUG_exit_code = 99;
6ea18fff
JS
116 argc = parse_options(argc, argv, NULL, options, test_tool_usage,
117 PARSE_OPT_STOP_AT_NON_OPTION |
118 PARSE_OPT_KEEP_ARGV0);
119
efd71f89 120 if (argc < 2)
4e26569d 121 die_usage();
efd71f89 122
6ea18fff
JS
123 if (working_directory && chdir(working_directory) < 0)
124 die("Could not cd to '%s'", working_directory);
125
efd71f89
NTND
126 for (i = 0; i < ARRAY_SIZE(cmds); i++) {
127 if (!strcmp(cmds[i].name, argv[1])) {
128 argv++;
129 argc--;
ee4512ed
JH
130 trace2_cmd_name(cmds[i].name);
131 trace2_cmd_list_config();
3d3adaad 132 trace2_cmd_list_env_vars();
efd71f89
NTND
133 return cmds[i].fn(argc, argv);
134 }
135 }
4e26569d
JK
136 error("there is no tool named '%s'", argv[1]);
137 die_usage();
efd71f89 138}