From 9e3497317c7232623ea066d02d29c44c636a133f Mon Sep 17 00:00:00 2001 From: Cameron Tacklind Date: Sun, 21 Feb 2016 01:04:01 -0800 Subject: [PATCH 1/7] Don't loop forever on Windows if .git folder is missing --- lib/git-hooks.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/git-hooks.js b/lib/git-hooks.js index afd6dc0..9a4c933 100644 --- a/lib/git-hooks.js +++ b/lib/git-hooks.js @@ -177,13 +177,18 @@ function spawnHook(hookName, args) { */ function getClosestGitPath(currentPath) { currentPath = currentPath || __dirname; - // reaches the fs root - if (currentPath === '/') { - return; - } + var dirnamePath = path.join(currentPath, '.git'); - return fsHelpers.exists(dirnamePath) ? - dirnamePath : - getClosestGitPath(path.resolve(currentPath, '..')); + if (fsHelpers.exists(dirnamePath)) { + return dirnamePath; + } + + var nextPath = path.resolve(currentPath, '..'); + + if (nextPath === currentPath) { + return; + } + + return getClosestGitPath(nextPath); } From 150ea5211ccf0d47d61bec6b2ca3c6ea2b63a1b1 Mon Sep 17 00:00:00 2001 From: Cameron Tacklind Date: Sun, 21 Feb 2016 01:20:10 -0800 Subject: [PATCH 2/7] Fix non-POSIX (Windows) separators --- lib/git-hooks.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/git-hooks.js b/lib/git-hooks.js index 9a4c933..dc591c6 100644 --- a/lib/git-hooks.js +++ b/lib/git-hooks.js @@ -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); From f56a4beeca922ee4a90e2502d3812028d3ca1e28 Mon Sep 17 00:00:00 2001 From: Cameron Tacklind Date: Sun, 21 Feb 2016 01:58:10 -0800 Subject: [PATCH 3/7] git-hooks is a registered npm module. No need to use the full path. --- lib/git-hooks.js | 5 +---- lib/hook-template.js | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/git-hooks.js b/lib/git-hooks.js index dc591c6..5568560 100644 --- a/lib/git-hooks.js +++ b/lib/git-hooks.js @@ -51,10 +51,7 @@ 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); + var hook = hookTemplate.toString(); fsHelpers.makeDir(hooksPath); HOOKS.forEach(function (hookName) { diff --git a/lib/hook-template.js b/lib/hook-template.js index 3b852df..7c1d52b 100644 --- a/lib/hook-template.js +++ b/lib/hook-template.js @@ -1,7 +1,7 @@ #!/usr/bin/env node try { - require('%s/git-hooks').run(__filename, process.argv[2], function (code) { + require('git-hooks').run(__filename, process.argv[2], function (code) { process.exit(code); }); } catch (e) { From f0aa2675f10df35d025975909b8451f9df1f65e8 Mon Sep 17 00:00:00 2001 From: Cameron Tacklind Date: Sun, 21 Feb 2016 02:04:10 -0800 Subject: [PATCH 4/7] Fix indentation --- lib/git-hooks.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/git-hooks.js b/lib/git-hooks.js index 5568560..8fc353f 100644 --- a/lib/git-hooks.js +++ b/lib/git-hooks.js @@ -180,13 +180,13 @@ function getClosestGitPath(currentPath) { var dirnamePath = path.join(currentPath, '.git'); if (fsHelpers.exists(dirnamePath)) { - return dirnamePath; + return dirnamePath; } var nextPath = path.resolve(currentPath, '..'); if (nextPath === currentPath) { - return; + return; } return getClosestGitPath(nextPath); From 6bec3421faa6b08cf8a767c6e920128e61dc76a9 Mon Sep 17 00:00:00 2001 From: Cameron Tacklind Date: Sun, 21 Feb 2016 02:05:45 -0800 Subject: [PATCH 5/7] remove un-used util --- lib/git-hooks.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/git-hooks.js b/lib/git-hooks.js index 8fc353f..a2b6f3e 100644 --- a/lib/git-hooks.js +++ b/lib/git-hooks.js @@ -1,5 +1,4 @@ var path = require('path'); -var util = require('util'); var spawn = require('child_process').spawn; var fs = require('fs'); var fsHelpers = require('./fs-helpers'); From b1040ee7cfef0fdd89ce87d19a3480f24abd1032 Mon Sep 17 00:00:00 2001 From: Cameron Tacklind Date: Sun, 21 Feb 2016 20:32:27 -0800 Subject: [PATCH 6/7] Revert "git-hooks is a registered npm module. No need to use the full path." This reverts commit f56a4beeca922ee4a90e2502d3812028d3ca1e28. --- lib/git-hooks.js | 5 ++++- lib/hook-template.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/git-hooks.js b/lib/git-hooks.js index a2b6f3e..2d518f7 100644 --- a/lib/git-hooks.js +++ b/lib/git-hooks.js @@ -50,7 +50,10 @@ module.exports = { } var hookTemplate = fs.readFileSync(__dirname + '/' + HOOKS_TEMPLATE_FILE_NAME); - var hook = hookTemplate.toString(); + 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); HOOKS.forEach(function (hookName) { diff --git a/lib/hook-template.js b/lib/hook-template.js index 7c1d52b..3b852df 100644 --- a/lib/hook-template.js +++ b/lib/hook-template.js @@ -1,7 +1,7 @@ #!/usr/bin/env node try { - require('git-hooks').run(__filename, process.argv[2], function (code) { + require('%s/git-hooks').run(__filename, process.argv[2], function (code) { process.exit(code); }); } catch (e) { From 480aabf0a0e7a8c6ef550f999a430b07c83d9f8f Mon Sep 17 00:00:00 2001 From: Cameron Tacklind Date: Sun, 21 Feb 2016 20:33:13 -0800 Subject: [PATCH 7/7] Revert "remove un-used util" This reverts commit 6bec3421faa6b08cf8a767c6e920128e61dc76a9. --- lib/git-hooks.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/git-hooks.js b/lib/git-hooks.js index 2d518f7..b0e377a 100644 --- a/lib/git-hooks.js +++ b/lib/git-hooks.js @@ -1,4 +1,5 @@ var path = require('path'); +var util = require('util'); var spawn = require('child_process').spawn; var fs = require('fs'); var fsHelpers = require('./fs-helpers');