git-katas icon indicating copy to clipboard operation
git-katas copied to clipboard

Custom hooks interferring w/ exercises

Open figaw opened this issue 7 years ago • 4 comments

Global hooks designed to force conventions e.g. "adding a jira-id" to a commit message, interferes with the exercises, i.e. while doing exercises on machines with these hooks, we have to keep adding jira-id's to do our commits.

Would it be possible to nullify "all" or "acceptance" hooks, on a repository level - just for the exercises?

figaw avatar Jan 16 '18 08:01 figaw

@figaw how are these global hooks implemented? Githooks are local to the repository, and by default are not included in a clone. The only way I know of to have hooks included in a newly cloned repository is to have it stored along with the default hook samples in the templates directory in the local git installation ($HOME/git/share/git-core/templates/hooks). So a simple way to disable global hooks is to simply delete the contents of .git/hooks in the git-kata repo and those created by the setup scripts.

Also, since Git 2.9 we've had the core.hooksPath config setting which makes it even simpler:

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.

Simply set core.hooksPath to /dev/null or another empty directory after cloning the repository. The hook will still be copied with the rest of the samples, but won't look for it in the usual place.

michaelin avatar Feb 18 '20 23:02 michaelin

We had it happen at a customer some time ago, so I do not remember precisely how the implementation was instated, but you can assume it was "system wide" configuration. The issue could also happen in a post-checkout hook, so it might not be enough to do something after the clone of the gitkatas. It might also be something that we can solve in a different way my creating a release with the exercise repositories created, and add a script to reset rather than create other commits.

RandomSort avatar Feb 19 '20 06:02 RandomSort

The post-checkout hook still needs to be set up at some point on the local machine. So they probably have an environment configuration script that they have run on their local machines.

As far as I can see, the only way to enforce system-wide hooks, is to a) copy the hooks into the local clones .git/hooks directory automatically, or b) use core.hooksPath to point to the hooks in another location

In both cases, changing core.hooksPath in the local git config should solve the problem, as it overrides values from the global or system level config.

It could be great to try it out next time it happens. Simply run git config --local core.hooksPath .local_hooks inside the exercise repo after running the setup script.

Also, maybe we need a kata on git hooks? ;)

michaelin avatar Feb 19 '20 12:02 michaelin

There is already one :) It might also be useful to just skip client side hooks with flags, on each command :)

On Wed, Feb 19, 2020 at 1:48 PM Michael Ingeman-Nielsen < [email protected]> wrote:

The post-checkout hook still needs to be set up at some point on the local machine. So they probably have an environment configuration script that they have run on their local machines.

As far as I can see, the only way to enforce system-wide hooks, is to a) copy the hooks into the local clones .git/hooks directory automatically, or b) use core.hooksPath to point to the hooks in another location

In both cases, changing core.hooksPath in the local git config should solve the problem, as it overrides values from the global or system level config.

It could be great to try it out next time it happens. Simply run git config --local core.hooksPath .local_hooks inside the exercise repo after running the setup script.

Also, maybe we need a kata on git hooks? ;)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/praqma-training/git-katas/issues/124?email_source=notifications&email_token=AAEOHKZ2DJLWVOZTQKME6ELRDUTBTA5CNFSM4EL5QY42YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMHV7ZY#issuecomment-588210151, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEOHK5UAE63TEGBQJTABATRDUTBTANCNFSM4EL5QY4Q .

RandomSort avatar Feb 19 '20 13:02 RandomSort