diff --git a/src/index.js b/src/index.js index c88877d2f..0d452d3a7 100644 --- a/src/index.js +++ b/src/index.js @@ -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) { diff --git a/test/index.js b/test/index.js index 788e5b26a..4631a517a 100644 --- a/test/index.js +++ b/test/index.js @@ -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': {}