Skip to content

Commit e649c6b

Browse files
authored
0.14 (#142)
0.14
1 parent 3ba3c34 commit e649c6b

16 files changed

+2519
-458
lines changed

CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# CHANGELOG
22

3-
## Unreleased
3+
## 0.14.0
44

5-
* Add Git worktree support
6-
* Drop Node 0.12 support
7-
* Don't reload nvm if it's already in PATH
5+
* Fix `npm@5` `Error: Cannot find module` warning when uninstalling
6+
* Drop `Node 0.12` support
7+
* Don't reload `nvm` if it's already in `PATH`
8+
* Add Git worktree support [#114](https://github.com/typicode/husky/pull/114)
9+
* Hide irrelevant `--no-verify` message for `prepare-commit-msg` [#137](https://github.com/typicode/husky/issues/137)
810

911
## 0.13.4
1012

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ Git params can be found in `GIT_PARAMS` environment variable.
7474

7575
### Setting a different log level
7676

77-
By default, husky will run scripts using `--silent` to make the output more readable. If you want to override this, simply pass a different log level to your scripts:
77+
By default, husky will run scripts using `--silent` to make the output more readable. If you want to override this, simply pass a different log level to your scripts:
7878

7979
```json
8080
"precommit": "npm run some-script -q"
8181
```
8282

8383
_`-q/--quiet` is equivalent to `--loglevel warn` which is npm default log level._
8484

85-
### Git submodule support
85+
### Git submodule and subtree support
8686

8787
Yes
8888

@@ -102,4 +102,4 @@ Please use `yarn` `v0.24+`
102102

103103
## License
104104

105-
MIT - [Typicode :cactus:](https://github.com/typicode)
105+
MIT - [Typicode :cactus:](https://github.com/typicode) - [Patreon](https://www.patreon.com/typicode)

__tests__/index.js

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
'use strict'
2+
3+
const fs = require('fs')
4+
const path = require('path')
5+
const mock = require('mock-fs')
6+
const installFrom = require('../src/install')
7+
const uninstallFrom = require('../src/uninstall')
8+
9+
const gitDir = '/.git'
10+
11+
function readHook(hookPath) {
12+
return fs.readFileSync(path.join(gitDir, hookPath), 'utf-8')
13+
}
14+
15+
function exists(hookPath) {
16+
return fs.existsSync(path.join(gitDir, hookPath))
17+
}
18+
19+
describe('husky', function() {
20+
afterEach(function() {
21+
mock.restore()
22+
})
23+
24+
it('should support basic layout', function() {
25+
mock({
26+
'/.git/hooks': {},
27+
'/node_modules/husky': {}
28+
})
29+
30+
installFrom('/node_modules/husky')
31+
const hook = readHook('hooks/pre-commit')
32+
33+
expect(hook).toMatch('#husky')
34+
expect(hook).toMatch('cd .')
35+
expect(hook).toMatch('npm run -s precommit')
36+
expect(hook).toMatch('--no-verify')
37+
38+
const prepareCommitMsg = readHook('hooks/prepare-commit-msg')
39+
expect(prepareCommitMsg).toMatch('cannot be bypassed')
40+
41+
uninstallFrom('/node_modules/husky')
42+
expect(exists('hooks/pre-push')).toBeFalsy()
43+
})
44+
45+
it('should support project installed in sub directory', function() {
46+
mock({
47+
'/.git/hooks': {},
48+
'/A/B/node_modules/husky': {}
49+
})
50+
51+
installFrom('/A/B/node_modules/husky')
52+
const hook = readHook('hooks/pre-commit')
53+
54+
expect(hook).toMatch('cd A/B')
55+
56+
uninstallFrom('/A/B/node_modules/husky')
57+
expect(exists('hooks/pre-push')).toBeFalsy()
58+
})
59+
60+
it('should support git submodule', function() {
61+
mock({
62+
'/.git/modules/A/B': {},
63+
'/A/B/.git': 'git: ../../.git/modules/A/B',
64+
'/A/B/node_modules/husky': {}
65+
})
66+
67+
installFrom('/A/B/node_modules/husky')
68+
const hook = readHook('modules/A/B/hooks/pre-commit')
69+
70+
expect(hook).toMatch('cd .')
71+
72+
uninstallFrom('/A/B/node_modules/husky')
73+
expect(exists('hooks/pre-push')).toBeFalsy()
74+
})
75+
76+
it('should support git submodule and sub directory', function() {
77+
mock({
78+
'/.git/modules/A/B': {},
79+
'/A/B/.git': 'git: ../../.git/modules/A/B',
80+
'/A/B/C/node_modules/husky': {}
81+
})
82+
83+
installFrom('/A/B/C/node_modules/husky')
84+
const hook = readHook('modules/A/B/hooks/pre-commit')
85+
86+
expect(hook).toMatch('cd C')
87+
88+
uninstallFrom('/A/B/app/node_modules/husky')
89+
expect(exists('hooks/pre-push')).toBeFalsy()
90+
})
91+
92+
it('should support git worktrees', function() {
93+
mock({
94+
'/.git/worktrees/B': {},
95+
'/A/B/.git': 'git: /.git/worktrees/B',
96+
'/A/B/node_modules/husky': {}
97+
})
98+
99+
installFrom('/A/B/node_modules/husky')
100+
const hook = readHook('worktrees/B/hooks/pre-commit')
101+
102+
expect(hook).toMatch('cd .')
103+
104+
uninstallFrom('/A/B/node_modules/husky')
105+
expect(exists('hooks/pre-commit')).toBeFalsy()
106+
})
107+
108+
it('should not modify user hooks', function() {
109+
mock({
110+
'/.git/hooks': {},
111+
'/.git/hooks/pre-push': 'foo',
112+
'/node_modules/husky': {}
113+
})
114+
115+
// Verify that it's not overwritten
116+
installFrom('/node_modules/husky')
117+
const hook = readHook('hooks/pre-push')
118+
expect(hook).toBe('foo')
119+
120+
uninstallFrom('/node_modules/husky')
121+
expect(exists('hooks/pre-push')).toBeTruthy()
122+
})
123+
124+
it('should not install from /node_modules/A/node_modules', function() {
125+
mock({
126+
'/.git/hooks': {},
127+
'/node_modules/A/node_modules/husky': {}
128+
})
129+
130+
installFrom('/node_modules/A/node_modules/husky')
131+
expect(exists('hooks/pre-push')).toBeFalsy()
132+
})
133+
134+
it("should not crash if there's no .git directory", function() {
135+
mock({
136+
'/node_modules/husky': {}
137+
})
138+
139+
expect(function() {
140+
installFrom('/node_modules/husky')
141+
}).not.toThrow()
142+
143+
expect(function() {
144+
uninstallFrom('/node_modules/husky')
145+
}).not.toThrow()
146+
})
147+
148+
it('should migrate ghooks scripts', function() {
149+
mock({
150+
'/.git/hooks/pre-commit':
151+
'// Generated by ghooks. Do not edit this file.',
152+
'/node_modules/husky': {}
153+
})
154+
155+
installFrom('/node_modules/husky')
156+
const hook = readHook('hooks/pre-commit')
157+
expect(hook).toMatch('husky')
158+
expect(hook).not.toMatch('ghooks')
159+
})
160+
})

appveyor.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Test against the latest version of this Node.js version
2+
environment:
3+
nodejs_version: "8"
4+
5+
# Install scripts. (runs after repo cloning)
6+
install:
7+
# Get the latest stable version of Node.js or io.js
8+
- ps: Install-Product node $env:nodejs_version
9+
# install modules
10+
- npm install
11+
12+
# Post-install test scripts.
13+
test_script:
14+
# Output useful info for debugging.
15+
- node --version
16+
- npm --version
17+
# run tests
18+
- npm test
19+
20+
# Don't actually build.
21+
build: off

bin/install.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
'use strict'
2+
13
// Run when package is installed
2-
var path = require('path')
3-
var chalk = require('chalk')
4-
var isCI = require('is-ci')
5-
var husky = require('../src/')
4+
const path = require('path')
5+
const isCI = require('is-ci')
6+
const installFrom = require('../src/install')
67

7-
console.log(chalk.cyan.underline('husky'))
8+
console.log('husky')
89

910
if (isCI) {
1011
console.log('CI detected, skipping Git hooks installation')
1112
process.exit(0)
1213
}
1314

14-
console.log('setting up hooks')
15+
console.log('setting up Git hooks')
1516

16-
var huskyDir = path.join(__dirname, '..')
17-
husky.installFrom(huskyDir)
17+
const huskyDir = path.join(__dirname, '..')
18+
installFrom(huskyDir)

bin/uninstall.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
'use strict'
2+
13
// Run when package is uninstalled
2-
var path = require('path')
3-
var chalk = require('chalk')
4-
var husky = require('../src/')
4+
const path = require('path')
5+
const uninstallFrom = require('../src/uninstall')
56

6-
console.log(chalk.cyan.underline('husky'))
7-
console.log('uninstalling')
7+
console.log('husky')
8+
console.log('uninstalling Git hooks')
89

9-
var huskyDir = path.join(__dirname, '..')
10-
husky.uninstallFrom(huskyDir)
10+
const huskyDir = path.join(__dirname, '..')
11+
uninstallFrom(huskyDir)

package.json

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"name": "husky",
3-
"version": "0.13.4",
3+
"version": "0.14.0-1",
44
"description": "Prevents bad commit or push (git hooks, pre-commit/precommit, pre-push/prepush, post-merge/postmerge and all that stuff...)",
5-
"main": "./src/index.js",
5+
"engines": {
6+
"node": ">=4"
7+
},
68
"scripts": {
7-
"test": "mocha && standard",
8-
"precommit": "npm test",
9-
"prepublish": "pkg-ok",
9+
"test": "jest",
10+
"format": "prettier --single-quote --no-semi --write **/*.js",
1011
"install": "node ./bin/install.js",
1112
"uninstall": "node ./bin/uninstall.js"
1213
},
@@ -35,22 +36,19 @@
3536
},
3637
"homepage": "https://github.com/typicode/husky",
3738
"devDependencies": {
38-
"expect": "^1.20.2",
39-
"mocha": "^3.2.0",
39+
"jest": "^20.0.4",
4040
"mock-fs": "^4.4.1",
41-
"pkg-ok": "^1.0.1",
42-
"rimraf": "^2.2.8",
43-
"standard": "^8.6.0"
41+
"prettier": "^1.4.4",
42+
"rimraf": "^2.2.8"
4443
},
4544
"dependencies": {
46-
"chalk": "^1.1.3",
47-
"find-parent-dir": "^0.3.0",
48-
"is-ci": "^1.0.9",
49-
"normalize-path": "^1.0.0"
45+
"is-ci": "^1.0.10",
46+
"normalize-path": "^1.0.0",
47+
"strip-indent": "^2.0.0"
5048
},
5149
"standard": {
5250
"env": {
53-
"mocha": true
51+
"jest": true
5452
}
5553
}
5654
}

0 commit comments

Comments
 (0)