Comparing version 1.1.7 to 1.1.8
@@ -56,5 +56,16 @@ var fs = require('fs'); | ||
return fs.existsSync(path); | ||
} | ||
}, | ||
/** | ||
* @param {String} path | ||
* @returns {Boolean} | ||
*/ | ||
isExecutable: function (path) { | ||
var stats = fs.lstatSync(path); | ||
return (stats.mode & 1) || | ||
(stats.mode & 8) && process.getgid && stats.gid === process.getgid() || | ||
(stats.mode & 64) && process.getuid && stats.uid === process.getuid(); | ||
} | ||
}; | ||
module.exports = helpers; |
@@ -6,3 +6,2 @@ var path = require('path'); | ||
var fsHelpers = require('./fs-helpers'); | ||
var exec = require('child_process').exec; | ||
@@ -30,15 +29,2 @@ var HOOKS_DIRNAME = 'hooks'; | ||
/** | ||
* @param {String[]} hooks List of hook's paths with possible excludes(.gitignore files) | ||
* @param {function} callback Filtered hooks will be passed in the callback | ||
*/ | ||
function excludeIgnoredPaths(hooks, callback) { | ||
exec('git check-ignore ' + hooks.join(' '), function (error, output) { | ||
// intentionally ignore errors | ||
callback(hooks.filter(function (hookName) { | ||
return output.indexOf(hookName) === -1; | ||
})); | ||
}); | ||
} | ||
module.exports = { | ||
@@ -128,8 +114,18 @@ /** | ||
var list = fs.readdirSync(hooksDirname); | ||
var hooks = list.map(function (hookName) { | ||
return path.resolve(hooksDirname, hookName); | ||
}); | ||
excludeIgnoredPaths(hooks, function (filteredHooks) { | ||
runHooks(filteredHooks, args, callback); | ||
}); | ||
var hooks = list | ||
.map(function (hookName) { | ||
return path.resolve(hooksDirname, hookName); | ||
}) | ||
.filter(function (hookPath) { | ||
var isFile = fs.lstatSync(hookPath).isFile(); | ||
var isExecutable = fs.lstatSync(hookPath).isFile() && fsHelpers.isExecutable(hookPath); | ||
if (isFile && !isExecutable) { | ||
console.warn('[GIT-HOOKS WARNING] Non-executable file ' + hookPath + ' is skipped'); | ||
} | ||
return isFile && isExecutable; | ||
}); | ||
runHooks(hooks, args, callback); | ||
} else { | ||
@@ -169,12 +165,2 @@ callback(0); | ||
/** | ||
* @param {fs.Stats} stats | ||
* @returns {Boolean} | ||
*/ | ||
function isExecutable(stats) { | ||
return (stats.mode & 1) || | ||
(stats.mode & 8) && process.getgid && stats.gid === process.getgid() || | ||
(stats.mode & 64) && process.getuid && stats.uid === process.getuid(); | ||
} | ||
/** | ||
* Spawns hook as a separate process. | ||
@@ -187,7 +173,2 @@ * | ||
function spawnHook(hookName, args) { | ||
var stats = fs.statSync(hookName); | ||
var isHookExecutable = stats && stats.isFile() && isExecutable(stats); | ||
if (!isHookExecutable) { | ||
throw new Error('Cannot execute hook: ' + hookName + '. Please check file permissions.'); | ||
} | ||
args = args || []; | ||
@@ -194,0 +175,0 @@ return spawn(hookName, args, {stdio: 'inherit'}); |
@@ -5,3 +5,3 @@ { | ||
"author": "Alexander Tarmolov <tarmolov@gmail.com>", | ||
"version": "1.1.7", | ||
"version": "1.1.8", | ||
"repository": "https://github.com/tarmolov/git-hooks-js", | ||
@@ -8,0 +8,0 @@ "contributors": [ |
@@ -54,3 +54,2 @@ # git-hooks-js | ||
* [pre-commit](https://github.com/observing/pre-commit) | ||
* [ghooks](https://github.com/gtramontina/ghooks) | ||
* [husky](https://github.com/typicode/husky) |
1
14360
293
55