MCPcopy Index your code
hub / github.com/git/git / find_hook

Function find_hook

hook.c:26–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24}
25
26const char *find_hook(struct repository *r, const char *name)
27{
28 static struct strbuf path = STRBUF_INIT;
29
30 int found_hook;
31
32 if (!r || !r->gitdir)
33 return NULL;
34
35 repo_git_path_replace(r, &path, "hooks/%s", name);
36 found_hook = access(path.buf, X_OK) >= 0;
37#ifdef STRIP_EXTENSION
38 if (!found_hook) {
39 int err = errno;
40
41 strbuf_addstr(&path, STRIP_EXTENSION);
42 found_hook = access(path.buf, X_OK) >= 0;
43 if (!found_hook)
44 errno = err;
45 }
46#endif
47
48 if (!found_hook) {
49 if (errno == EACCES && advice_enabled(ADVICE_IGNORED_HOOK)) {
50 static struct string_list advise_given = STRING_LIST_INIT_DUP;
51
52 if (!string_list_lookup(&advise_given, name)) {
53 string_list_insert(&advise_given, name);
54 advise(_("The '%s' hook was ignored because "
55 "it's not set as executable.\n"
56 "You can disable this warning with "
57 "`git config set advice.ignoredHook false`."),
58 path.buf);
59 }
60 }
61 return NULL;
62 }
63 return path.buf;
64}
65
66void hook_free(void *p, const char *str UNUSED)
67{

Callers 2

list_hooks_add_defaultFunction · 0.85
run_proc_receive_hookFunction · 0.85

Calls 6

repo_git_path_replaceFunction · 0.85
strbuf_addstrFunction · 0.85
advice_enabledFunction · 0.85
string_list_lookupFunction · 0.85
string_list_insertFunction · 0.85
adviseFunction · 0.85

Tested by

no test coverage detected