I cloned an existing project on my local.
I have a pre-commit bash script that is in the .git/hooks folder.
This is what it looks like:
#!/bin/bash
cd api && php artisan enforcer:check --githook
I am changing into the api folder since my git root is one level up and api contains the laravel framework where I can use the php artisan commands.
Whenever I commit something on the commandline, When I go to the line in my code that says:
$projectGitRoot = trim(shell_exec("git rev-parse --show-toplevel"));
it gives me fatal: Not a git repository: '.git' error.
Whenever I run the actual pre-commit on command line by doing ./.git/hooks/pre-commit, it works just fine.
I then changed the pre-commit to use Sudo and everything works (but this is not a good solution)
#!/bin/bash
cd api && sudo php artisan enforcer:check --githook
I have verified using whoami that in both cases it is the same user. I have tried chowning the .git folder with my commandline user. Nothing works.
What can I do? I looked at other questions like fatal: Not a git repository: '.git' error
but still very lost.
UPDATE:
It appears that the git pre-commit hook does not want to do anything with GIT. It cant even return a git status.