With this MWE Git executes hooks in a the wrong repository (A):
# Make simple repo
git init "/tmp/A" && cd "/tmp/A" || exit 1
# Make hook to demonstrate the problem
mkdir -p ".git/hooks" &&
echo "echo 'EXECUTED!!!'" >.git/hooks/reference-transaction &&
chmod +x ".git/hooks/reference-transaction" &&
git clone -c core.hooksPath=".git/hooks" --template= "https://github.com/gabyx/Githooks.git" /tmp/Githooks
Results in
Initialized empty Git repository in /home/test/tmp/A/.git/
Cloning into 'Githooks'...
EXECUTED!!!
EXECUTED!!!
EXECUTED!!!
EXECUTED!!!
Which is totally weird: I expect git clone to execute the hook in /tmp/Githooks/.git/hooks because from
The path can be either absolute or relative. A relative path is taken as relative to the directory where the hooks are run (see the "DESCRIPTION" section of githooks[5]).
and further in Doc :
Before Git invokes a hook, it changes its working directory to either $GIT_DIR in a bare repository or the root of the working tree in a non-bare repository.
Why is this, and is this a Bug which should be reported?