test-lib: unset trace2 parent envvars
[git.git] / hook.c
blob55e1145a4b7b8c59276f082ab0b240817702ace4
1 #include "cache.h"
2 #include "hook.h"
3 #include "run-command.h"
5 const char *find_hook(const char *name)
7 static struct strbuf path = STRBUF_INIT;
9 strbuf_reset(&path);
10 strbuf_git_path(&path, "hooks/%s", name);
11 if (access(path.buf, X_OK) < 0) {
12 int err = errno;
14 #ifdef STRIP_EXTENSION
15 strbuf_addstr(&path, STRIP_EXTENSION);
16 if (access(path.buf, X_OK) >= 0)
17 return path.buf;
18 if (errno == EACCES)
19 err = errno;
20 #endif
22 if (err == EACCES && advice_enabled(ADVICE_IGNORED_HOOK)) {
23 static struct string_list advise_given = STRING_LIST_INIT_DUP;
25 if (!string_list_lookup(&advise_given, name)) {
26 string_list_insert(&advise_given, name);
27 advise(_("The '%s' hook was ignored because "
28 "it's not set as executable.\n"
29 "You can disable this warning with "
30 "`git config advice.ignoredHook false`."),
31 path.buf);
34 return NULL;
36 return path.buf;
39 int hook_exists(const char *name)
41 return !!find_hook(name);