Run a husky git hook manually (without triggering it w/git command)
Asked Answered
Z

2

13

I'm setting up a node project with husky and I want to have a git-hook script run manually, without having to trigger it in git.

Example:

My package.json has the following:

{
...
    "scripts": {
        "precommit": // something goes here
    }
...
    "husky": {
        "hooks": {
            "pre-commit": "lint-staged"
        }
    },
...
}

If I run npm run precommit, the lint-staged hook step runs, WITHOUT the commit actually occurring in git.

Is this possible?

Zephyrus answered 14/11, 2019 at 23:3 Comment(3)
Just call lint-staged command, "precommit": "lint-staged"Coprology
That didn't work, but @VonC's answer did (bash .git/hooks/pre-commit)Zephyrus
npx lint-staged works for me.Catechetical
K
15

It should be possible, since this answer illustrates you can simply call the .git/hooks/pre-commit

So as long as you are calling the hook directly, with its full path, you would run whatever it contains.

Kelsy answered 15/11, 2019 at 5:56 Comment(3)
Thank you sir. I thought I combed through SO but missed that one. :/Zephyrus
@Zephyrus No problem. I have been combing through SO since the dawn of time.Kelsy
honestly I feel like husky should have a shortcut for this, like pre-commit does.Alarum
P
1

If pre-commit is installed globally, you can just run this in the terminal:

pre-commit run --all-files
Permanganate answered 7/3 at 14:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.