Skip to content

Commit 5ae3cbe

Browse files
committed
Merge pull request tarmolov#15 from cinderblock/master
Fix Windows path issues
2 parents c622106 + 480aabf commit 5ae3cbe

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

lib/git-hooks.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ module.exports = {
5252

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

5759
fsHelpers.makeDir(hooksPath);
@@ -177,13 +179,18 @@ function spawnHook(hookName, args) {
177179
*/
178180
function getClosestGitPath(currentPath) {
179181
currentPath = currentPath || __dirname;
180-
// reaches the fs root
181-
if (currentPath === '/') {
182+
183+
var dirnamePath = path.join(currentPath, '.git');
184+
185+
if (fsHelpers.exists(dirnamePath)) {
186+
return dirnamePath;
187+
}
188+
189+
var nextPath = path.resolve(currentPath, '..');
190+
191+
if (nextPath === currentPath) {
182192
return;
183193
}
184-
var dirnamePath = path.join(currentPath, '.git');
185194

186-
return fsHelpers.exists(dirnamePath) ?
187-
dirnamePath :
188-
getClosestGitPath(path.resolve(currentPath, '..'));
195+
return getClosestGitPath(nextPath);
189196
}

0 commit comments

Comments
 (0)