git hook run: add an --ignore-missing flag
[git] / hook.h
1 #ifndef HOOK_H
2 #define HOOK_H
3 #include "strbuf.h"
4 #include "strvec.h"
5 #include "run-command.h"
6
7 struct hook {
8         /* The path to the hook */
9         const char *hook_path;
10 };
11
12 struct run_hooks_opt
13 {
14         /* Environment vars to be set for each hook */
15         struct strvec env;
16
17         /* Args to be passed to each hook */
18         struct strvec args;
19
20         /* Number of threads to parallelize across */
21         int jobs;
22
23         /* Resolve and run the "absolute_path(hook)" instead of
24          * "hook". Used for "git worktree" hooks
25          */
26         int absolute_path;
27
28         /* Path to initial working directory for subprocess */
29         const char *dir;
30
31 };
32
33 #define RUN_HOOKS_OPT_INIT { \
34         .jobs = 1, \
35         .env = STRVEC_INIT, \
36         .args = STRVEC_INIT, \
37 }
38
39 /*
40  * Callback provided to feed_pipe_fn and consume_sideband_fn.
41  */
42 struct hook_cb_data {
43         int rc;
44         const char *hook_name;
45         struct hook *run_me;
46         struct run_hooks_opt *options;
47 };
48
49 /*
50  * Returns the path to the hook file, or NULL if the hook is missing
51  * or disabled. Note that this points to static storage that will be
52  * overwritten by further calls to find_hook and run_hook_*.
53  */
54 const char *find_hook(const char *name);
55
56 /*
57  * A boolean version of find_hook()
58  */
59 int hook_exists(const char *hookname);
60
61 void run_hooks_opt_clear(struct run_hooks_opt *o);
62
63 /*
64  * Calls find_hook(hookname) and runs the hooks (if any) with
65  * run_found_hooks().
66  */
67 int run_hooks(const char *hook_name, struct run_hooks_opt *options);
68
69 /*
70  * Takes an already resolved hook and runs it. Internally the simpler
71  * run_hooks() will call this.
72  */
73 int run_found_hooks(const char *hookname, const char *hook_path,
74                     struct run_hooks_opt *options);
75 #endif