mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-27 00:18:56 +02:00
almost can do tests
This commit is contained in:
parent
565142048c
commit
ddf399e099
10 changed files with 288 additions and 163 deletions
|
@ -1,23 +1,24 @@
|
|||
var _;
|
||||
var _ = require('underscore');
|
||||
var Backbone;
|
||||
// horrible hack to get localStorage Backbone plugin
|
||||
if (!require('../util').isBrowser()) {
|
||||
_ = require('underscore');
|
||||
Backbone = require('backbone');
|
||||
} else {
|
||||
Backbone = window.Backbone;
|
||||
_ = window._;
|
||||
}
|
||||
|
||||
var GitEngine = require('../git').GitEngine;
|
||||
var AnimationFactory = require('../visuals/animation/animationFactory').AnimationFactory;
|
||||
var GitVisuals = require('../visuals').GitVisuals;
|
||||
var TreeCompare = require('../git/treeCompare').TreeCompare;
|
||||
|
||||
var Collections = require('../models/collections');
|
||||
var CommitCollection = Collections.CommitCollection;
|
||||
var BranchCollection = Collections.BranchCollection;
|
||||
var Command = require('../models/commandModel').Command;
|
||||
|
||||
var mock = require('../util/mock').mock;
|
||||
var util = require('../util');
|
||||
|
||||
var HeadlessGit = function() {
|
||||
this.init();
|
||||
|
@ -26,6 +27,7 @@ var HeadlessGit = function() {
|
|||
HeadlessGit.prototype.init = function() {
|
||||
this.commitCollection = new CommitCollection();
|
||||
this.branchCollection = new BranchCollection();
|
||||
this.treeCompare = new TreeCompare();
|
||||
|
||||
// here we mock visuals and animation factory so the git engine
|
||||
// is headless
|
||||
|
@ -42,5 +44,16 @@ HeadlessGit.prototype.init = function() {
|
|||
this.gitEngine.init();
|
||||
};
|
||||
|
||||
HeadlessGit.prototype.sendCommand = function(value) {
|
||||
util.splitTextCommand(value, function(commandStr) {
|
||||
var commandObj = new Command({
|
||||
rawStr: commandStr
|
||||
});
|
||||
console.log('dispatching command', value);
|
||||
var done = function() {};
|
||||
this.gitEngine.dispatch(commandObj, done);
|
||||
}, this);
|
||||
};
|
||||
|
||||
exports.HeadlessGit = HeadlessGit;
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ if (!require('../util').isBrowser()) {
|
|||
|
||||
var AnimationFactoryModule = require('../visuals/animation/animationFactory');
|
||||
var AnimationQueue = require('../visuals/animation').AnimationQueue;
|
||||
var TreeCompare = require('./treeCompare').TreeCompare;
|
||||
|
||||
var Errors = require('../util/errors');
|
||||
var GitError = Errors.GitError;
|
||||
|
@ -107,8 +108,15 @@ GitEngine.prototype.exportTree = function() {
|
|||
return totalExport;
|
||||
};
|
||||
|
||||
GitEngine.prototype.printTree = function() {
|
||||
var str = escape(JSON.stringify(this.exportTree()));
|
||||
GitEngine.prototype.printTree = function(tree) {
|
||||
tree = tree || this.exportTree();
|
||||
TreeCompare.prototype.stripTreeFields([tree]);
|
||||
|
||||
var str = JSON.stringify(tree);
|
||||
if (/'/.test(str)) {
|
||||
// escape it to make it more copy paste friendly
|
||||
str = escape(str);
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
var _ = require('underscore');
|
||||
|
||||
// static class...
|
||||
function TreeCompare() {
|
||||
|
||||
|
@ -80,7 +82,10 @@ TreeCompare.prototype.compareTrees = function(treeA, treeB) {
|
|||
// like createTime, message, author
|
||||
this.stripTreeFields([treeA, treeB]);
|
||||
|
||||
console.log('comparing tree A', treeA, 'to', treeB);
|
||||
|
||||
return _.isEqual(treeA, treeB);
|
||||
};
|
||||
|
||||
exports.TreeCompare = TreeCompare;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue