Skip to content

What’s the point of husky.sh? #929

Closed
@remcohaszing

Description

@remcohaszing

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

typicode commented on Apr 1, 2021

@typicode
Owner

Hi @remcohaszing,

Thanks :)

Did you create hooks with husky add (or husky set)? It should create them with husky.sh being sourced at the beginning of the file.

Good suggestion for the FAQ.

remcohaszing

remcohaszing commented on Apr 1, 2021

@remcohaszing
Author

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:

  // …
  "scripts": {
    // …
    "prepare": "husky install"
  },
  // …

This just works.

nemchik

nemchik commented on Apr 1, 2021

@nemchik

husky set ... doesn't seem to be documented anywhere on https://typicode.github.io/husky/#/

thasmo

thasmo commented on Apr 2, 2021

@thasmo

@typicode, wondering if husky should use #!/usr/bin/env sh instead of #!/bin/sh in all it's scripts.

typicode

typicode commented on Apr 4, 2021

@typicode
Owner

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 against env sh but what would be good reasons to change it?

remcohaszing

remcohaszing commented on Apr 5, 2021

@remcohaszing
Author

Using #!/usr/bin/env some-shell allows some-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 with nvm.
  • #!/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 be sourced from a script, not to be called as a script directly.

remcohaszing

remcohaszing commented on Apr 15, 2021

@remcohaszing
Author

All of my questions have been answered. Thanks!

TravisBallard

TravisBallard commented on May 19, 2021

@TravisBallard

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

TravisBallard commented on May 22, 2021

@TravisBallard

adding a prepare script to package.json solved it for me.

{ "scripts": {"prepare": "husky install"}}

joetidee

joetidee commented on Aug 11, 2021

@joetidee

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

remcohaszing commented on Aug 11, 2021

@remcohaszing
Author

@joetidee I don’t know why you’d want that, but you can use git add -f to ignore the .gitignore file.

git add -f .husky/_/husky.sh
joetidee

joetidee commented on Aug 11, 2021

@joetidee

@joetidee I don’t know why you’d want that, but you can use git add -f to ignore the .gitignore file.

git add -f .husky/_/husky.sh

I'm not sure why I wouldn't want that :) - could you elaborate on why it shouldn't be included?

remcohaszing

remcohaszing commented on Aug 11, 2021

@remcohaszing
Author

I'm not sure why I wouldn't want that :) - could you elaborate on why it shouldn't be included?

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

joetidee commented on Aug 11, 2021

@joetidee

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

remcohaszing commented on Aug 11, 2021

@remcohaszing
Author

The prepare script in package.json run when you run npm install (or yarn), not when you switch branches.

joetidee

joetidee commented on Aug 11, 2021

@joetidee

Right, so if it disappears when switching branches, that is a pain in the backside :)

remcohaszing

remcohaszing commented on Aug 11, 2021

@remcohaszing
Author

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

iameduardod commented on Aug 24, 2021

@iameduardod

@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....

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @thasmo@nemchik@remcohaszing@TravisBallard@typicode

        Issue actions

          What’s the point of husky.sh? · Issue #929 · typicode/husky