]> git.ipfire.org Git - thirdparty/git.git/blob - hook.h
Merge branch 'ab/help-fixes'
[thirdparty/git.git] / hook.h
1 #ifndef HOOK_H
2 #define HOOK_H
3 #include "strvec.h"
4
5 struct run_hooks_opt
6 {
7 /* Environment vars to be set for each hook */
8 struct strvec env;
9
10 /* Args to be passed to each hook */
11 struct strvec args;
12
13 /* Emit an error if the hook is missing */
14 unsigned int error_if_missing:1;
15
16 /**
17 * An optional initial working directory for the hook,
18 * translates to "struct child_process"'s "dir" member.
19 */
20 const char *dir;
21 };
22
23 #define RUN_HOOKS_OPT_INIT { \
24 .env = STRVEC_INIT, \
25 .args = STRVEC_INIT, \
26 }
27
28 struct hook_cb_data {
29 /* rc reflects the cumulative failure state */
30 int rc;
31 const char *hook_name;
32 const char *hook_path;
33 struct run_hooks_opt *options;
34 };
35
36 /*
37 * Returns the path to the hook file, or NULL if the hook is missing
38 * or disabled. Note that this points to static storage that will be
39 * overwritten by further calls to find_hook and run_hook_*.
40 */
41 const char *find_hook(const char *name);
42
43 /**
44 * A boolean version of find_hook()
45 */
46 int hook_exists(const char *hookname);
47
48 /**
49 * Takes a `hook_name`, resolves it to a path with find_hook(), and
50 * runs the hook for you with the options specified in "struct
51 * run_hooks opt". Will free memory associated with the "struct run_hooks_opt".
52 *
53 * Returns the status code of the run hook, or a negative value on
54 * error().
55 */
56 int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options);
57
58 /**
59 * A wrapper for run_hooks_opt() which provides a dummy "struct
60 * run_hooks_opt" initialized with "RUN_HOOKS_OPT_INIT".
61 */
62 int run_hooks(const char *hook_name);
63
64 /**
65 * Like run_hooks(), a wrapper for run_hooks_opt().
66 *
67 * In addition to the wrapping behavior provided by run_hooks(), this
68 * wrapper takes a list of strings terminated by a NULL
69 * argument. These things will be used as positional arguments to the
70 * hook. This function behaves like the old run_hook_le() API.
71 */
72 int run_hooks_l(const char *hook_name, ...);
73 #endif