Clean up init a bit

This commit is contained in:
Daniel Hengeveld
2015-10-16 19:12:08 +02:00
parent 3b15f4b259
commit dfb24ce617
2 changed files with 10 additions and 16 deletions

View File

@@ -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

View File

@@ -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 () {