mirror of
https://github.com/hanzoai/husky.git
synced 2026-09-24 16:59:45 +00:00
automatically rm deprecated code
This commit is contained in:
+134
-132
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 532 KiB After Width: | Height: | Size: 533 KiB |
@@ -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,6 +15,16 @@ 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'))
|
||||
|
||||
@@ -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
|
||||
Regular → Executable
Executable
+21
@@ -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"
|
||||
+1
-1
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
Regular → Executable
Regular → Executable
Reference in New Issue
Block a user