From df949d3a3dcf3f446380d3ac437dc2d5173c360f Mon Sep 17 00:00:00 2001 From: Daniel Hengeveld Date: Fri, 16 Oct 2015 19:24:34 +0200 Subject: [PATCH] more ::checkoutHead specs --- spec/git-repository-async-spec.coffee | 49 ++++++++++++++++----------- src/git-repository-async.js | 4 +-- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/spec/git-repository-async-spec.coffee b/spec/git-repository-async-spec.coffee index 068756a72..7de2a0b01 100644 --- a/spec/git-repository-async-spec.coffee +++ b/spec/git-repository-async-spec.coffee @@ -113,15 +113,6 @@ fdescribe "GitRepositoryAsync", -> runs -> expect(onSuccess.mostRecentCall.args[0]).toBeTruthy() - - it "resolves true if the path is deleted", -> - fs.removeSync(filePath) - onSuccess = jasmine.createSpy('onSuccess') - waitsForPromise -> - repo.isPathModified(filePath).then(onSuccess) - runs -> - expect(onSuccess.mostRecentCall.args[0]).toBeTruthy() - it "resolves false if the path is new", -> onSuccess = jasmine.createSpy('onSuccess') waitsForPromise -> @@ -162,27 +153,47 @@ fdescribe "GitRepositoryAsync", -> expect(onSuccess.mostRecentCall.args[0]).toBeFalsy() - xdescribe ".checkoutHead(path)", -> + describe ".checkoutHead(path)", -> [filePath] = [] beforeEach -> workingDirPath = copyRepository() - repo = new GitRepository(workingDirPath) + repo = GitRepositoryAsync.open(workingDirPath) filePath = path.join(workingDirPath, 'a.txt') it "no longer reports a path as modified after checkout", -> - expect(repo.isPathModified(filePath)).toBeFalsy() - fs.writeFileSync(filePath, 'ch ch changes') - expect(repo.isPathModified(filePath)).toBeTruthy() - expect(repo.checkoutHead(filePath)).toBeTruthy() - expect(repo.isPathModified(filePath)).toBeFalsy() + onSuccess = jasmine.createSpy('onSuccess') + waitsForPromise -> + repo.isPathModified(filePath).then(onSuccess) + runs -> + expect(onSuccess.mostRecentCall.args[0]).toBeFalsy() + fs.writeFileSync(filePath, 'ch ch changes') + + onSuccess = jasmine.createSpy('onSuccess') + waitsForPromise -> + repo.isPathModified(filePath).then(onSuccess) + runs -> + expect(onSuccess.mostRecentCall.args[0]).toBeTruthy() + + # Don't need to assert that this succeded because waitsForPromise will + # fail if it was rejected. + waitsForPromise -> + repo.checkoutHead(filePath) + + onSuccess = jasmine.createSpy('onSuccess') + waitsForPromise -> + repo.isPathModified(filePath).then(onSuccess) + runs -> + expect(onSuccess.mostRecentCall.args[0]).toBeFalsy() it "restores the contents of the path to the original text", -> fs.writeFileSync(filePath, 'ch ch changes') - expect(repo.checkoutHead(filePath)).toBeTruthy() - expect(fs.readFileSync(filePath, 'utf8')).toBe '' + waitsForPromise -> + repo.checkoutHead(filePath) + runs -> + expect(fs.readFileSync(filePath, 'utf8')).toBe '' - it "fires a status-changed event if the checkout completes successfully", -> + xit "fires a status-changed event if the checkout completes successfully", -> fs.writeFileSync(filePath, 'ch ch changes') repo.getPathStatus(filePath) statusHandler = jasmine.createSpy('statusHandler') diff --git a/src/git-repository-async.js b/src/git-repository-async.js index f3916eb19..7d7aab570 100644 --- a/src/git-repository-async.js +++ b/src/git-repository-async.js @@ -63,9 +63,9 @@ module.exports = class GitRepositoryAsync { } checkoutHead (_path) { - return this.repoPromise.then(function (repo) { + return this.repoPromise.then((repo) => { var checkoutOptions = new Git.CheckoutOptions() - checkoutOptions.paths = [_path] + checkoutOptions.paths = [this._gitUtilsRepo.relativize(_path)] checkoutOptions.checkoutStrategy = Git.Checkout.STRATEGY.FORCE | Git.Checkout.STRATEGY.DISABLE_PATHSPEC_MATCH Git.Checkout.head(repo, checkoutOptions) })