Added .hasBranch

This commit is contained in:
joshaber
2015-12-03 11:29:34 -05:00
parent 9bb8703978
commit 46d6e3b3c4
2 changed files with 25 additions and 4 deletions

View File

@@ -453,4 +453,21 @@ describe('GitRepositoryAsync', () => {
expect(deleted).toBe(0)
})
})
describe('.hasBranch(branch)', () => {
beforeEach(() => {
const workingDirectory = copyRepository()
repo = GitRepositoryAsync.open(workingDirectory)
})
it('resolves true when the branch exists', async () => {
const hasBranch = await repo.hasBranch('master')
expect(hasBranch).toBe(true)
})
it("resolves false when the branch doesn't exist", async () => {
const hasBranch = await repo.hasBranch('trolleybus')
expect(hasBranch).toBe(false)
})
})
})

View File

@@ -96,7 +96,7 @@ export default class GitRepositoryAsync {
// Public: Returns a {Promise} which resolves to the {String} working
// directory path of the repository.
getWorkingDirectory () {
throw new Error('Unimplemented')
return this.repoPromise.then(repo => repo.workdir())
}
// Public: Returns a {Promise} that resolves to true if at the root, false if
@@ -104,7 +104,7 @@ export default class GitRepositoryAsync {
isProjectAtRoot () {
if (!this.projectAtRoot && this.project) {
this.projectAtRoot = Promise.resolve(() => {
return this.repoPromise.then(repo => this.project.relativize(repo.workdir))
return this.repoPromise.then(repo => this.project.relativize(repo.workdir()))
})
}
@@ -154,9 +154,13 @@ export default class GitRepositoryAsync {
return _path
}
// Public: Returns true if the given branch exists.
// Public: Returns a {Promise} which resolves to whether the given branch
// exists.
hasBranch (branch) {
throw new Error('Unimplemented')
return this.repoPromise
.then(repo => repo.getBranch(branch))
.then(branch => branch != null)
.catch(_ => false)
}
// Public: Retrieves a shortened version of the HEAD reference value.