From 170d79d259c585bac8859600cd94db99266caa2f Mon Sep 17 00:00:00 2001 From: Wout Mertens Date: Wed, 10 Feb 2021 07:57:17 +0100 Subject: [PATCH] /head: return object --- components/staging/staging.js | 5 +++-- source/git-api.js | 5 ++++- test/spec.git-api.js | 10 ++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/components/staging/staging.js b/components/staging/staging.js index 2dc1336bf..8cef36bb0 100644 --- a/components/staging/staging.js +++ b/components/staging/staging.js @@ -134,10 +134,11 @@ class StagingViewModel { refreshContent() { return Promise.all([ + // TODO we only use the title??? this.server .getPromise('/head', { path: this.repoPath(), limit: 1 }) - .then((log) => { - if (log.length > 0) { + .then((head) => { + if (head) { const array = log[0].message.split('\n'); this.HEAD({ title: array[0], body: array.slice(2).join('\n') }); } else this.HEAD(null); diff --git a/source/git-api.js b/source/git-api.js index 981c5dff6..80c76adba 100644 --- a/source/git-api.js +++ b/source/git-api.js @@ -463,7 +463,10 @@ exports.registerApi = (env) => { ['log', '--decorate=full', '--pretty=fuller', '-z', '--parents', '--max-count=1'], req.query.path ) - .then(gitParser.parseGitLog) + .then((text) => { + const out = gitParser.parseGitLog(text); + return out[0]; + }) .catch((err) => { if (err.stderr.indexOf("fatal: bad default revision 'HEAD'") == 0) return []; else if ( diff --git a/test/spec.git-api.js b/test/spec.git-api.js index d9501807d..465674b68 100644 --- a/test/spec.git-api.js +++ b/test/spec.git-api.js @@ -106,7 +106,7 @@ describe('git-api', () => { it('head should be empty before first commit', () => { return common.get(req, '/head', { path: testDir }).then((res) => { - expect(res).to.be.a('array'); + expect(res).to.be.false(); expect(res.length).to.be(0); }); }); @@ -176,11 +176,9 @@ describe('git-api', () => { it('head should show latest commit', () => { return common.get(req, '/head', { path: testDir }).then((res) => { - expect(res).to.be.a('array'); - expect(res.length).to.be(1); - expect(res[0].message.indexOf(commitMessage)).to.be(0); - expect(res[0].authorName).to.be(gitConfig['user.name']); - expect(res[0].authorEmail).to.be(gitConfig['user.email']); + expect(res.message.indexOf(commitMessage)).to.be(0); + expect(res.authorName).to.be(gitConfig['user.name']); + expect(res.authorEmail).to.be(gitConfig['user.email']); }); });