From dfb24ce617d9178cb79bffbdf9c55a7c91cd5799 Mon Sep 17 00:00:00 2001 From: Daniel Hengeveld Date: Fri, 16 Oct 2015 19:12:08 +0200 Subject: [PATCH] Clean up init a bit --- spec/git-repository-async-spec.coffee | 4 ++-- src/git-repository-async.js | 22 ++++++++-------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/spec/git-repository-async-spec.coffee b/spec/git-repository-async-spec.coffee index 0eba6a4f4..068756a72 100644 --- a/spec/git-repository-async-spec.coffee +++ b/spec/git-repository-async-spec.coffee @@ -34,8 +34,8 @@ fdescribe "GitRepositoryAsync", -> it "repo is null when no repository is found", -> repo = GitRepositoryAsync.open(path.join(temp.dir, 'nogit.txt')) - waitsFor -> - repo._opening is false + waitsForPromise {shouldReject: true}, -> + repo.repoPromise runs -> expect(repo.repo).toBe null diff --git a/src/git-repository-async.js b/src/git-repository-async.js index aec474f45..f3916eb19 100644 --- a/src/git-repository-async.js +++ b/src/git-repository-async.js @@ -3,26 +3,20 @@ const Git = require('nodegit') const path = require('path') +// GitUtils is temporarily used for ::relativize only, because I don't want +// to port it just yet. TODO: remove +const GitUtils = require('git-utils') + module.exports = class GitRepositoryAsync { static open (path) { // QUESTION: Should this wrap Git.Repository and reject with a nicer message? - return new GitRepositoryAsync(Git.Repository.open(path)) + return new GitRepositoryAsync(path) } - constructor (openPromise) { + constructor (path) { this.repo = null - // this could be replaced with a function - this._opening = true - - // Do I use this outside of tests? - openPromise.then((repo) => { - this.repo = repo - this._opening = false - }).catch((e) => { - this._opening = false - }) - - this.repoPromise = openPromise + this._gitUtilsRepo = GitUtils.open(path) // TODO remove after porting ::relativize + this.repoPromise = Git.Repository.open(path) } getPath () {