From dae5c1037e6a0753ac5fdcaa5936466018285eeb Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Sun, 9 Oct 2016 14:57:55 -0700 Subject: [PATCH] Support cygpath for cygwin-based git executable --- package.json | 3 ++- src/index.js | 14 +++++++++++++- test/index.js | 3 ++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 7ed1fa6b9..fd71601ff 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ }, "dependencies": { "is-ci": "^1.0.9", - "normalize-path": "^1.0.0" + "normalize-path": "^1.0.0", + "which": "^1.2.11" } } diff --git a/src/index.js b/src/index.js index 583551073..c36f87004 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,7 @@ var fs = require('fs') var path = require('path') var exec = require('child_process').exec var normalize = require('normalize-path') +var which = require('which') module.exports = { isHusky: function (filename) { @@ -14,7 +15,18 @@ module.exports = { if (error) { callback(stderr, null) } else { - callback(null, stdout.trim() + '/hooks') + var hooksPath = stdout.trim() + '/hooks' + if (process.platform === 'win32' && which.sync('cygpath')) { + exec('cygpath -w ' + hooksPath, function (cygError, cygStdout, cygStdErr) { + if (cygError) { + callback(cygStdEr, null) + } else { + callback(null, cygStdout.trim()) + } + }) + } else { + callback(null, hooksPath) + } } }) }, diff --git a/test/index.js b/test/index.js index 6c254876b..53976e845 100644 --- a/test/index.js +++ b/test/index.js @@ -3,13 +3,14 @@ var fs = require('fs') var path = require('path') var rmrf = require('rimraf') var husky = require('../src/') +var normalize = require('normalize-path') // Some very basic tests... // should return git hooks path husky.hooksDir(function (err, dir) { assert.equal(err, null) - assert.equal(dir, '.git/hooks') + assert.equal(normalize(dir), '.git/hooks') }) // Reset tmp dir