Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 705
n8jadams Avatar asked Nov 14 '19 23:11

n8jadams


People also ask

How do I manually run a pre-commit hook?

If you want to manually run all pre-commit hooks on a repository, run pre-commit run --all-files . To run individual hooks use pre-commit run <hook_id> . The first time pre-commit runs on a file it will automatically download, install, and run the hook.

How do I bypass a git hook?

Use the --no-verify option to skip git commit hooks, e.g. git commit -m "commit message" --no-verify . When the --no-verify option is used, the pre-commit and commit-msg hooks are bypassed.


1 Answers

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.

like image 145
VonC Avatar answered Oct 22 '22 18:10

VonC