| 24 | } |
| 25 | |
| 26 | const 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 | |
| 66 | void hook_free(void *p, const char *str UNUSED) |
| 67 | { |
no test coverage detected