WIP - pretty print commit on console

This commit is contained in:
Raghu Rajagopalan 2016-03-27 23:02:31 +05:30
parent d3caa9b97d
commit 8befe916fb
3 changed files with 14 additions and 0 deletions

View File

@ -42,6 +42,7 @@
"dagre": "^0.7.4",
"dagre-d3": "0.4.10",
"he": "^0.5.0",
"lodash": "^4.6.1",
"minimist": "^1.1.0",
"mkdirp": "^0.5.0",
"moment": "^2.9.0",

View File

@ -1,6 +1,7 @@
var crypto = require("crypto");
var Logger = require('../../logger');
var log = new Logger.Log();
var _ = require("lodash");
//var log = new Logger.Log(1);
@ -42,9 +43,11 @@ function isReachableFrom(currentCommit, otherCommit) {
if (currentSeq > otherSeq) return isfastforwardable(otherCommit, currentCommit);
return false;
}
exports.setDirection = function(dir) {
direction = dir;
}
exports.commit = function(msg) {
var commit = { id: getId(),
message: msg,
@ -101,6 +104,14 @@ exports.reset = function(ref) {
branches[curBranch] = commit.id;
}
exports.prettyPrint = function() {
var commitArr = Object.keys(commits).map(function (key) {
return commits[key];
});
var sortedCommits = _.orderBy(commitArr, ['seq'], ['desc']);
console.log(sortedCommits);
}
exports.clear = function () {
commits = {};
head = null;

View File

@ -176,5 +176,7 @@ describe('when parsing a gitGraph',function() {
expect(parser.yy.getCurrentBranch()).toBe("newbranch");
expect(parser.yy.getBranches()["newbranch"]).toEqual(parser.yy.getBranches()["master"]);
expect(parser.yy.getHead().id).toEqual(parser.yy.getBranches()["master"]);
parser.yy.prettyPrint();
});
});