Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update pre_commit hook file on version control

Tags:

git

githooks

I recently updated my pre_commit.sample file to run rubocop upon a commit (renamed to pre_commit).

#!/bin/sh
#
# Check for ruby style errors
rake run:rubocop

Mistakingly I thought this would update on other developers machines when pulling the changes. How can i ensure that anyone who pulls the change has their pre_commit file updated

Thanks

like image 511
Richlewis Avatar asked Sep 08 '26 13:09

Richlewis


1 Answers

Up until git v2.9 there was no way to update hooks on client side.

Git v2.9 exposed new configuration to allow this with this:

git config [--local] core.hooksPath ...

core.hooksPath By default Git will look for your hooks in the $GIT_DIR/hooks directory. Set this to different path, e.g. /etc/git/hooks, and Git will try to find your hooks in that directory, e.g. /etc/git/hooks/pre-receive instead of in $GIT_DIR/hooks/pre-receive.

The path can be either absolute or relative.
A relative path is taken as relative to the directory where the hooks are run.

This configuration variable is useful in cases where you’d like to centrally configure your Git hooks instead of configuring them on a per-repository basis, or as a more flexible and centralized alternative to having an init.templateDir where you’ve changed default hooks.

like image 175
CodeWizard Avatar answered Sep 11 '26 02:09

CodeWizard