Added .getReferences

This commit is contained in:
joshaber
2015-12-03 11:44:31 -05:00
parent b60056f960
commit c1e511927b
2 changed files with 33 additions and 2 deletions

View File

@@ -470,4 +470,19 @@ describe('GitRepositoryAsync', () => {
expect(hasBranch).toBe(false)
})
})
describe('.getReferences(path)', () => {
let workingDirectory
beforeEach(() => {
workingDirectory = copyRepository()
repo = GitRepositoryAsync.open(workingDirectory)
})
it('returns the heads, remotes, and tags', async () => {
const {heads, remotes, tags} = await repo.getReferences()
expect(heads.length).toBe(1)
expect(remotes.length).toBe(0)
expect(tags.length).toBe(0)
})
})
})

View File

@@ -264,12 +264,28 @@ export default class GitRepositoryAsync {
// * `path` An optional {String} path in the repository to get this information
// for, only needed if the repository has submodules.
//
// Returns an {Object} with the following keys:
// Returns a {Promise} which resolves to an {Object} with the following keys:
// * `heads` An {Array} of head reference names.
// * `remotes` An {Array} of remote reference names.
// * `tags` An {Array} of tag reference names.
getReferences (_path) {
throw new Error('Unimplemented')
return this._getRepo(_path)
.then(repo => repo.getReferences(Git.Reference.TYPE.LISTALL))
.then(refs => {
const heads = []
const remotes = []
const tags = []
for (const ref of refs) {
if (ref.isTag()) {
tags.push(ref.name())
} else if (ref.isRemote()) {
remotes.push(ref.name())
} else if (ref.isBranch()) {
heads.push(ref.name())
}
}
return {heads, remotes, tags}
})
}
// Public: Returns the current {String} SHA for the given reference.