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: v9.1.0
Choose a base ref
...
head repository: typicode/husky
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2968998755465f69069f297b5bb603e26d6b1772
Choose a head ref
  • 11 commits
  • 14 files changed
  • 3 contributors

Commits on Jun 12, 2024

  1. Get the path from dirname instead of using Bash variable operators

    On Windows, under certain circumstances, the path separator is "\".
    
    This change will ensure compatibility with both Linux and Windows path separators
    Carlos Cerrillo committed Jun 12, 2024
    Copy the full SHA
    c65ec43 View commit details

Commits on Jul 18, 2024

  1. Small typo fix (#1471)

    philipbelesky authored Jul 18, 2024
    Copy the full SHA
    71e5dcb View commit details
  2. Copy the full SHA
    b9f5889 View commit details
  3. v9.1.0 (#1467)

    typicode committed Jul 18, 2024
    Copy the full SHA
    9085a9d View commit details
  4. 9.1.0

    typicode committed Jul 18, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a24ccbc View commit details
  5. Small typo fix (#1471)

    philipbelesky authored and typicode committed Jul 18, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e8badd7 View commit details
  6. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    eb54845 View commit details
  7. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    bbfe8e3 View commit details
  8. update vitepress

    typicode committed Jul 18, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a25c6ce View commit details
  9. docs

    typicode committed Jul 18, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    902749b View commit details
  10. 9.1.1

    typicode committed Jul 18, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2968998 View commit details
Showing with 1,905 additions and 705 deletions.
  1. +2 −2 docs/get-started.md
  2. +1 −3 docs/index.md
  3. +1,727 −559 docs/package-lock.json
  4. +134 −132 docs/sponsorkit/sponsors.svg
  5. +14 −4 index.js
  6. +2 −2 package-lock.json
  7. +1 −1 package.json
  8. +1 −0 test.sh
  9. 0 test/10_init.sh
  10. +21 −0 test/12_rm_deprecated.sh
  11. +1 −1 test/1_default.sh
  12. +1 −1 test/6_command_not_found.sh
  13. 0 test/8_set_u.sh
  14. 0 test/9_husky_0.sh
4 changes: 2 additions & 2 deletions docs/get-started.md
Original file line number Diff line number Diff line change
@@ -73,8 +73,8 @@ prettier $(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g') -
git update-index --again
```

_This is a basic but workinkg example, check [lint-staged](https://github.com/lint-staged/lint-staged) if you need more._
_This is a basic but working example, check [lint-staged](https://github.com/lint-staged/lint-staged) if you need more._

### Disabling hooks

Husky doesn't force Git hooks. It can be globally disabled (`HUSKY=0`) or be opt-in if wanted. See the [How To](how-to) section for manual setup and more information.
Husky doesn't force Git hooks. It can be globally disabled (`HUSKY=0`) or be opt-in if wanted. See the [How To](how-to) section for manual setup and more information.
4 changes: 1 addition & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
![npm](https://img.shields.io/npm/dm/husky)

> Modern native git hooks made easy
> Ultra-fast modern native git hooks
Husky enhances your commits and more 🐶 _woof!_

Automatically **lint your commit messages**, **code**, and **run tests** upon committing or pushing.

Get started [here](/get-started.md).

[Check out the v9 changelog](https://github.com/typicode/husky/releases/tag/v9.0.1) to discover all the new and improved features! 🚀

## Features

- Just `2 kB` (📦 _gzipped_) with no dependencies
2,286 changes: 1,727 additions & 559 deletions docs/package-lock.json

Large diffs are not rendered by default.

266 changes: 134 additions & 132 deletions docs/sponsorkit/sponsors.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 14 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import c from 'child_process'
import f, { writeFileSync as w } from 'fs'
import f, { readdir, writeFileSync as w } from 'fs'
import p from 'path'

let l = [ 'pre-commit', 'prepare-commit-msg', 'commit-msg', 'post-commit', 'applypatch-msg', 'pre-applypatch', 'post-applypatch', 'pre-rebase', 'post-rewrite', 'post-checkout', 'post-merge', 'pre-push', 'pre-auto-gc' ]
let l = [ 'pre-commit', 'prepare-commit-msg', 'commit-msg', 'post-commit', 'applypatch-msg', 'pre-applypatch', 'post-applypatch', 'pre-rebase', 'post-rewrite', 'post-checkout', 'post-merge', 'pre-push', 'pre-auto-gc' ],
re = /^(#!\/usr\/bin\/env sh|\. "\$\(dirname -- "\$0"\)\/_\/husky\.sh")\r?\n/gm

export default (d = '.husky') => {
if (process.env.HUSKY === '0') return 'HUSKY=0 skip install'
@@ -14,10 +15,19 @@ export default (d = '.husky') => {
if (s == null) return 'git command not found'
if (s) return '' + e

f.rmSync(_('husky.sh'), { force: true })
l.forEach(h => {
let hp = p.join(d, h)
if (!f.existsSync(hp)) return
let prev = f.readFileSync(hp, 'utf8')
let next = prev.replace(re, '')
if (prev !== next) console.log(`husky - removed deprecated code from ${hp}`)
f.writeFileSync(hp, next)
})

f.mkdirSync(_(), { recursive: true })
w(_('.gitignore'), '*')
f.copyFileSync(new URL('husky', import.meta.url), _('h'))
l.forEach(h => w(_(h), `#!/usr/bin/env sh\n. "\${0%/*}/h"`, { mode: 0o755 }))
w(_('husky.sh'), 'echo "husky - `#!/usr/bin/env sh` and `. "$(dirname -- "$0")/_/husky.sh"` lines in hooks are DEPRECATED and won\'t be supported in v10. You can remove these two lines for even simpler scripts"')
l.forEach(h => w(_(h), `#!/usr/bin/env sh\n. "\$(dirname "\$0")/h"`, { mode: 0o755 }))
return ''
}
4 changes: 2 additions & 2 deletions package-lock.json
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "husky",
"version": "9.1.0",
"version": "9.1.1",
"type": "module",
"description": "Modern native Git hooks",
"keywords": [
1 change: 1 addition & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -13,3 +13,4 @@ sh test/8_set_u.sh
sh test/9_husky_0.sh
sh test/10_init.sh
sh test/11_time.sh
sh test/12_rm_deprecated.sh
Empty file modified test/10_init.sh
100644 → 100755
Empty file.
21 changes: 21 additions & 0 deletions test/12_rm_deprecated.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
. test/functions.sh
setup
install

npx --no-install husky

cat > .husky/pre-commit <<'EOL'
# foo
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
# bar
EOL

cat > expected <<'EOL'
# foo
# bar
EOL

npx --no-install husky
expect 0 "diff .husky/pre-commit expected"
2 changes: 1 addition & 1 deletion test/1_default.sh
Original file line number Diff line number Diff line change
@@ -10,5 +10,5 @@ expect_hooksPath_to_be ".husky/_"

# Test pre-commit
git add package.json
echo "echo \"pre-commit\" && exit 1" >.husky/pre-commit
echo "echo \"pre-commit\" && exit 1" > .husky/pre-commit
expect 1 "git commit -m foo"
2 changes: 1 addition & 1 deletion test/6_command_not_found.sh
Original file line number Diff line number Diff line change
@@ -10,5 +10,5 @@ expect_hooksPath_to_be ".husky/_"

# Test pre-commit with 127 exit code
git add package.json
echo "exit 127" >.husky/pre-commit
echo "exit 127" > .husky/pre-commit
expect 1 "git commit -m foo"
Empty file modified test/8_set_u.sh
100644 → 100755
Empty file.
Empty file modified test/9_husky_0.sh
100644 → 100755
Empty file.