1 #define USE_THE_REPOSITORY_VARIABLE
6 #include "parse-options.h"
9 #define BUILTIN_HOOK_RUN_USAGE \
10 N_("git hook run [--ignore-missing] [--to-stdin=<path>] <hook-name> [-- <hook-args>]")
12 static const char * const builtin_hook_usage
[] = {
13 BUILTIN_HOOK_RUN_USAGE
,
17 static const char * const builtin_hook_run_usage
[] = {
18 BUILTIN_HOOK_RUN_USAGE
,
22 static int run(int argc
, const char **argv
, const char *prefix
)
25 struct run_hooks_opt opt
= RUN_HOOKS_OPT_INIT
;
26 int ignore_missing
= 0;
27 const char *hook_name
;
28 struct option run_options
[] = {
29 OPT_BOOL(0, "ignore-missing", &ignore_missing
,
30 N_("silently ignore missing requested <hook-name>")),
31 OPT_STRING(0, "to-stdin", &opt
.path_to_stdin
, N_("path"),
32 N_("file to read into hooks' stdin")),
37 argc
= parse_options(argc
, argv
, prefix
, run_options
,
38 builtin_hook_run_usage
,
39 PARSE_OPT_KEEP_DASHDASH
);
45 * Having a -- for "run" when providing <hook-args> is
48 if (argc
> 1 && strcmp(argv
[1], "--") &&
49 strcmp(argv
[1], "--end-of-options"))
52 /* Add our arguments, start after -- */
53 for (i
= 2 ; i
< argc
; i
++)
54 strvec_push(&opt
.args
, argv
[i
]);
56 /* Need to take into account core.hooksPath */
57 git_config(git_default_config
, NULL
);
61 opt
.error_if_missing
= 1;
62 ret
= run_hooks_opt(the_repository
, hook_name
, &opt
);
63 if (ret
< 0) /* error() return */
67 usage_with_options(builtin_hook_run_usage
, run_options
);
70 int cmd_hook(int argc
,
73 struct repository
*repo UNUSED
)
75 parse_opt_subcommand_fn
*fn
= NULL
;
76 struct option builtin_hook_options
[] = {
77 OPT_SUBCOMMAND("run", &fn
, run
),
81 argc
= parse_options(argc
, argv
, NULL
, builtin_hook_options
,
82 builtin_hook_usage
, 0);
84 return fn(argc
, argv
, prefix
);