Git Tag: Initial support for tagging

Branching in git even more useful if using tags. Simulate relase branches,
maintenance branches and so on is therefore really useful in this tool.

Now, rudimentary tagging is implemented, where tags can be attached to the
commits, and referenced by for exmapmle git checkout

Signed-off-by: Max Sikström <msikstrom@op5.com>
This commit is contained in:
Max Sikström 2013-10-08 18:41:00 +02:00
parent fa7b918be9
commit 74342e2028
13 changed files with 2009 additions and 29 deletions

View file

@ -35,6 +35,7 @@ function GitEngine(options) {
this.localRepo = null;
this.branchCollection = options.branches;
this.tagCollection = options.tags;
this.commitCollection = options.collection;
this.gitVisuals = options.gitVisuals;
@ -207,6 +208,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;
});
@ -228,8 +230,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;
@ -291,6 +292,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;
@ -302,8 +309,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);
@ -438,6 +448,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];
@ -485,6 +508,7 @@ GitEngine.prototype.reloadGraphics = function() {
GitEngine.prototype.removeAll = function() {
this.branchCollection.reset();
this.tagCollection.reset();
this.commitCollection.reset();
this.refs = {};
this.HEAD = null;
@ -551,6 +575,20 @@ GitEngine.prototype.validateAndMakeBranch = function(id, target) {
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');
@ -565,10 +603,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) {
@ -619,6 +684,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) {
@ -2063,12 +2139,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);
};
@ -2102,6 +2181,11 @@ GitEngine.prototype.branch = function(name, ref) {
this.validateAndMakeBranch(name, target);
};
GitEngine.prototype.tag = function(name, ref) {
var target = this.getCommitFromRef(ref);
this.validateAndMakeTag(name, target);
};
GitEngine.prototype.deleteBranch = function(name) {
// trying to delete, lets check our refs
var target = this.resolveID(name);
@ -2603,8 +2687,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;