New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A global git-hooks directory defined in a global .gitconfig file prevents husky from functioning properly #391

Closed
jakewies opened this Issue Oct 31, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@jakewies
Copy link

jakewies commented Oct 31, 2018

I have been having trouble with husky lately. It hasn't been running the pre-commit hook I define in my package.json even after its successful installation. Up until this point I had no idea why, but I've found the root cause.

In my ~/.gitconfig I define a path to a "global" git-hooks directory using the property core.hookspath:

~/.gitconfig

[core]
    hookspath = /path/to/global/git-hooks

Inside of this git-hooks directory I currently have 1 hook named prepare-commit-msg.

If I comment out the core.hookspath property in my ~/.gitconfig then husky will work perfectly.

~/.gitconfig

[core]
    # hookspath = /path/to/global/git-hooks

This is sort of frustrating because I clearly want the functionality of husky, AND I always want my global prepare-commit-msg hook to run. But at this moment I have no clue how to allow both to run.

Not sure if anyone has had the same issues.

@adam-moss

This comment has been minimized.

Copy link

adam-moss commented Nov 7, 2018

I don't think you can - from https://git-scm.com/docs/git-config#git-config-corehooksPath it looks like you can have one, or the other, but not both.

You could potentially use init.templateDir for your global hook, symlink'ing in that so you still have one place to maintain it?

@jakewies

This comment has been minimized.

Copy link
Author

jakewies commented Nov 8, 2018

@adam-moss thanks for the reply. That's too bad, it's kind of a frustrating thing. Not a fault of husky, I love the tool. It's just unfortunate I can't have both. I'll look into init.templateDir. Thanks!

@jakewies

This comment has been minimized.

Copy link
Author

jakewies commented Nov 8, 2018

Taking the suggestion of @adam-moss , I ran:

git config --global init.templateDir '~/.git_template'

Then inside of ~/.git_template I added a /hooks directory and moved all of my global hooks there (currently just one).

Now when running git init git will us my /hooks directory as the project's default for .git/hooks.

When I then install husky my custom hooks and the hooks installed by husky can live side by side. I've tested this and it seems to work out great.

on Symlinking

@adam-moss suggested symlinking my already existing core.hooksPath directory to the /hooks directory inside of ~/.git_template, however I was not able to achieve the desired results. I ended up just removing that configuration option in favor of init.templateDir.

Thanks @adam-moss ! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment