]> git.ipfire.org Git - thirdparty/git.git/blame - hook.c
test-ref-store: remove force-create argument for create-reflog
[thirdparty/git.git] / hook.c
CommitLineData
5e3aba33
ÆAB
1#include "cache.h"
2#include "hook.h"
3#include "run-command.h"
4
5const char *find_hook(const char *name)
6{
7 static struct strbuf path = STRBUF_INIT;
8
9 strbuf_reset(&path);
10 strbuf_git_path(&path, "hooks/%s", name);
11 if (access(path.buf, X_OK) < 0) {
12 int err = errno;
13
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
21
22 if (err == EACCES && advice_enabled(ADVICE_IGNORED_HOOK)) {
23 static struct string_list advise_given = STRING_LIST_INIT_DUP;
24
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);
32 }
33 }
34 return NULL;
35 }
36 return path.buf;
37}
330155ed
ES
38
39int hook_exists(const char *name)
40{
41 return !!find_hook(name);
42}