diff --git a/spec/git-repository-async-spec.js b/spec/git-repository-async-spec.js index ba4559225..27306d9d9 100644 --- a/spec/git-repository-async-spec.js +++ b/spec/git-repository-async-spec.js @@ -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) + }) + }) }) diff --git a/src/git-repository-async.js b/src/git-repository-async.js index 8bdb8ca22..0dcc5b786 100644 --- a/src/git-repository-async.js +++ b/src/git-repository-async.js @@ -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.