5
#include "parse-options.h"
8
#define BUILTIN_HOOK_RUN_USAGE \
9
N_("git hook run [--ignore-missing] [--to-stdin=<path>] <hook-name> [-- <hook-args>]")
11
static const char * const builtin_hook_usage[] = {
12
BUILTIN_HOOK_RUN_USAGE,
16
static const char * const builtin_hook_run_usage[] = {
17
BUILTIN_HOOK_RUN_USAGE,
21
static int run(int argc, const char **argv, const char *prefix)
24
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
25
int ignore_missing = 0;
26
const char *hook_name;
27
struct option run_options[] = {
28
OPT_BOOL(0, "ignore-missing", &ignore_missing,
29
N_("silently ignore missing requested <hook-name>")),
30
OPT_STRING(0, "to-stdin", &opt.path_to_stdin, N_("path"),
31
N_("file to read into hooks' stdin")),
36
argc = parse_options(argc, argv, prefix, run_options,
37
builtin_hook_run_usage,
38
PARSE_OPT_KEEP_DASHDASH);
44
* Having a -- for "run" when providing <hook-args> is
47
if (argc > 1 && strcmp(argv[1], "--") &&
48
strcmp(argv[1], "--end-of-options"))
51
/* Add our arguments, start after -- */
52
for (i = 2 ; i < argc; i++)
53
strvec_push(&opt.args, argv[i]);
55
/* Need to take into account core.hooksPath */
56
git_config(git_default_config, NULL);
60
opt.error_if_missing = 1;
61
ret = run_hooks_opt(the_repository, hook_name, &opt);
62
if (ret < 0) /* error() return */
66
usage_with_options(builtin_hook_run_usage, run_options);
69
int cmd_hook(int argc, const char **argv, const char *prefix)
71
parse_opt_subcommand_fn *fn = NULL;
72
struct option builtin_hook_options[] = {
73
OPT_SUBCOMMAND("run", &fn, run),
77
argc = parse_options(argc, argv, NULL, builtin_hook_options,
78
builtin_hook_usage, 0);
80
return fn(argc, argv, prefix);