MCPcopy Create free account
hub / github.com/git/git / run

Function run

builtin/hook.c:120–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120static int run(int argc, const char **argv, const char *prefix,
121 struct repository *repo UNUSED)
122{
123 int i;
124 struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
125 int ignore_missing = 0;
126 int allow_unknown = 0;
127 int jobs = 0;
128 const char *hook_name;
129 struct option run_options[] = {
130 OPT_BOOL(0, "allow-unknown-hook-name", &allow_unknown,
131 N_("allow running a hook with a non-native hook name")),
132 OPT_BOOL(0, "ignore-missing", &ignore_missing,
133 N_("silently ignore missing requested <hook-name>")),
134 OPT_STRING(0, "to-stdin", &opt.path_to_stdin, N_("path"),
135 N_("file to read into hooks' stdin")),
136 OPT_INTEGER('j', "jobs", &jobs,
137 N_("run up to <n> hooks simultaneously (-1 for CPU count)")),
138 OPT_END(),
139 };
140 int ret;
141
142 argc = parse_options(argc, argv, prefix, run_options,
143 builtin_hook_run_usage,
144 PARSE_OPT_KEEP_DASHDASH);
145
146 if (jobs == -1)
147 opt.jobs = online_cpus();
148 else if (jobs < 0)
149 die(_("invalid value for -j: %d"
150 " (use -1 for CPU count or a"
151 " positive integer)"), jobs);
152 else
153 opt.jobs = jobs;
154
155 if (!argc)
156 goto usage;
157
158 /*
159 * Having a -- for "run" when providing <hook-args> is
160 * mandatory.
161 */
162 if (argc > 1 && strcmp(argv[1], "--") &&
163 strcmp(argv[1], "--end-of-options"))
164 goto usage;
165
166 /* Add our arguments, start after -- */
167 for (i = 2 ; i < argc; i++)
168 strvec_push(&opt.args, argv[i]);
169
170 /* Need to take into account core.hooksPath */
171 repo_config(the_repository, git_default_config, NULL);
172
173 hook_name = argv[0];
174
175 if (!allow_unknown && !is_known_hook(hook_name)) {
176 error(_("unknown hook event '%s';\n"
177 "use --allow-unknown-hook-name to allow non-native hook names"),

Callers

nothing calls this directly

Calls 9

parse_optionsFunction · 0.85
online_cpusFunction · 0.85
strvec_pushFunction · 0.85
is_known_hookFunction · 0.85
errorFunction · 0.85
usage_with_optionsFunction · 0.85
run_hooks_optClass · 0.70
dieFunction · 0.50
repo_configFunction · 0.50

Tested by

no test coverage detected