pre-commit never installs from the repository under test, only the configuration (otherwise caching is intractable)
the working directory during installation is implementation detail and not customizable, it is the root of the hook repository itself inside the pre-commit cache
for things like pylint which need dynamic analysis and direct access to your codebase and dependencies an unmanaged repo: local hook is suggested instead (or enumerate your dependencies in additional_dependencies
disclaimer: I created pre-commit
Answer from anthony sottile on Stack OverflowIn a git hook is the current working directory guaranteed to be within the git repository? - Stack Overflow
Question: How to change working directory in `system` language hook
Git pre-commit hooks per directory - Stack Overflow
Setting up pre-commit hooks to existing and all future repo's (check files for text before allowing commit)
Videos
The current answers appear to be outdated. As of 2.9.0, the docs state the following:
Before Git invokes a hook, it changes its working directory to either the root of the working tree in a non-bare repository, or to the $GIT_DIR in a bare repository.
https://git-scm.com/docs/githooks/2.9.0
It is based on the value set for environment variable GIT_DIR. It is set to the root of the repository when the hook starts running. Many hooks, especially those doing a pull from another repo, unset ( and reset) this environment variable as needed.
I'm looking to install some pre-commit hooks locally for existing and future repo's I use. Specifically, I just want to scan files for some text and if it's found not let me commit anything (e.g. password=(.+)).
I went through a few different install steps, but nothing seems to work. Updating my gitconfig to link to a common hooks directory, etc.
How the heck do I do this?
As an aside - anyone able to recommend some "idiot proof" hooks?