Skip to content
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

Husky v6 - conflict between git hooks and husky hooks? #943

Closed
flo-sch opened this issue Apr 9, 2021 · 8 comments
Closed

Husky v6 - conflict between git hooks and husky hooks? #943

flo-sch opened this issue Apr 9, 2021 · 8 comments

Comments

@flo-sch
Copy link

flo-sch commented Apr 9, 2021

Context
I recently migrated from v4 to v6 and managed to get husky hooks working fine with the new config.
However, I had hooks setup from other tools (in my case, gitmoji), installed directly inside .git/hooks/prepare-commit-msg

#!/bin/sh
# gitmoji as a commit hook
exec < /dev/tty
gitmoji --hook $1 $2

Before migrating

Using husky v4, I had the possibility to enforce hooks with husky:

// package.json
"husky": {
  "hooks": {
    "pre-commit": "lint-staged"
  }
},

And git hooks setup directly inside .git/hooks were running just fine as well.

After migrating

Using husky v6, hooks setup inside .git/hooks seem to be ignored for some reason (cannot figure out why myself).
The content of files in there has not changed, and when I reset .git/hooks/prepare-commit-msg using gitmoji -r then gitmoji -i, I can see the file .git/hooks/prepare-commit-msg being removed then re-created.

If I install it as a husky hook inside .husky/prepare-commit-msg then it is active when running git commit.

BUT, my problem is that .husky is commited, and the hook would apply to anyone contributing in the project,
where .git/hooks, which is not commited, allows for anyone to enable or disable specific hooks.

A few questions then:

  • is husky v6 somehow preventing "direct" git hooks to run (is that a known Breaking Change that I missed somewhere?)
  • is there a workaround to use direct hooks in parallel of husky v6?

PS: I have not tested the edge-case of conflicting hooks defined both inside .git/hooks AND .husky (same hook), but this is not really my case here (I would personally be fine with husky "taking over" in such case, to enforce a team's shared settings over user personal settings)

@SalahAdDin
Copy link

Did you review in the last comments? I think we had this bug migrating from 4 to 5 and the solution was deleting the .git/hooks folder. Did you try it?

@flo-sch
Copy link
Author

flo-sch commented Apr 12, 2021

I did not find anything mentioning that in the other issues, is that a thing?
Unless there are very specific reasons behind it, I would rather avoid doing such, since those could be setup by husky or other tools

@flo-sch
Copy link
Author

flo-sch commented Apr 12, 2021

I just tested the following scenario and it did not help, prepare-commit-msg native git hook is still being ignored.

# move the current settings so they are ignored
mv .husky/prepare-commit-msg .husky/prepare-commit-msg2
mv .git/hooks .git/hooks2

# create an empty .git/hooks folder
mkdir .git/hooks

# Reinitialize husky & gitmoji
npx husky-init
gitmoji -i
# ✔ Gitmoji commit hook created successfully

But same status: .git/hooks/prepare-commit-msg is correctly created, and is executable with 0755 permissions, but is ignored when running git commit.

@SalahAdDin
Copy link

@SalahAdDin As far as I can remember, since Husky5 it does relate anymore on .git/hooks but on .husky folder.

@flo-sch
Copy link
Author

flo-sch commented Apr 12, 2021

Yes I'm aware that husky hooks should be moved to .husky in v6, and those work fine :)

My issue is that, after migrating to husky v6, hooks setup directly inside .git/hooks (folder which is not specific to husky) are ignored

@flo-sch
Copy link
Author

flo-sch commented Apr 12, 2021

Okay I think I understand now, running husky install by default sets core.hooksPath path to .husky directory, which applies to every git hooks, and result in hooks placed under .git/hooks being ignored.

In my case, gitmoji is not aware of that config and still try to to put those in there.
I could tell husky to install inside .git/hooks:

{
  "scripts": {
    "prepare": "husky install .git/hooks"
  }
}

But then all hooks (even husky ones) are unversioned, up to every contributor to set or not set those (also unsure if that works in Windows systems)

Or I guess I could add prepare-commit-msg to .husky/gitignore to specifically unversion that one.

Still, I felt husky v4 was naturally integrating with git hooks, where v6 is taking over the native git config and a way that I find too opinionated for me 😕

@flo-sch
Copy link
Author

flo-sch commented Apr 14, 2021

I guess I will close that one then, since it seems like the intended behavior of husky v6

@flo-sch flo-sch closed this as completed Apr 14, 2021
@reda-alaoui
Copy link

The fact that Husky changes core.hooksPath as if it was the only git hook provider in the world is stunning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants