]> git.ipfire.org Git - thirdparty/git.git/blame - t/helper/test-tool.c
Merge branch 'js/update-index-ignore-removal-for-skip-worktree'
[thirdparty/git.git] / t / helper / test-tool.c
CommitLineData
efd71f89
NTND
1#include "git-compat-util.h"
2#include "test-tool.h"
ee4512ed 3#include "trace2.h"
6ea18fff
JS
4#include "parse-options.h"
5
6static const char * const test_tool_usage[] = {
7 "test-tool [-C <directory>] <command [<arguments>...]]",
8 NULL
9};
efd71f89
NTND
10
11struct test_cmd {
12 const char *name;
13 int (*fn)(int argc, const char **argv);
14};
15
16static struct test_cmd cmds[] = {
0e496492 17 { "chmtime", cmd__chmtime },
0e2678af 18 { "config", cmd__config },
e4998944 19 { "ctype", cmd__ctype },
a801a7cf 20 { "date", cmd__date },
9153dde5 21 { "delta", cmd__delta },
150791ad 22 { "dir-iterator", cmd__dir_iterator },
1c854745 23 { "drop-caches", cmd__drop_caches },
06ccb29e 24 { "dump-cache-tree", cmd__dump_cache_tree },
f1ef0b02 25 { "dump-fsmonitor", cmd__dump_fsmonitor },
8133061e 26 { "dump-split-index", cmd__dump_split_index },
cd780f0b 27 { "dump-untracked-cache", cmd__dump_untracked_cache },
dbceb3ec 28 { "example-decorate", cmd__example_decorate },
c680668d 29 { "genrandom", cmd__genrandom },
d5cfd142 30 { "genzeros", cmd__genzeros },
7c18cbd5 31 { "hashmap", cmd__hashmap },
37649b7f 32 { "hash-speed", cmd__hash_speed },
cc6f663d 33 { "index-version", cmd__index_version },
75459410 34 { "json-writer", cmd__json_writer },
64eb82fe 35 { "lazy-init-name-hash", cmd__lazy_init_name_hash },
9080e75f 36 { "match-trees", cmd__match_trees },
34889d3c 37 { "mergesort", cmd__mergesort },
d9cc2c87 38 { "mktemp", cmd__mktemp },
11510dec 39 { "oidmap", cmd__oidmap },
c033cc15 40 { "online-cpus", cmd__online_cpus },
2f17c78c 41 { "parse-options", cmd__parse_options },
b8d5cf4f 42 { "path-utils", cmd__path_utils },
8ea40cc5 43 { "pkt-line", cmd__pkt_line },
15b75817 44 { "prio-queue", cmd__prio_queue },
2bb74b53 45 { "progress", cmd__progress },
ab176ac4 46 { "reach", cmd__reach },
5fbe600c 47 { "read-cache", cmd__read_cache },
4d80560c 48 { "read-midx", cmd__read_midx },
65370d81 49 { "ref-store", cmd__ref_store },
9038531f 50 { "regex", cmd__regex },
dade47c0 51 { "repository", cmd__repository },
77d4b8c8 52 { "revision-walking", cmd__revision_walking },
ae6a51f5 53 { "run-command", cmd__run_command },
ff5fb8b0 54 { "scrap-cache-tree", cmd__scrap_cache_tree },
b7ce24d0 55 { "serve-v2", cmd__serve_v2 },
dae2ff9b 56 { "sha1", cmd__sha1 },
a0fe6e6e 57 { "sha1-array", cmd__sha1_array },
13eeedb5 58 { "sha256", cmd__sha256 },
e154a6f3 59 { "sigchain", cmd__sigchain },
1a5f3d70 60 { "strcmp-offset", cmd__strcmp_offset },
c932a5ff 61 { "string-list", cmd__string_list },
b6188213 62 { "submodule-config", cmd__submodule_config },
2b1257e4 63 { "submodule-nested-repo-config", cmd__submodule_nested_repo_config },
112edd6a 64 { "subprocess", cmd__subprocess },
a15860dc 65 { "trace2", cmd__trace2 },
599fbd87 66 { "urlmatch-normalization", cmd__urlmatch_normalization },
22231908 67 { "xml-encode", cmd__xml_encode },
0489289d 68 { "wildmatch", cmd__wildmatch },
06ba9d03
JH
69#ifdef GIT_WINDOWS_NATIVE
70 { "windows-named-pipe", cmd__windows_named_pipe },
71#endif
c81f843d 72 { "write-cache", cmd__write_cache },
efd71f89
NTND
73};
74
4e26569d
JK
75static NORETURN void die_usage(void)
76{
77 size_t i;
78
79 fprintf(stderr, "usage: test-tool <toolname> [args]\n");
80 for (i = 0; i < ARRAY_SIZE(cmds); i++)
81 fprintf(stderr, " %s\n", cmds[i].name);
82 exit(128);
83}
84
efd71f89
NTND
85int cmd_main(int argc, const char **argv)
86{
87 int i;
6ea18fff
JS
88 const char *working_directory = NULL;
89 struct option options[] = {
90 OPT_STRING('C', NULL, &working_directory, "directory",
91 "change the working directory"),
92 OPT_END()
93 };
efd71f89 94
a86303cb 95 BUG_exit_code = 99;
6ea18fff
JS
96 argc = parse_options(argc, argv, NULL, options, test_tool_usage,
97 PARSE_OPT_STOP_AT_NON_OPTION |
98 PARSE_OPT_KEEP_ARGV0);
99
efd71f89 100 if (argc < 2)
4e26569d 101 die_usage();
efd71f89 102
6ea18fff
JS
103 if (working_directory && chdir(working_directory) < 0)
104 die("Could not cd to '%s'", working_directory);
105
efd71f89
NTND
106 for (i = 0; i < ARRAY_SIZE(cmds); i++) {
107 if (!strcmp(cmds[i].name, argv[1])) {
108 argv++;
109 argc--;
ee4512ed
JH
110 trace2_cmd_name(cmds[i].name);
111 trace2_cmd_list_config();
efd71f89
NTND
112 return cmds[i].fn(argc, argv);
113 }
114 }
4e26569d
JK
115 error("there is no tool named '%s'", argv[1]);
116 die_usage();
efd71f89 117}