mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-25 07:28:35 +02:00
Conflicts: src/js/git/index.js
This commit is contained in:
commit
ebfd5e84d2
10 changed files with 647 additions and 6 deletions
|
@ -41,6 +41,7 @@ function GitEngine(options) {
|
|||
this.localRepo = null;
|
||||
|
||||
this.branchCollection = options.branches;
|
||||
this.tagCollection = options.tags;
|
||||
this.commitCollection = options.collection;
|
||||
this.gitVisuals = options.gitVisuals;
|
||||
|
||||
|
@ -214,6 +215,7 @@ GitEngine.prototype.exportTree = function() {
|
|||
_.each(this.branchCollection.toJSON(), function(branch) {
|
||||
branch.target = branch.target.get('id');
|
||||
branch.visBranch = undefined;
|
||||
branch.visTag = undefined;
|
||||
|
||||
totalExport.branches[branch.id] = branch;
|
||||
});
|
||||
|
@ -235,8 +237,7 @@ GitEngine.prototype.exportTree = function() {
|
|||
}, this);
|
||||
|
||||
var HEAD = this.HEAD.toJSON();
|
||||
HEAD.visBranch = undefined;
|
||||
HEAD.lastTarget = HEAD.lastLastTarget = HEAD.visBranch = undefined;
|
||||
HEAD.lastTarget = HEAD.lastLastTarget = HEAD.visBranch = HEAD.visTag =undefined;
|
||||
HEAD.target = HEAD.target.get('id');
|
||||
totalExport.HEAD = HEAD;
|
||||
|
||||
|
@ -298,6 +299,12 @@ GitEngine.prototype.instantiateFromTree = function(tree) {
|
|||
this.branchCollection.add(branch, {silent: true});
|
||||
}, this);
|
||||
|
||||
_.each(tree.tags, function(tagJSON) {
|
||||
var tag = this.getOrMakeRecursive(tree, createdSoFar, tagJSON.id);
|
||||
|
||||
this.tagCollection.add(tag, {silent: true});
|
||||
}, this);
|
||||
|
||||
var HEAD = this.getOrMakeRecursive(tree, createdSoFar, tree.HEAD.id);
|
||||
this.HEAD = HEAD;
|
||||
|
||||
|
@ -309,8 +316,11 @@ GitEngine.prototype.instantiateFromTree = function(tree) {
|
|||
|
||||
this.gitVisuals.gitReady = false;
|
||||
this.branchCollection.each(function(branch) {
|
||||
this.gitVisuals.addBranch(branch);
|
||||
}, this);
|
||||
this.gitVisuals.addBranch(branch);
|
||||
}, this);
|
||||
this.tagCollection.each(function(tag) {
|
||||
this.gitVisuals.addTag(tag);
|
||||
}, this);
|
||||
|
||||
if (tree.originTree) {
|
||||
var treeString = JSON.stringify(tree.originTree);
|
||||
|
@ -512,6 +522,19 @@ GitEngine.prototype.getOrMakeRecursive = function(tree, createdSoFar, objID) {
|
|||
return branch;
|
||||
}
|
||||
|
||||
if (type == 'tag') {
|
||||
var tagJSON = tree.tags[objID];
|
||||
|
||||
var tag = new Tag(_.extend(
|
||||
tree.tags[objID],
|
||||
{
|
||||
target: this.getOrMakeRecursive(tree, createdSoFar, tagJSON.target)
|
||||
}
|
||||
));
|
||||
createdSoFar[objID] = tag;
|
||||
return tag;
|
||||
}
|
||||
|
||||
if (type == 'commit') {
|
||||
// for commits, we need to grab all the parents
|
||||
var commitJSON = tree.commits[objID];
|
||||
|
@ -559,6 +582,7 @@ GitEngine.prototype.reloadGraphics = function() {
|
|||
|
||||
GitEngine.prototype.removeAll = function() {
|
||||
this.branchCollection.reset();
|
||||
this.tagCollection.reset();
|
||||
this.commitCollection.reset();
|
||||
this.refs = {};
|
||||
this.HEAD = null;
|
||||
|
@ -625,6 +649,20 @@ GitEngine.prototype.validateAndMakeBranch = function(id, target) {
|
|||
return this.makeBranch(id, target);
|
||||
};
|
||||
|
||||
GitEngine.prototype.validateAndMakeTag = function(id, target) {
|
||||
id = this.validateBranchName(id);
|
||||
if (this.refs[id]) {
|
||||
throw new GitError({
|
||||
msg: intl.str(
|
||||
'bad-tag-name',
|
||||
{ tag: name }
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
this.makeTag(id, target);
|
||||
};
|
||||
|
||||
GitEngine.prototype.makeBranch = function(id, target) {
|
||||
if (this.refs[id]) {
|
||||
throw new Error('woah already have that');
|
||||
|
@ -639,10 +677,37 @@ GitEngine.prototype.makeBranch = function(id, target) {
|
|||
return branch;
|
||||
};
|
||||
|
||||
GitEngine.prototype.makeTag = function(id, target) {
|
||||
if (this.refs[id]) {
|
||||
throw new Error('woah already have that');
|
||||
}
|
||||
|
||||
var tag = new Tag({
|
||||
target: target,
|
||||
id: id
|
||||
});
|
||||
this.tagCollection.add(tag);
|
||||
this.refs[tag.get('id')] = tag;
|
||||
return tag;
|
||||
};
|
||||
|
||||
GitEngine.prototype.getHead = function() {
|
||||
return _.clone(this.HEAD);
|
||||
};
|
||||
|
||||
GitEngine.prototype.getTags = function() {
|
||||
var toReturn = [];
|
||||
this.tagCollection.each(function(tag) {
|
||||
toReturn.push({
|
||||
id: tag.get('id'),
|
||||
target: tag.get('target'),
|
||||
remote: tag.getIsRemote(),
|
||||
obj: tag
|
||||
});
|
||||
}, this);
|
||||
return toReturn;
|
||||
};
|
||||
|
||||
GitEngine.prototype.getBranches = function() {
|
||||
var toReturn = [];
|
||||
this.branchCollection.each(function(branch) {
|
||||
|
@ -693,6 +758,17 @@ GitEngine.prototype.printBranches = function(branches) {
|
|||
});
|
||||
};
|
||||
|
||||
GitEngine.prototype.printTags = function(tags) {
|
||||
var result = '';
|
||||
_.each(tags, function(tag) {
|
||||
console.log(tag);
|
||||
result += tag.id + '\n';
|
||||
});
|
||||
throw new CommandResult({
|
||||
msg: result
|
||||
});
|
||||
};
|
||||
|
||||
GitEngine.prototype.printRemotes = function(options) {
|
||||
var result = '';
|
||||
if (options.verbose) {
|
||||
|
@ -2261,12 +2337,15 @@ GitEngine.prototype.checkout = function(idOrTarget) {
|
|||
target = this.getCommitFromRef(target.get('id'));
|
||||
}
|
||||
|
||||
if (type !== 'branch' && type !== 'commit') {
|
||||
if (type !== 'branch' && type !== 'tag' && type !== 'commit') {
|
||||
throw new GitError({
|
||||
msg: intl.str('git-error-options')
|
||||
});
|
||||
}
|
||||
|
||||
if (type === 'tag') {
|
||||
target = target.get('target');
|
||||
}
|
||||
|
||||
this.HEAD.set('target', target);
|
||||
};
|
||||
|
||||
|
@ -2313,6 +2392,11 @@ GitEngine.prototype.isRemoteBranchRef = function(ref) {
|
|||
return resolved.getIsRemote();
|
||||
};
|
||||
|
||||
GitEngine.prototype.tag = function(name, ref) {
|
||||
var target = this.getCommitFromRef(ref);
|
||||
this.validateAndMakeTag(name, target);
|
||||
};
|
||||
|
||||
GitEngine.prototype.validateAndDeleteBranch = function(name) {
|
||||
// trying to delete, lets check our refs
|
||||
var target = this.resolveID(name);
|
||||
|
@ -2810,8 +2894,20 @@ var Commit = Backbone.Model.extend({
|
|||
}
|
||||
});
|
||||
|
||||
var Tag = Ref.extend({
|
||||
defaults: {
|
||||
visTag: null
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
Ref.prototype.initialize.call(this);
|
||||
this.set('type', 'tag');
|
||||
}
|
||||
});
|
||||
|
||||
exports.GitEngine = GitEngine;
|
||||
exports.Commit = Commit;
|
||||
exports.Branch = Branch;
|
||||
exports.Tag = Tag;
|
||||
exports.Ref = Ref;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue