Reputation: 21407
I followed these directions to install a flake8 pre-commit hook: flake8 --install-hook git
. How do I make this pre-commit hook default for everyone?
It looks like it changed my own sandbox (.git/hooks/pre-commit
), but there's nothing to commit or push. Other devs on the project won't get the pre-commit hook unless they install it on their own.
I expected it to be like .gitignore, where there's a file kept in source code control that we can all update and version.
Upvotes: 2
Views: 2322
Reputation: 45689
Local hooks are not like the .gitignore
file. Rather they are like .git/info/exclude
. That is to say, they are local and must be configured on any repo that should use them.
There are arguably security reasons why this should be this way. (Cloning your repo doesn't mean that I want to run your code by default when I initiate a git command.) But whether you subscribe to those reasons or not, that's how hooks work.
What you can do is to provide the hook script, possibly an installer that would copy the script to the correct directory, and a README asking developers to install the hook.
If you need something that developers can't override, you need a server-side hook. For example you can use a pre-receive hook to reject pushes that didn't follow the rules you wanted to enforce at the commit level. (This does give developers an incentive to install the pre-commit hook, so that they catch any rules violations sooner and don't waste effort.)
Upvotes: 7