ClickThisNick
ClickThisNick

Reputation: 5250

git core.hooksPath permission denied issue

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?

Upvotes: 1

Views: 3737

Answers (1)

Edward Thomson
Edward Thomson

Reputation: 78653

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

Upvotes: 2

Related Questions