From 74a0528bef18fdd4d9013012cb59db891009b400 Mon Sep 17 00:00:00 2001 From: joshaber Date: Thu, 3 Dec 2015 12:18:00 -0500 Subject: [PATCH] Added .getConfigValue --- spec/git-repository-async-spec.js | 24 ++++++++++++++++++++---- src/git-repository-async.js | 8 +++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/spec/git-repository-async-spec.js b/spec/git-repository-async-spec.js index 8d0c87bd6..f226743b2 100644 --- a/spec/git-repository-async-spec.js +++ b/spec/git-repository-async-spec.js @@ -472,9 +472,8 @@ describe('GitRepositoryAsync', () => { }) describe('.getReferences(path)', () => { - let workingDirectory beforeEach(() => { - workingDirectory = copyRepository() + const workingDirectory = copyRepository() repo = GitRepositoryAsync.open(workingDirectory) }) @@ -487,9 +486,8 @@ describe('GitRepositoryAsync', () => { }) describe('.getReferenceTarget(reference, path)', () => { - let workingDirectory beforeEach(() => { - workingDirectory = copyRepository() + const workingDirectory = copyRepository() repo = GitRepositoryAsync.open(workingDirectory) }) @@ -498,4 +496,22 @@ describe('GitRepositoryAsync', () => { expect(SHA).toBe('8a9c86f1cb1f14b8f436eb91f4b052c8802ca99e') }) }) + + describe('.getConfigValue(key, path)', () => { + beforeEach(() => { + const workingDirectory = copyRepository() + console.log(workingDirectory) + repo = GitRepositoryAsync.open(workingDirectory) + }) + + it('looks up the value for the key', async () => { + const bare = await repo.getConfigValue('core.bare') + expect(bare).toBe('false') + }) + + it("resolves to null if there's no value", async () => { + const value = await repo.getConfigValue('my.special.key') + expect(value).toBe(null) + }) + }) }) diff --git a/src/git-repository-async.js b/src/git-repository-async.js index 1fd90362d..432502d17 100644 --- a/src/git-repository-async.js +++ b/src/git-repository-async.js @@ -233,8 +233,14 @@ 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 a {Promise} which resolves to the {String} git configuration value + // specified by the key. getConfigValue (key, _path) { - throw new Error('Unimplemented') + return this._getRepo(_path) + .then(repo => repo.configSnapshot()) + .then(config => config.getStringBuf(key)) + .catch(_ => null) } // Public: Returns the origin url of the repository.