Skip to content

Commit

Permalink
Prevent installing from node_modules/project/node_modules/husky
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode committed Jan 11, 2017
1 parent 6de2176 commit 2f70374
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ function removeHook (dir, name) {

function installFrom (huskyDir) {
try {
var isInSubNodeModule = (huskyDir.match(/node_modules/g) || []).length > 1
if (isInSubNodeModule) {
return console.log(
'Trying to install from sub \'node_module\' directory,',
'skipping Git hooks installation'
)
}

var hooksDir = findHooksDir(huskyDir)

if (hooksDir) {
Expand Down
10 changes: 10 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ describe('husky', function () {
expect(exists('hooks/pre-push')).toBeTruthy()
})

it('should not install from /node_modules/A/node_modules', function () {
mock({
'/.git/hooks': {},
'/node_modules/A/node_modules/husky': {}
})

husky.installFrom('/node_modules/A/node_modules/husky')
expect(exists('hooks/pre-push')).toBeFalsy()
})

it('should not crash if there\'s no .git directory', function () {
mock({
'/node_modules/husky': {}
Expand Down

0 comments on commit 2f70374

Please sign in to comment.