Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions lib/git-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ module.exports = {

var hookTemplate = fs.readFileSync(__dirname + '/' + HOOKS_TEMPLATE_FILE_NAME);
var pathToGitHooks = path.relative(hooksPath, __dirname);
// Fix non-POSIX (Windows) separators
pathToGitHooks = pathToGitHooks.replace(new RegExp(path.sep.replace(/\\/g, '\\$&'), 'g'), '/');
var hook = util.format(hookTemplate.toString(), pathToGitHooks);

fsHelpers.makeDir(hooksPath);
Expand Down Expand Up @@ -177,13 +179,18 @@ function spawnHook(hookName, args) {
*/
function getClosestGitPath(currentPath) {
currentPath = currentPath || __dirname;
// reaches the fs root
if (currentPath === '/') {

var dirnamePath = path.join(currentPath, '.git');

if (fsHelpers.exists(dirnamePath)) {
return dirnamePath;
}

var nextPath = path.resolve(currentPath, '..');

if (nextPath === currentPath) {
return;
}
var dirnamePath = path.join(currentPath, '.git');

return fsHelpers.exists(dirnamePath) ?
dirnamePath :
getClosestGitPath(path.resolve(currentPath, '..'));
return getClosestGitPath(nextPath);
}