Skip to content

Commit

Permalink
/head: return object
Browse files Browse the repository at this point in the history
  • Loading branch information
wmertens committed Feb 10, 2021
1 parent 500a237 commit 170d79d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
5 changes: 3 additions & 2 deletions components/staging/staging.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion source/git-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
10 changes: 4 additions & 6 deletions test/spec.git-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down Expand Up @@ -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']);
});
});

Expand Down

0 comments on commit 170d79d

Please sign in to comment.