Closed
Description
I love how the latest husky incorporates core.hooksPath
. This makes it so much simpler.
I noticed husky creates .husky/_/husky.sh
(and .husky/.gitignore
), but I don’t really see the point of this file. As far as I can tell, it’s unused.
Could someone explain what this is for? Perhaps it belongs in the FAQ.
Activity
typicode commentedon Apr 1, 2021
Hi @remcohaszing,
Thanks :)
Did you create hooks with
husky add
(orhusky set
)? It should create them withhusky.sh
being sourced at the beginning of the file.Good suggestion for the FAQ.
remcohaszing commentedon Apr 1, 2021
No, I created
.husky/pre-commit
with the following contents:#!/usr/bin/env sh yarn lint-staged
And of course I added the following to
package.json
:This just works.
nemchik commentedon Apr 1, 2021
husky set ...
doesn't seem to be documented anywhere on https://typicode.github.io/husky/#/husky.sh
inside hook using#!/usr/bin/env node
? #930thasmo commentedon Apr 2, 2021
@typicode, wondering if
husky
should use#!/usr/bin/env sh
instead of#!/bin/sh
in all it's scripts.typicode commentedon Apr 4, 2021
Generally speaking, I'd recommend keeping
husky.sh
. It contains code that can be useful for GUI users cloning the project and may have some additional features in future versions of husky.@thasmo I picked the shebang used by Git hooks samples (in
.git/hooks
). I'm not againstenv sh
but what would be good reasons to change it?remcohaszing commentedon Apr 5, 2021
Using
#!/usr/bin/env some-shell
allowssome-shell
to be detected from the environment, whereas specifying an exact path in the shebang forces the user to install the shell to that specific location. Some practival examples:#!/usr/bin/env node
works withnvm
.#!/usr/bin/env python
works with Python virtual environments.#!/usr/bin/env bash
allows users to install a specific version of bash. I.e. I recall system bash was outdated on MacOS at some point.For
husky.sh
the shebang is unused. It’s supposed to besource
d from a script, not to be called as a script directly.huksy
tosimple-git-hooks
typescript-eslint/typescript-eslint#3222remcohaszing commentedon Apr 15, 2021
All of my questions have been answered. Thanks!
TravisBallard commentedon May 19, 2021
Why is husky.sh added to the .gitignore file? This means anyone who checks out the code in my repo can still commit without the hooks running. The hooks wont run until the user runs
npx husky install
to generate the_
folder that's missing from the repo since it's being ignored?TravisBallard commentedon May 22, 2021
adding a
prepare
script topackage.json
solved it for me.{ "scripts": {"prepare": "husky install"}}
joetidee commentedon Aug 11, 2021
Every time I checkout from my branch to master, the husky.sh file disappears. Any reason why> Why can it not be committed with the repo?
remcohaszing commentedon Aug 11, 2021
@joetidee I don’t know why you’d want that, but you can use
git add -f
to ignore the.gitignore
file.joetidee commentedon Aug 11, 2021
I'm not sure why I wouldn't want that :) - could you elaborate on why it shouldn't be included?
remcohaszing commentedon Aug 11, 2021
It’s autogenerated by husky. Generally I think committing autogenerated files is a bad idea. Husky creates a
.gitignore
file for it for a reason.joetidee commentedon Aug 11, 2021
ok, so why doesn't it autogenerate when I checkout master? (I have the
"prepare": "husky install"
in my package.json)p.s. I have husky 6.0.0 installed.
remcohaszing commentedon Aug 11, 2021
The
prepare
script inpackage.json
run when you runnpm install
(oryarn
), not when you switch branches.joetidee commentedon Aug 11, 2021
Right, so if it disappears when switching branches, that is a pain in the backside :)
remcohaszing commentedon Aug 11, 2021
Switching branches doesn’t delete files that haven’t been committed. Maybe you have committed it in one of the branches your working on?
iameduardod commentedon Aug 24, 2021
@husky team - not including this shell script and forcing new repo users to do the init overrides the existing repo's .husky/pre-commit file.
Not very cash money....