6 #include "parse-options.h"
10 #define BUILTIN_HOOK_RUN_USAGE \
11 N_("git hook run [--ignore-missing] [--to-stdin=<path>] <hook-name> [-- <hook-args>]")
13 static const char * const builtin_hook_usage
[] = {
14 BUILTIN_HOOK_RUN_USAGE
,
18 static const char * const builtin_hook_run_usage
[] = {
19 BUILTIN_HOOK_RUN_USAGE
,
23 static int run(int argc
, const char **argv
, const char *prefix
)
26 struct run_hooks_opt opt
= RUN_HOOKS_OPT_INIT
;
27 int ignore_missing
= 0;
28 const char *hook_name
;
29 struct option run_options
[] = {
30 OPT_BOOL(0, "ignore-missing", &ignore_missing
,
31 N_("silently ignore missing requested <hook-name>")),
32 OPT_STRING(0, "to-stdin", &opt
.path_to_stdin
, N_("path"),
33 N_("file to read into hooks' stdin")),
38 argc
= parse_options(argc
, argv
, prefix
, run_options
,
39 builtin_hook_run_usage
,
40 PARSE_OPT_KEEP_DASHDASH
);
46 * Having a -- for "run" when providing <hook-args> is
49 if (argc
> 1 && strcmp(argv
[1], "--") &&
50 strcmp(argv
[1], "--end-of-options"))
53 /* Add our arguments, start after -- */
54 for (i
= 2 ; i
< argc
; i
++)
55 strvec_push(&opt
.args
, argv
[i
]);
57 /* Need to take into account core.hooksPath */
58 git_config(git_default_config
, NULL
);
62 opt
.error_if_missing
= 1;
63 ret
= run_hooks_opt(hook_name
, &opt
);
64 if (ret
< 0) /* error() return */
68 usage_with_options(builtin_hook_run_usage
, run_options
);
71 int cmd_hook(int argc
, const char **argv
, const char *prefix
)
73 parse_opt_subcommand_fn
*fn
= NULL
;
74 struct option builtin_hook_options
[] = {
75 OPT_SUBCOMMAND("run", &fn
, run
),
79 argc
= parse_options(argc
, argv
, NULL
, builtin_hook_options
,
80 builtin_hook_usage
, 0);
82 return fn(argc
, argv
, prefix
);