From e24efdba551eb200387078061909c44200aea95b Mon Sep 17 00:00:00 2001 From: Jared Cugno Date: Mon, 3 Dec 2012 14:57:43 -0800 Subject: [PATCH] Added the ability for submodules to also get the pre commit hooks --- install.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/install.js b/install.js index 6d55bb8..019fa8c 100644 --- a/install.js +++ b/install.js @@ -4,17 +4,28 @@ var fs = require('fs'), var existsSync = fs.existsSync || path.existsSync; var projectPath = path.resolve(__dirname, '../../'), + projectName = path.basename(projectPath), filePath = path.join(__dirname, 'files'), pcPath = path.join(projectPath, '.git', 'hooks', 'pre-commit'), jsiPath = path.join(projectPath, '.jshintignore'), - jsrcPath = path.join(projectPath, '.jshintrc'); + jsrcPath = path.join(projectPath, '.jshintrc'), + pcModulePath = path.join(projectPath, '../', '.git', 'modules', projectName, 'hooks'); -if (existsSync(path.join(projectPath, '.git'))) { +var stats = fs.lstatSync(path.join(projectPath, '.git')); + +if (stats.isDirectory() && existsSync(path.join(projectPath, '.git'))) { if (existsSync(pcPath)) fs.unlinkSync(pcPath); console.log('Found .git directory, adding pre-commit hook'); var pcHook = fs.readFileSync(path.join(filePath, 'pre-commit')); fs.writeFileSync(pcPath, pcHook); fs.chmodSync(pcPath, '755'); +} else if (existsSync(pcModulePath)){ + + console.log('Found submodule .git directory, adding pre-commit hook'); + var pcHook = fs.readFileSync(path.join(filePath, 'pre-commit')); + var pcModuleFullPath = path.join(pcModulePath, 'pre-commit'); + fs.writeFileSync(pcModuleFullPath, pcHook); + fs.chmodSync(pcModuleFullPath, '755'); } if (!existsSync(jsiPath)) {