From 70601772d085aa90222ff874e226335c8a6889ca Mon Sep 17 00:00:00 2001 From: joshaber Date: Thu, 3 Dec 2015 11:54:55 -0500 Subject: [PATCH] Added .getReferenceTarget --- spec/git-repository-async-spec.js | 13 +++++++++++++ src/git-repository-async.js | 9 +++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/spec/git-repository-async-spec.js b/spec/git-repository-async-spec.js index 27306d9d9..8d0c87bd6 100644 --- a/spec/git-repository-async-spec.js +++ b/spec/git-repository-async-spec.js @@ -485,4 +485,17 @@ describe('GitRepositoryAsync', () => { expect(tags.length).toBe(0) }) }) + + describe('.getReferenceTarget(reference, path)', () => { + let workingDirectory + beforeEach(() => { + workingDirectory = copyRepository() + repo = GitRepositoryAsync.open(workingDirectory) + }) + + it('returns the SHA target', async () => { + const SHA = await repo.getReferenceTarget('refs/heads/master') + expect(SHA).toBe('8a9c86f1cb1f14b8f436eb91f4b052c8802ca99e') + }) + }) }) diff --git a/src/git-repository-async.js b/src/git-repository-async.js index 0dcc5b786..1fd90362d 100644 --- a/src/git-repository-async.js +++ b/src/git-repository-async.js @@ -288,13 +288,18 @@ export default class GitRepositoryAsync { }) } - // Public: Returns the current {String} SHA for the given reference. + // Public: Get the SHA for the given reference. // // * `reference` The {String} reference to get the target of. // * `path` An optional {String} path in the repo to get the reference target // for. Only needed if the repository contains submodules. + // + // Returns a {Promise} which resolves to the current {String} SHA for the + // given reference. getReferenceTarget (reference, _path) { - throw new Error('Unimplemented') + return this._getRepo(_path) + .then(repo => repo.getReference(reference)) + .then(ref => ref.target().tostrS()) } // Reading Status