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

Subsequent Init runs would clear Husky pre-commit #1520

Open
fgrande opened this issue Sep 16, 2024 · 6 comments
Open

Subsequent Init runs would clear Husky pre-commit #1520

fgrande opened this issue Sep 16, 2024 · 6 comments

Comments

@fgrande
Copy link

fgrande commented Sep 16, 2024

Hi,

if I run "npx run init" after I've already changed pre-commit file in .husky/pre-commit, I lose my changes, it return to the "npm test"

I would suggest (going to send a PR) to create the pre-commit file only if it doesn't exists (so accidental multiple "npx run init" don't break changes).

Going to move the file creation into the try...catch, adding the flag "wx" (it raise an error if the file already exists)

regards
FabioG

@Munaf-Divan
Copy link

I have a similar requirement. I want my existing pre-commit to remain unchanged while I run npx husky init.

@kaspar-p
Copy link

+1. Deprecating install and replacing it with something that does not do what install did is annoying.

@typicode
Copy link
Owner

Init should be run only once. You can do the setup manually also.

@fgrande
Copy link
Author

fgrande commented Oct 31, 2024

@typicode It "should" be run only once. But what if a dev runs it again, after changes on pre-commit file ? That's the meaning of my PR.

@shdq
Copy link

shdq commented Feb 3, 2025

Removing the lines below from your hook files will solve your problems. See "How to Migrate" in the release notes.

e.g. .husky/pre-commit

- #!/usr/bin/env sh
- . "$(dirname -- "$0")/_/husky.sh"
npm run lint --fix

@DevJake
Copy link

DevJake commented Feb 21, 2025

Deprecating install and replacing it with something that does not do what install did is annoying.

Exactly this. An install command is logical, and I don't understand why it was deprecated. I cannot imagine many would want to manually install hooks either. Really, the init command should be idempotent by not overwriting file contents. @shdq I have just tested with what you suggested, with no luck... the file contents are still being overwritten :/

The documentation is rather lacking on what an alternative solution would be. There seemingly isn't a help command (I might be wrong!), so that would be beneficial to view what commands and flags are available.

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

6 participants