Reputation: 35
I tried to add the pre-commit hook file gitlab server side. I know pre-commit hook is client side hook. I just want to add the pre-commit hook file in all the project's .git/hooks
folder.
What I tried:-
I edited all the pre-commit.sample
file in my gitlab server machine and created the new project. But I did not found that edited sample hook file in my local (windows) after cloned the repo.
Is there any way to add the pre-commit
hook in all the project's git folder by server side? Because we have more than 500 projects.
Upvotes: 1
Views: 1549
Reputation: 45819
This is the fundamental trade-off with client-side hooks: they can't be centrally configured.
You could add the hook script(s) you want to the work tree, along with a script that you run in the root of the work tree to copy the scripts into .git/hooks
. Then if individual users want the hooks, they can run the script. (Assuming they don't have some exotic setup where .git
isn't in the root of the work tree.)
But no, you can't make it automatic that cloning your repo causes arbitrary code you selected to be run at times of your specification on someone else's computer.
Upvotes: 1
Reputation: 503
You can't do that, from the documentation at https://git-scm.com/book/gr/v2/Customizing-Git-Git-Hooks
It’s important to note that client-side hooks are not copied when you clone a repository. If your intent with these scripts is to enforce a policy, you’ll probably want to do that on the server side
Upvotes: 4