1

I'm trying to have one repo with all my githooks and every other repo references that.

My repo directory structure looks like this.

~/dev/githooks/.git/hooks
 |-> pre-push
   |-> prevent-master

prevent-master

#!/bin/sh

branch_blocked="master"

if grep -q "$branch_blocked"; then
    echo "Branch '$branch_blocked' is blocked by yourself." >&2
    exit 1
fi

Now I tell my git config to use this githook directory git config core.hooksPath ~/dev/githooks/.git/hooks

In a separate repo I'm trying to push and it says

clickthisnick$ git push
fatal: cannot exec '/Users/clickthisnick/dev/githooks/.git/hooks/pre-push': Permission denied

I have chmod -R +xr ~/dev/githooks and am using a git version that supports this git version 2.17.2.

Anything else I can try to get this to work?

4
  • 2
    The path that you chmoded is not the path to your hooks (~/dev/githooks.git vs ~/dev/githooks/.git)... Commented Jan 2, 2019 at 20:21
  • Good catch, that was a typo tho. I chmod the correct directory and its parent Commented Jan 2, 2019 at 20:31
  • What's the output of ls -l /Users/clickthisnick/dev/githooks/.git/hooks/pre-push? Commented Jan 2, 2019 at 21:05
  • -rwxr-xr-x 1 clickthisnick staff 149 Jan 2 15:02 prevent-master Commented Jan 2, 2019 at 21:15

1 Answer 1

2

Your git hook needs to be an executable file, not a directory. git will try to invoke:

/Users/clickthisnick/dev/githooks/.git/hooks/pre-push

But you have this configured as a directory, containing a hook (prevent-master) not a file. Instead, rename:

/Users/clickthisnick/dev/githooks/.git/hooks/pre-push/prevent-master

to

/Users/clickthisnick/dev/githooks/.git/hooks/pre-push
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.