diff --git a/lib/git-hooks.js b/lib/git-hooks.js index f7f911c..37c55f1 100644 --- a/lib/git-hooks.js +++ b/lib/git-hooks.js @@ -47,9 +47,11 @@ module.exports = { throw new Error('git-hooks already installed'); } - if (fsHelpers.exists(hooksPath)) { - fs.renameSync(hooksPath, hooksOldPath); + if (!fsHelpers.exists(hooksPath)) { + // Standard hooks folder has been removed - make an empty placeholder one + fsHelpers.makeDir(hooksPath); } + fs.renameSync(hooksPath, hooksOldPath); var hookTemplate = fs.readFileSync(__dirname + '/' + HOOKS_TEMPLATE_FILE_NAME); var pathToGitHooks = __dirname; @@ -86,13 +88,11 @@ module.exports = { var hooksPath = path.resolve(gitPath, HOOKS_DIRNAME); var hooksOldPath = path.resolve(gitPath, HOOKS_OLD_DIRNAME); - if (!fsHelpers.exists(hooksPath)) { - throw new Error('git-hooks is not installed'); - } - if (fsHelpers.exists(hooksOldPath)) { fsHelpers.removeDir(hooksPath); fs.renameSync(hooksOldPath, hooksPath); + } else { + throw new Error('git-hooks is not installed'); } }, diff --git a/tests/uninstall.test.js b/tests/uninstall.test.js index f15673e..56fa421 100644 --- a/tests/uninstall.test.js +++ b/tests/uninstall.test.js @@ -1,15 +1,22 @@ require('chai').should(); +var exec = require('child_process').exec; var gitHooks = require('../lib/git-hooks'); var fsHelpers = require('../lib/fs-helpers'); -var SANDBOX_PATH = __dirname + '/tmp-sandbox/'; +var SANDBOX_PATH = '/tmp/tmp-sandbox/'; var GIT_ROOT = SANDBOX_PATH + '.git/'; var GIT_HOOKS = GIT_ROOT + 'hooks'; var GIT_HOOKS_OLD = GIT_ROOT + 'hooks.old'; describe('--uninstall', function () { - beforeEach(function () { - fsHelpers.makeDir(GIT_ROOT); + beforeEach(function (done) { + fsHelpers.makeDir(SANDBOX_PATH); + exec('git init', {cwd: SANDBOX_PATH}, function (err) { + if (err) { + throw err; + } + done(); + }); }); afterEach(function () { @@ -39,19 +46,18 @@ describe('--uninstall', function () { }); describe('when backup is absent', function () { - beforeEach(function () { - fsHelpers.makeDir(GIT_HOOKS); - }); it('should not remove hooks directory', function () { - gitHooks.uninstall(SANDBOX_PATH); + var fn = function () { + gitHooks.uninstall(SANDBOX_PATH); + }; + fn.should.throw(Error); fsHelpers.exists(GIT_HOOKS).should.be.true; }); }); describe('when backup exists', function () { beforeEach(function () { - fsHelpers.makeDir(GIT_HOOKS); fsHelpers.makeDir(GIT_HOOKS_OLD); });