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 v5 and Gitkraken #875

Closed
nicolas-goudry opened this issue Feb 16, 2021 · 31 comments
Closed

Husky v5 and Gitkraken #875

nicolas-goudry opened this issue Feb 16, 2021 · 31 comments

Comments

@nicolas-goudry
Copy link

nicolas-goudry commented Feb 16, 2021

Disclaimer

This is no longer an issue since Gitkraken v7.7.2, as support for core.hooksPath has been added.

However, only absolute paths are supported if you’re using Gitkraken version lower than 8.0.0. Since Gitkraken v8.0.0, relative paths from repository are also supported.

You can see the Gitkraken feature request here.

Original issue

For anyone having issues setting up Husky v5 with Gitkraken, here are some explanations about why it’s happening, and how to fix it.

As of husky v5, a custom hooks path is used (.husky) rather than default git’s one (.git/hooks). This is done through setting local git config core.hookspath key.

As of today and version 7.5, Gitkraken does not support core.hookspath and will use .git/hooks folder anyway.
This is a known issue of Gitkraken team that goes back as far as 7 months ago. There seems to be an existing feature request to support it, so you could show your interest on Slack if you want things to move faster.
I don’t work at Axosoft, so I’m not sure if showing interest would make this feature come earlier, but it definitely would bring some light on it!

The workaround to fix this issue is pretty simple: create a symbolic link from .git/hooks to husky’s directory. It may not be the best way, but it’s the only way I found.

Linux / MacOS

From you project root:

$ rm -rf .git/hooks && ln -s ../.husky .git/hooks

You may add this command to your package.json postinstall script, alongside husky install:

{
  "scripts": {
    "postinstall": "husky install && rm -rf .git/hooks && ln -s ../.husky .git/hooks"
  }
}

Windows

Solution provided by @Autapomorph (see comment):

Add shx and then, from you project root:

$ shx rm -rf .git/hooks && shx ln -s ../.husky .git/hooks

Solution provided by @snebjorn (see comment):

Use mklink after removing .git/hooks folder (not tested):

$ mklink /j hooks ..\.husky

As well as for Linux / MacOS solution, you may add these commands to your package.json postinstall script, alongside husky install (if using shx variant, don’t forget to add it as a devDependency to your project).

All systems

You will need to reload the repository in Gitkraken if it’s already opened.

After doing so, husky’s hooks will work as expected in Gitkraken.

@Fdawgs
Copy link

Fdawgs commented Feb 18, 2021

Thanks @nicolas-goudry!
Ended up staying on v4 as I couldn't figure out how to get v5 working with Gitkraken.

Will give this a shot now.

@nicolas-goudry
Copy link
Author

@Fdawgs you're welcome, tell me if you have any problem!

@typicode
Copy link
Owner

Thanks for sharing @nicolas-goudry 👍

@adriankwiat
Copy link

Do you have solution that works on Windows too?

@Autapomorph
Copy link

Autapomorph commented Feb 22, 2021

@adriankwiat you can try shx for cross-platform:

{
  "scripts": {
    "postinstall": "husky install && shx rm -rf .git/hooks && shx ln -s ../.husky .git/hooks"
  }
}

@thasmo
Copy link

thasmo commented Mar 30, 2021

@nicolas-goudry Do you know, is there public information from Axosoft regarding this feature request somewhere? Thanks!

@nicolas-goudry
Copy link
Author

@thasmo Apart from the Slack message linked in main issue, there isn’t anything else that I know of that references this issue publicly.

@nicolas-goudry
Copy link
Author

@typicode I made a small tool to auto-install husky in different project typologies, which also (optionally) addresses this issue.

Could you please give it a look?

➡️ auto-husky

@bertyhell
Copy link

I had the same issue. I solved it by using the pre-commit package to trigger the hooks, which plays nice with gitkraken.
And then a custom script to use lint-staged to only process the staged files.

Use at your own risk:
https://gist.github.com/bertyhell/c8ae817626e053375bad0d62efc1da7d

@zoispag
Copy link

zoispag commented Jun 25, 2021

This is a known issue of Gitkraken team that goes back as far as 7 months ago.

Sorry to reply to an old issue description, but, 7 months you say?
I've reported this almost 3 years ago. They said the feature request is under review. Still waiting! :)

image

image

@akd-io
Copy link

akd-io commented Jul 1, 2021

Running into this issue as well. Very unfortunate. Have been very happy with GitKraken otherwise.

As of husky v5, a custom hooks path is used (.husky) rather than default git’s one (.git/hooks).

Does anyone know why this is the case exactly?

@zoispag
Copy link

zoispag commented Jul 1, 2021

Running into this issue as well. Very unfortunate. Have been very happy with GitKraken otherwise.

As of husky v5, a custom hooks path is used (.husky) rather than default git’s one (.git/hooks).

Does anyone know why this is the case exactly?

Best guess; NodeGit that GitKraken is using, does not support the hookspath option.

@snebjorn
Copy link

snebjorn commented Jul 9, 2021

On Windows you can use mklink

Delete the hooks folder in .git folder, then create a Directory Junction that makes .git/hooks point to .husky using the below command. (Only works in the command prompt)

mklink /j hooks ..\.husky

You can also upvote the core.hookspath feature request here:
https://feedback.gitkraken.com/suggestions/191601/support-githookspath

@SalahAdDin
Copy link

Running into this issue as well. Very unfortunate. Have been very happy with GitKraken otherwise.

As of husky v5, a custom hooks path is used (.husky) rather than default git’s one (.git/hooks).

Does anyone know why this is the case exactly?

Best guess; NodeGit that GitKraken is using, does not support the hookspath option.

I'm having this issue with the last version (7.0).

@snebjorn
Copy link

GitKraken support for core.hooksPath is now marked as "Planned" 🎉
Thanks for upvoting, it really seemed to have made a difference :)

@akd-io
Copy link

akd-io commented Jul 29, 2021

@snebjorn Woohoo! 🎊 Thanks for the update

@Fdawgs
Copy link

Fdawgs commented Aug 11, 2021

Support for core.hooksPath now in v7.7.2

@KillWolfVlad
Copy link

On Windows don't work. GitKraken v7.7.2 say that my path is invalid.
изображение

Absolute path works like a charm.

@cedricr
Copy link

cedricr commented Aug 12, 2021

On Windows don't work. GitKraken v7.7.2 say that my path is invalid.
изображение

Absolute path works like a charm.

Same on Mac.

@KillWolfVlad
Copy link

On Windows don't work. GitKraken v7.7.2 say that my path is invalid.
изображение

Absolute path works like a charm.

I think it is because GitKraken v7.7.2 don't join relative hooks path with repository path. If you copy your .husky directory to GitKraken working directory (on Windows it is %LOCALAPPDATA%\gitkraken\app-7.7.2) everything will work.

grikomsn pushed a commit to grikomsn/multiverse that referenced this issue Aug 13, 2021
@C0ZEN
Copy link

C0ZEN commented Aug 18, 2021

Fixing the path and running once again the installation of husky change back the path to “.husky”, which doesn't works.
So, it's easy to come up with a fix in GitKraken config, but it's annoying if for example you use a “prepare” script which install husky.

@SalahAdDin
Copy link

Fixing the path and running once again the installation of husky change back the path to “.husky”, which doesn't works.
So, it's easy to come up with a fix in GitKraken config, but it's annoying if for example you use a “prepare” script which install husky.

of course, it is.

@snebjorn
Copy link

The GitKraken team is aware of this bug. They're maybe working on it. Their response is vague and non-commiting 😞

Hi Sebastian and Esd, there isn't a feature request for adding support for relative paths that I know of - it is bug that is with our team for investigation (this board is for feature requests only, bugs are kept internally by our team) .

I have noted your additional interest fixing the GitKraken hooks path setting to recognize relative paths. When bugs are fixed they will be listed in our release notes both in-app and on our support site

https://feedback.gitkraken.com/suggestions/191601/support-corehookspath

@moroine
Copy link

moroine commented Sep 20, 2021

You just need to use husky install $PWD/.husky as postinstall script

@ShaneYu
Copy link

ShaneYu commented Sep 22, 2021

FYI - I am using GitKraken version 8.0.0 (x64) and it's running the Husky hooks no problem, guessing that this issue has not been fixed.

The release note detailed Relative paths are now allowed in hooksPath., not sure if that was the fix, but it's working now.

@bertyhell
Copy link

@ShaneYu

guessing that this issue has not been fixed.

You mean: this issue has been fixed.
right?

@Peterabsolon
Copy link

You just need to use husky install $PWD/.husky as postinstall script

That doesn't work for Windows users though

@nicolas-goudry
Copy link
Author

@Peterabsolon you could use husky install %cd%/.husky or use shx pwd in an evaluated subcommand.

@H6LS1S
Copy link

H6LS1S commented Oct 9, 2021

Today updated to version 7 of the husky, kind of everything works fine, I migrated using this tool: https://github.com/typicode/husky-4-to-7

OS: Solus 4.3 ( Linux )
Husky: 7.0.0
Git: 2.32.0
GK: 8.0.1

@nicolas-goudry
Copy link
Author

@H6LS1S as per this comment and this comment it seems to be fixed since Gitkraken 7.7.2, with an even better support on v8+.

Not related to husky 7 then.

I might update the original issue to provide more detailed information about everything that has been discussed in the 40+ comments here.

@typicode should I close this issue, as it's not anymore an ongoing bug with latest Gitkraken versions?

@nicolas-goudry
Copy link
Author

Original issue has been updated with relevant details.

Closing this as it’s no longer an issue.

yoonminsang added a commit to yoonminsang/react-typescript-boilerplate that referenced this issue Jul 22, 2022
- gitkraken을 사용하는 경우 필요한 스크립트
- typicode/husky#875
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