Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: typicode/husky
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 85a47046c5cf1ae26072fbf39f5f01fdde1cae34
Choose a base ref
...
head repository: typicode/husky
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b9a09172ac3516b3d1f9e2cfa53ace31ae9ff412
Choose a head ref

Commits on May 6, 2020

  1. increase sponsors height

    typicode committed May 6, 2020
    Copy the full SHA
    5c49052 View commit details
  2. Update README.md

    typicode authored May 6, 2020
    Copy the full SHA
    275f088 View commit details
  3. Update README.md

    typicode authored May 6, 2020
    Copy the full SHA
    0b4a64d View commit details

Commits on May 26, 2020

  1. Copy the full SHA
    7259d0f View commit details
  2. Update README.md

    typicode authored May 26, 2020
    1
    Copy the full SHA
    e5531f1 View commit details

Commits on Sep 7, 2020

  1. add .cjs suport (#754)

    mbrevda authored Sep 7, 2020
    Copy the full SHA
    6eb57f0 View commit details
  2. Bump lodash from 4.17.15 to 4.17.19 (#744)

    Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19.
    - [Release notes](https://github.com/lodash/lodash/releases)
    - [Commits](lodash/lodash@4.17.15...4.17.19)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Sep 7, 2020
    Copy the full SHA
    4ea1ef5 View commit details
  3. Copy the full SHA
    88fe8ea View commit details
  4. 4.3.0

    typicode committed Sep 7, 2020
    Copy the full SHA
    28d29e8 View commit details
  5. update snapshot

    typicode committed Sep 7, 2020
    Copy the full SHA
    905fc4f View commit details

Commits on Sep 15, 2020

  1. Update README.md

    typicode authored Sep 15, 2020
    Copy the full SHA
    f9ec4ec View commit details
  2. Create node.js.yml

    typicode authored Sep 15, 2020
    Copy the full SHA
    5495c68 View commit details
  3. Update node.js.yml

    typicode authored Sep 15, 2020
    Copy the full SHA
    505e8ac View commit details
  4. Update node.js.yml

    typicode authored Sep 15, 2020
    Copy the full SHA
    44e02bd View commit details
  5. Update node.js.yml

    typicode authored Sep 15, 2020
    Copy the full SHA
    b05e72f View commit details

Commits on Sep 17, 2020

  1. Update README.md

    typicode authored Sep 17, 2020
    Copy the full SHA
    bb0c414 View commit details
  2. Changed create-react-app repo url (#759)

    Repo create-react-app has been moved from 'facebookincubator' to 'facebook'
    LuisEnMarroquin authored Sep 17, 2020
    Copy the full SHA
    b616d84 View commit details

Commits on Sep 22, 2020

  1. Update README.md

    typicode authored Sep 22, 2020
    Copy the full SHA
    eff9aa3 View commit details

Commits on Dec 1, 2020

  1. update gitignore

    typicode committed Dec 1, 2020
    Copy the full SHA
    38a7163 View commit details
  2. 1
    Copy the full SHA
    033a2ae View commit details
  3. 4.3.1

    typicode committed Dec 1, 2020
    Copy the full SHA
    6dc9a51 View commit details

Commits on Dec 5, 2020

  1. provide workaround for npm7

    typicode committed Dec 5, 2020
    Copy the full SHA
    41472b7 View commit details
  2. 4.3.2

    typicode committed Dec 5, 2020
    Copy the full SHA
    a5f1259 View commit details
  3. ignore tsconfig.tsbuildinfo

    typicode committed Dec 5, 2020
    Copy the full SHA
    fd0233e View commit details
  4. 4.3.3

    typicode committed Dec 5, 2020
    Copy the full SHA
    b29ee2b View commit details
  5. update error message

    typicode committed Dec 5, 2020
    Copy the full SHA
    1e1b289 View commit details
  6. 4.3.4

    typicode committed Dec 5, 2020
    Copy the full SHA
    3c43bd5 View commit details
  7. Update README.md

    typicode authored Dec 5, 2020
    Copy the full SHA
    ccb71b2 View commit details

Commits on Dec 7, 2020

  1. Copy the full SHA
    642af0c View commit details
  2. 4.3.5

    typicode committed Dec 7, 2020
    Copy the full SHA
    992c1e0 View commit details

Commits on Dec 11, 2020

  1. add prepare-commit-msg test

    all credit goes to @kirkoman
    
    Co-authored-by: Kirk McKelvey <kmckelvey@extensis.com>
    typicode and Kirk McKelvey committed Dec 11, 2020
    Copy the full SHA
    cbd0e06 View commit details
  2. Update README.md

    typicode authored Dec 11, 2020
    Copy the full SHA
    65bc6e5 View commit details

Commits on Dec 13, 2020

  1. Copy the full SHA
    eb1eeb8 View commit details
  2. 4.3.6

    typicode committed Dec 13, 2020
    Copy the full SHA
    cbb0af7 View commit details

Commits on Jan 7, 2021

  1. Upgrade find-versions to 4.0.0 (#837)

    `find-versions` 4.0.0 depends on `^3.1.2` of `semver-regex`. Previous
    versions of `semver-regex` contained a [vulnernability][0]. This was
    unlikely to affect `husky` because of how `find-versions` is used, but
    the only breaking change in `find-versions` is increasing the minimum
    Node.js verison to 10, which is the same as Husky's minimum.
    
    [0]: https://app.snyk.io/vuln/SNYK-JS-SEMVERREGEX-1047770
    k0nserv authored Jan 7, 2021
    Copy the full SHA
    6a1b3da View commit details
  2. Copy the full SHA
    839d84a View commit details
  3. 4.3.7

    typicode committed Jan 7, 2021
    Copy the full SHA
    b9a0917 View commit details
Showing with 601 additions and 276 deletions.
  1. +25 −0 .github/workflows/node.js.yml
  2. +2 −0 .gitignore
  3. +1 −0 .npmignore
  4. +100 −80 README.md
  5. +414 −174 package-lock.json
  6. +7 −6 package.json
  7. +2 −2 scripts/oc.js
  8. +32 −0 scripts/test-install.sh
  9. +2 −2 sh/husky.sh
  10. +6 −6 src/installer/__tests__/__snapshots__/scripts.ts.snap
  11. +6 −1 src/installer/bin.ts
  12. +1 −2 src/runner/__tests__/index.ts
  13. +3 −3 src/runner/index.ts
25 changes: 25 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on: [push]

jobs:
build:
name: Test on node ${{ matrix.node_version }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}

strategy:
matrix:
node-version: [10.x, 14.x]
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run postinstall --if-present
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*.log
.DS_Store
.husky
ci-post-checkout
hook-params
lib
node_modules/
tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -10,3 +10,4 @@ hook-params
scripts
src
tsconfig.json
tsconfig.tsbuildinfo
180 changes: 100 additions & 80 deletions README.md
Original file line number Diff line number Diff line change
@@ -6,8 +6,14 @@
Husky can prevent bad `git commit`, `git push` and more 🐶 _woof!_

**Announcement: Husky v5 has been published, to view v5 docs click [here](https://typicode.github.io/husky).**

**Note to npm v7 users**: if hooks aren't being installed with npm `v7`, check that your version is at least `v7.1.2`.

## Install

This will install husky v4.

```sh
npm install husky --save-dev
```
@@ -43,84 +49,100 @@ npm uninstall husky

_Git hooks installed by husky will be removed._

## Financial Contributors

Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/husky/contribute)]

### Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/husky/contribute)]

<!-- oc -->
#### Gold Sponsors ($500/mo)
<a href="https://opencollective.com/husky/tiers/gold-sponsor/0/website"><img src="https://opencollective.com/husky/tiers/gold-sponsor/0/avatar.svg" height="60px"></a>
<a href="https://opencollective.com/husky/tiers/gold-sponsor/1/website"><img src="https://opencollective.com/husky/tiers/gold-sponsor/1/avatar.svg" height="60px"></a>
<a href="https://opencollective.com/husky/tiers/gold-sponsor/2/website"><img src="https://opencollective.com/husky/tiers/gold-sponsor/2/avatar.svg" height="60px"></a>
<a href="https://opencollective.com/husky/tiers/gold-sponsor/3/website"><img src="https://opencollective.com/husky/tiers/gold-sponsor/3/avatar.svg" height="60px"></a>
<a href="https://opencollective.com/husky/tiers/gold-sponsor/4/website"><img src="https://opencollective.com/husky/tiers/gold-sponsor/4/avatar.svg" height="60px"></a>
<a href="https://opencollective.com/husky/tiers/gold-sponsor/5/website"><img src="https://opencollective.com/husky/tiers/gold-sponsor/5/avatar.svg" height="60px"></a>
<a href="https://opencollective.com/husky/tiers/gold-sponsor/6/website"><img src="https://opencollective.com/husky/tiers/gold-sponsor/6/avatar.svg" height="60px"></a>
<a href="https://opencollective.com/husky/tiers/gold-sponsor/7/website"><img src="https://opencollective.com/husky/tiers/gold-sponsor/7/avatar.svg" height="60px"></a>
<a href="https://opencollective.com/husky/tiers/gold-sponsor/8/website"><img src="https://opencollective.com/husky/tiers/gold-sponsor/8/avatar.svg" height="60px"></a>
<a href="https://opencollective.com/husky/tiers/gold-sponsor/9/website"><img src="https://opencollective.com/husky/tiers/gold-sponsor/9/avatar.svg" height="60px"></a>

#### Silver Sponsors ($250/mo)
<a href="https://opencollective.com/husky/tiers/silver-sponsor/0/website"><img src="https://opencollective.com/husky/tiers/silver-sponsor/0/avatar.svg" height="45px"></a>
<a href="https://opencollective.com/husky/tiers/silver-sponsor/1/website"><img src="https://opencollective.com/husky/tiers/silver-sponsor/1/avatar.svg" height="45px"></a>
<a href="https://opencollective.com/husky/tiers/silver-sponsor/2/website"><img src="https://opencollective.com/husky/tiers/silver-sponsor/2/avatar.svg" height="45px"></a>
<a href="https://opencollective.com/husky/tiers/silver-sponsor/3/website"><img src="https://opencollective.com/husky/tiers/silver-sponsor/3/avatar.svg" height="45px"></a>
<a href="https://opencollective.com/husky/tiers/silver-sponsor/4/website"><img src="https://opencollective.com/husky/tiers/silver-sponsor/4/avatar.svg" height="45px"></a>
<a href="https://opencollective.com/husky/tiers/silver-sponsor/5/website"><img src="https://opencollective.com/husky/tiers/silver-sponsor/5/avatar.svg" height="45px"></a>
<a href="https://opencollective.com/husky/tiers/silver-sponsor/6/website"><img src="https://opencollective.com/husky/tiers/silver-sponsor/6/avatar.svg" height="45px"></a>
<a href="https://opencollective.com/husky/tiers/silver-sponsor/7/website"><img src="https://opencollective.com/husky/tiers/silver-sponsor/7/avatar.svg" height="45px"></a>
<a href="https://opencollective.com/husky/tiers/silver-sponsor/8/website"><img src="https://opencollective.com/husky/tiers/silver-sponsor/8/avatar.svg" height="45px"></a>
<a href="https://opencollective.com/husky/tiers/silver-sponsor/9/website"><img src="https://opencollective.com/husky/tiers/silver-sponsor/9/avatar.svg" height="45px"></a>

#### Bronze Sponsors ($100/mo)
<a href="https://opencollective.com/husky/tiers/bronze-sponsor/0/website"><img src="https://opencollective.com/husky/tiers/bronze-sponsor/0/avatar.svg" height="30px"></a>
<a href="https://opencollective.com/husky/tiers/bronze-sponsor/1/website"><img src="https://opencollective.com/husky/tiers/bronze-sponsor/1/avatar.svg" height="30px"></a>
<a href="https://opencollective.com/husky/tiers/bronze-sponsor/2/website"><img src="https://opencollective.com/husky/tiers/bronze-sponsor/2/avatar.svg" height="30px"></a>
<a href="https://opencollective.com/husky/tiers/bronze-sponsor/3/website"><img src="https://opencollective.com/husky/tiers/bronze-sponsor/3/avatar.svg" height="30px"></a>
<a href="https://opencollective.com/husky/tiers/bronze-sponsor/4/website"><img src="https://opencollective.com/husky/tiers/bronze-sponsor/4/avatar.svg" height="30px"></a>
<a href="https://opencollective.com/husky/tiers/bronze-sponsor/5/website"><img src="https://opencollective.com/husky/tiers/bronze-sponsor/5/avatar.svg" height="30px"></a>
<a href="https://opencollective.com/husky/tiers/bronze-sponsor/6/website"><img src="https://opencollective.com/husky/tiers/bronze-sponsor/6/avatar.svg" height="30px"></a>
<a href="https://opencollective.com/husky/tiers/bronze-sponsor/7/website"><img src="https://opencollective.com/husky/tiers/bronze-sponsor/7/avatar.svg" height="30px"></a>
<a href="https://opencollective.com/husky/tiers/bronze-sponsor/8/website"><img src="https://opencollective.com/husky/tiers/bronze-sponsor/8/avatar.svg" height="30px"></a>
<a href="https://opencollective.com/husky/tiers/bronze-sponsor/9/website"><img src="https://opencollective.com/husky/tiers/bronze-sponsor/9/avatar.svg" height="30px"></a>
<!-- oc-end -->
## Sponsors

### Companies (\$100+/month)

<!-- for (let i = 0; i < 40; i++) console.log(`[![Husky Sponsor](https://opencollective.com/husky/backer/${i}/avatar)](https://opencollective.com/husky/backer/${i}/website)`) -->

Does your company use Husky? Ask your manager or marketing team if your company would be interested in supporting this project.

<a href="https://opencollective.com/husky/tiers/sponsor/0/website"><img src="https://opencollective.com/husky/tiers/sponsor/0/avatar.svg" height="60px"></a>
<a href="https://opencollective.com/husky/tiers/sponsor/1/website"><img src="https://opencollective.com/husky/tiers/sponsor/1/avatar.svg" height="60px"></a>
<a href="https://opencollective.com/husky/tiers/sponsor/2/website"><img src="https://opencollective.com/husky/tiers/sponsor/2/avatar.svg" height="60px"></a>
<a href="https://opencollective.com/husky/tiers/sponsor/3/website"><img src="https://opencollective.com/husky/tiers/sponsor/3/avatar.svg" height="60px"></a>
<a href="https://opencollective.com/husky/tiers/sponsor/4/website"><img src="https://opencollective.com/husky/tiers/sponsor/4/avatar.svg" height="60px"></a>
<a href="https://opencollective.com/husky/tiers/sponsor/5/website"><img src="https://opencollective.com/husky/tiers/sponsor/5/avatar.svg" height="60px"></a>
<a href="https://opencollective.com/husky/tiers/sponsor/6/website"><img src="https://opencollective.com/husky/tiers/sponsor/6/avatar.svg" height="60px"></a>
<a href="https://opencollective.com/husky/tiers/sponsor/7/website"><img src="https://opencollective.com/husky/tiers/sponsor/7/avatar.svg" height="60px"></a>
<a href="https://opencollective.com/husky/tiers/sponsor/8/website"><img src="https://opencollective.com/husky/tiers/sponsor/8/avatar.svg" height="60px"></a>
<a href="https://opencollective.com/husky/tiers/sponsor/9/website"><img src="https://opencollective.com/husky/tiers/sponsor/9/avatar.svg" height="60px"></a>

### Individuals

<a href="https://opencollective.com/husky"><img src="https://opencollective.com/husky/individuals.svg?width=890" height="100px"></a>
Find Husky helpful? Become a backer and show your appreciation with a monthly donation on [Open Collective](https://opencollective.com/husky). You can also tip with a one-time donation.

[![Husky Sponsor](https://opencollective.com/husky/backer/0/avatar)](https://opencollective.com/husky/backer/0/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/1/avatar)](https://opencollective.com/husky/backer/1/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/2/avatar)](https://opencollective.com/husky/backer/2/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/3/avatar)](https://opencollective.com/husky/backer/3/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/4/avatar)](https://opencollective.com/husky/backer/4/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/5/avatar)](https://opencollective.com/husky/backer/5/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/6/avatar)](https://opencollective.com/husky/backer/6/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/7/avatar)](https://opencollective.com/husky/backer/7/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/8/avatar)](https://opencollective.com/husky/backer/8/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/9/avatar)](https://opencollective.com/husky/backer/9/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/10/avatar)](https://opencollective.com/husky/backer/10/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/11/avatar)](https://opencollective.com/husky/backer/11/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/12/avatar)](https://opencollective.com/husky/backer/12/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/13/avatar)](https://opencollective.com/husky/backer/13/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/14/avatar)](https://opencollective.com/husky/backer/14/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/15/avatar)](https://opencollective.com/husky/backer/15/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/16/avatar)](https://opencollective.com/husky/backer/16/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/17/avatar)](https://opencollective.com/husky/backer/17/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/18/avatar)](https://opencollective.com/husky/backer/18/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/19/avatar)](https://opencollective.com/husky/backer/19/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/20/avatar)](https://opencollective.com/husky/backer/20/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/21/avatar)](https://opencollective.com/husky/backer/21/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/22/avatar)](https://opencollective.com/husky/backer/22/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/23/avatar)](https://opencollective.com/husky/backer/23/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/24/avatar)](https://opencollective.com/husky/backer/24/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/25/avatar)](https://opencollective.com/husky/backer/25/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/26/avatar)](https://opencollective.com/husky/backer/26/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/27/avatar)](https://opencollective.com/husky/backer/27/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/28/avatar)](https://opencollective.com/husky/backer/28/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/29/avatar)](https://opencollective.com/husky/backer/29/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/30/avatar)](https://opencollective.com/husky/backer/30/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/31/avatar)](https://opencollective.com/husky/backer/31/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/32/avatar)](https://opencollective.com/husky/backer/32/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/33/avatar)](https://opencollective.com/husky/backer/33/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/34/avatar)](https://opencollective.com/husky/backer/34/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/35/avatar)](https://opencollective.com/husky/backer/35/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/36/avatar)](https://opencollective.com/husky/backer/36/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/37/avatar)](https://opencollective.com/husky/backer/37/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/38/avatar)](https://opencollective.com/husky/backer/38/website)
[![Husky Sponsor](https://opencollective.com/husky/backer/39/avatar)](https://opencollective.com/husky/backer/39/website)

GitHub sponsors can be viewed on my [profile](https://github.com/typicode). All past and current Open Collective sponsors can be viewed on [Husky's Open Collective](https://opencollective.com/husky).

## Used by

* [webpack](https://github.com/webpack/webpack)
* [babel](https://github.com/babel/babel)
* [create-react-app](https://github.com/facebookincubator/create-react-app)
* ... and many other awesome projects
- [webpack](https://github.com/webpack/webpack)
- [babel](https://github.com/babel/babel)
- [create-react-app](https://github.com/facebook/create-react-app)
- ... and many other awesome projects

## Guides

<!-- toc -->

* [Upgrading from 0.14](#upgrading-from-014)
* [Supported hooks](#supported-hooks)
* [Access Git params and stdin](#access-git-params-and-stdin)
* [Skip all hooks (rebase)](#skip-all-hooks-rebase)
* [Disable auto-install](#disable-auto-install)
* [CI servers](#ci-servers)
* [Monorepos](#monorepos)
* [Node version managers](#node-version-managers)
* [Local commands (~/.huskyrc)](#local-commands-huskyrc)
* [Multiple commands](#multiple-commands)
* [Troubleshoot](#troubleshoot)
+ [Debug messages](#debug-messages)
+ [Hooks aren't running](#hooks-arent-running)
+ [Commits aren't blocked](#commits-arent-blocked)
+ [Commits are slow](#commits-are-slow)
+ [Testing husky in a new repo](#testing-husky-in-a-new-repo)
+ [ENOENT error 'node_modules/husky/.git/hooks'](#enoent-error-node_moduleshuskygithooks)
- [Upgrading from 0.14](#upgrading-from-014)
- [Supported hooks](#supported-hooks)
- [Access Git params and stdin](#access-git-params-and-stdin)
- [Skip all hooks (rebase)](#skip-all-hooks-rebase)
- [Disable auto-install](#disable-auto-install)
- [CI servers](#ci-servers)
- [Monorepos](#monorepos)
- [Node version managers](#node-version-managers)
- [Local commands (~/.huskyrc)](#local-commands-huskyrc)
- [Multiple commands](#multiple-commands)
- [Troubleshoot](#troubleshoot)
- [Debug messages](#debug-messages)
- [Hooks aren't running](#hooks-arent-running)
- [Commits aren't blocked](#commits-arent-blocked)
- [Commits are slow](#commits-are-slow)
- [Testing husky in a new repo](#testing-husky-in-a-new-repo)
- [ENOENT error 'node_modules/husky/.git/hooks'](#enoent-error-node_moduleshuskygithooks)

<!-- tocstop -->

@@ -149,7 +171,7 @@ You can also do it manually. Move your existing hooks to `husky.hooks` field and
}
```

Starting with `1.0.0`, husky can be configured using `.huskyrc`, `.huskyrc.json`, `.huskyrc.js` or `husky.config.js` file.
Starting with `1.0.0`, husky can be configured using `.huskyrc`, `.huskyrc.json`, `.huskyrc.yaml`, `.huskyrc.yml`, `.huskyrc.js` or `husky.config.js` file.

```js
// .huskyrc
@@ -194,7 +216,7 @@ By default, Husky won't install on CI servers.

### Monorepos

If you have a multi-package repository, it's __recommended__ to use tools like [lerna](https://github.com/lerna/lerna) and have husky installed ONLY in the root `package.json` to act as the source of truth.
If you have a multi-package repository, it's **recommended** to use tools like [lerna](https://github.com/lerna/lerna) and have husky installed ONLY in the root `package.json` to act as the source of truth.

Generally speaking, you should AVOID defining husky in multiple `package.json`, as each package would overwrite previous husky installation.

@@ -232,6 +254,7 @@ Generally speaking, you should AVOID defining husky in multiple `package.json`,
If you're on Windows, husky will simply use the version installed globally on your system.

For macOS and Linux users:

- if you're running `git` commands in the terminal, husky will use the version defined in your shell `PATH`. In other words, if you're a `nvm` user, husky will use the version that you've set with `nvm`.
- if you're using a GUI client and `nvm`, it may have a different `PATH` and not load `nvm`, in this case the highest `node` version installed by `nvm` will usually be picked. You can also check `~/.node_path` to see which version is used by GUIs and edit if you want to use something else.

@@ -248,7 +271,7 @@ export NVM_DIR="$HOME/.nvm"

### Multiple commands

By design and just like `scripts` defined in `package.json`, husky will run hook scripts as a single command.
By design and just like `scripts` defined in `package.json`, husky will run hook scripts as a single command.

```json
"pre-commit": "cmd && cmd"
@@ -257,15 +280,12 @@ By design and just like `scripts` defined in `package.json`, husky will run hook
That said, if you prefer to use an array, the recommended approach is to define them in `.huskyrc.js` or `husky.config.js`.

```js
const tasks = arr => arr.join(' && ')
const tasks = (arr) => arr.join(' && ')

module.exports = {
'hooks': {
'pre-commit': tasks([
'cmd',
'cmd'
])
}
hooks: {
'pre-commit': tasks(['cmd', 'cmd']),
},
}
```

@@ -327,9 +347,9 @@ Verify that your version of Git is `>=2.13.0`.

## See also

* [pkg-ok](https://github.com/typicode/pkg-ok) - Prevents publishing a module with bad paths or incorrect line endings
* [please-upgrade-node](https://github.com/typicode/please-upgrade-node) - Show a message to upgrade Node instead of a stacktrace in your CLIs
* [pinst](https://github.com/typicode/pinst) - dev only postinstall hook
- [pkg-ok](https://github.com/typicode/pkg-ok) - Prevents publishing a module with bad paths or incorrect line endings
- [please-upgrade-node](https://github.com/typicode/please-upgrade-node) - Show a message to upgrade Node instead of a stacktrace in your CLIs
- [pinst](https://github.com/typicode/pinst) - dev only postinstall hook

## Patreon

588 changes: 414 additions & 174 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "husky",
"version": "4.2.5",
"version": "4.3.7",
"description": "Prevents bad commit or push (git hooks, pre-commit/precommit, pre-push/prepush, post-merge/postmerge and all that stuff...)",
"bin": {
"husky-run": "./bin/run.js",
@@ -52,25 +52,26 @@
"chalk": "^4.0.0",
"ci-info": "^2.0.0",
"compare-versions": "^3.6.0",
"cosmiconfig": "^6.0.0",
"find-versions": "^3.2.0",
"cosmiconfig": "^7.0.0",
"find-versions": "^4.0.0",
"opencollective-postinstall": "^2.0.2",
"pkg-dir": "^4.2.0",
"pkg-dir": "^5.0.0",
"please-upgrade-node": "^3.2.0",
"slash": "^3.0.0",
"which-pm-runs": "^1.0.0"
},
"devDependencies": {
"@types/ci-info": "^2.0.0",
"@types/cosmiconfig": "^6.0.0",
"@types/is-ci": "^2.0.0",
"@types/jest": "^25.2.1",
"@types/mkdirp": "^1.0.0",
"@types/node": "^13.11.1",
"@typescript-eslint/eslint-plugin": "^2.27.0",
"@typescript-eslint/parser": "^2.27.0",
"cross-env": "^7.0.2",
"del": "^5.1.0",
"del-cli": "^3.0.0",
"del-cli": "^3.0.1",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.1",
"eslint-config-xo-space": "^0.24.0",
@@ -79,7 +80,7 @@
"jest": "^25.3.0",
"markdown-toc": "^1.2.0",
"mkdirp": "^1.0.4",
"pinst": "^2.0.0",
"pinst": "^2.1.1",
"pkg-ok": "^2.3.1",
"prettier": "^2.0.4",
"tempy": "^0.5.0",
4 changes: 2 additions & 2 deletions scripts/oc.js
Original file line number Diff line number Diff line change
@@ -17,8 +17,8 @@ function renderTier(tier, height) {
function render() {
return [
['Gold', 60],
['Silver', 45],
['Bronze', 30],
['Silver', 60],
['Bronze', 60],
]
.map(([tier, height]) => renderTier(tier, height))
.join('\n\n')
32 changes: 32 additions & 0 deletions scripts/test-install.sh
Original file line number Diff line number Diff line change
@@ -152,5 +152,37 @@ if [ "$exitCode" -eq 0 ]; then
exit 1
fi

# ---
test "hook should run and pass all HUSKY_GIT_PARAMS"
cat > .huskyrc << EOL
{
"skipCI": false,
"hooks": {
"prepare-commit-msg": "echo \"prepare-commit-msg hook from Husky\" && echo \$HUSKY_GIT_PARAMS > $hookParamsFile"
}
}
EOL
if [ -f $hookParamsFile ]; then
rm $hookParamsFile
fi

commit sixth

if [ ! -f $hookParamsFile ]; then
echo "Fail: hook script didn't run"
exit 1
fi

actual=$(cat $hookParamsFile)
expected=".git/COMMIT_EDITMSG message"

if [ "$actual" != "$expected" ]; then
echo "Fail: HUSKY_GIT_PARAMS weren't set correctly"
echo "$actual != $expected"
exit 1
fi

echo
echo "Success: all tests passed"


4 changes: 2 additions & 2 deletions sh/husky.sh
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ command_exists () {

run_command () {
if command_exists "$1"; then
"$@" husky-run $hookName "$gitParams"
"$@" husky-run $hookName $gitParams

exitCode="$?"
debug "$* husky-run exited with $exitCode exit code"
@@ -58,7 +58,7 @@ debug "Current working directory is $(pwd)"
# Don't skip if .huskyrc.js or .huskyrc.config.js are used as the heuristic could
# fail due to the dynamic aspect of JS. For example:
# `"pre-" + "commit"` or `require('./config/hooks')`)
if [ ! -f .huskyrc.js ] && [ ! -f husky.config.js ] && ! hookIsDefined; then
if [ ! -f .huskyrc.js ] && [ ! -f huskyrc.cjs ] && [ ! -f husky.config.js ] && [ ! -f husky.config.cjs ] && ! hookIsDefined; then
debug "$hookName config not found, skipping hook"
exit 0
fi
12 changes: 6 additions & 6 deletions src/installer/__tests__/__snapshots__/scripts.ts.snap
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ exports[`hookScript should match snapshot 1`] = `
"#!/bin/sh
# husky
# Created by Husky v4.2.5 (https://github.com/typicode/husky#readme)
# Created by Husky v4.3.7 (https://github.com/typicode/husky#readme)
# At: <locale date string>
# From: /home/typicode/projects/foo-package (https://github.com/foo/foo-package)
@@ -13,7 +13,7 @@ exports[`hookScript should match snapshot 1`] = `
`;
exports[`localScript should match snapshot 1`] = `
"# Created by Husky v4.2.5 (https://github.com/typicode/husky#readme)
"# Created by Husky v4.3.7 (https://github.com/typicode/husky#readme)
# At: <locale date string>
# From: /home/typicode/projects/foo-package (https://github.com/foo/foo-package)
@@ -23,7 +23,7 @@ cd \\".\\"
`;
exports[`mainScript should match snapshot 1`] = `
"# Created by Husky v4.2.5 (https://github.com/typicode/husky#readme)
"# Created by Husky v4.3.7 (https://github.com/typicode/husky#readme)
# At: <locale date string>
# From: /home/typicode/projects/foo-package (https://github.com/foo/foo-package)
@@ -39,7 +39,7 @@ command_exists () {
run_command () {
if command_exists \\"$1\\"; then
\\"$@\\" husky-run $hookName \\"$gitParams\\"
\\"$@\\" husky-run $hookName $gitParams
exitCode=\\"$?\\"
debug \\"$* husky-run exited with $exitCode exit code\\"
@@ -67,7 +67,7 @@ hookIsDefined () {
.huskyrc.yml
}
huskyVersion=\\"4.2.5\\"
huskyVersion=\\"4.3.7\\"
gitParams=\\"$*\\"
hookName=\\"$(basename \\"$0\\")\\"
@@ -87,7 +87,7 @@ debug \\"Current working directory is $(pwd)\\"
# Don't skip if .huskyrc.js or .huskyrc.config.js are used as the heuristic could
# fail due to the dynamic aspect of JS. For example:
# \`\\"pre-\\" + \\"commit\\"\` or \`require('./config/hooks')\`)
if [ ! -f .huskyrc.js ] && [ ! -f husky.config.js ] && ! hookIsDefined; then
if [ ! -f .huskyrc.js ] && [ ! -f huskyrc.cjs ] && [ ! -f husky.config.js ] && [ ! -f husky.config.cjs ] && ! hookIsDefined; then
debug \\"$hookName config not found, skipping hook\\"
exit 0
fi
7 changes: 6 additions & 1 deletion src/installer/bin.ts
Original file line number Diff line number Diff line change
@@ -43,7 +43,12 @@ function getInitCwdEnv(): string {
if (INIT_CWD === undefined) {
const { name, version } = whichPMRuns()
throw new Error(
`INIT_CWD is not set, please upgrade your package manager (${name} ${version})`
`INIT_CWD is not set, please check that your package manager supports it (${name} ${version})
Alternatively, you could set it manually:
INIT_CWD="$(pwd)" npm install husky --save-dev
Or upgrade to husky v5`
)
}

3 changes: 1 addition & 2 deletions src/runner/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -138,8 +138,7 @@ describe('run', (): void => {
})
)

// 'commit-msg' takes one parameter from git
const status = await index(['', '', 'commit-msg', 'git fake param'], {
const status = await index(['', '', 'commit-msg', 'git', 'fake', 'param'], {
cwd: dir,
})
expectSpawnSyncToHaveBeenCalledWith(dir, 'echo success', {
6 changes: 3 additions & 3 deletions src/runner/index.ts
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ function runCommand(
* @param {promise} options.getStdinFn - used for mocking only
*/
export default async function run(
[, , hookName = '', HUSKY_GIT_PARAMS]: string[],
[, , hookName = '', ...HUSKY_GIT_PARAMS]: string[],
{ cwd = process.cwd() }: { cwd?: string } = {}
): Promise<number> {
const oldCommand = getOldCommand(cwd, hookName)
@@ -83,8 +83,8 @@ export default async function run(
// Add HUSKY_GIT_PARAMS to env
const env: Env = {}

if (HUSKY_GIT_PARAMS) {
env.HUSKY_GIT_PARAMS = HUSKY_GIT_PARAMS
if (HUSKY_GIT_PARAMS?.length) {
env.HUSKY_GIT_PARAMS = HUSKY_GIT_PARAMS.join(' ')
}

if (command) {