mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-25 07:28:35 +02:00
Issue #144 describe support for command
This commit is contained in:
parent
cda8d322f6
commit
c3f0f48f28
2 changed files with 70 additions and 6 deletions
|
@ -2378,6 +2378,53 @@ GitEngine.prototype.tag = function(name, ref) {
|
|||
this.validateAndMakeTag(name, target);
|
||||
};
|
||||
|
||||
GitEngine.prototype.describe = function(ref) {
|
||||
var startCommit = this.getCommitFromRef(ref);
|
||||
// ok we need to BFS from start upwards until we hit a tag. but
|
||||
// first we need to get a reverse mapping from tag to commit
|
||||
var tagMap = {};
|
||||
_.each(this.tagCollection.toJSON(), function(tag) {
|
||||
tagMap[tag.target.get('id')] = tag.id;
|
||||
});
|
||||
|
||||
var pQueue = [startCommit];
|
||||
var foundTag;
|
||||
var numAway = [];
|
||||
while (pQueue.length) {
|
||||
var popped = pQueue.pop();
|
||||
var thisID = popped.get('id');
|
||||
if (tagMap[thisID]) {
|
||||
foundTag = tagMap[thisID];
|
||||
break;
|
||||
}
|
||||
// ok keep going
|
||||
numAway.push(popped.get('id'));
|
||||
|
||||
var parents = popped.get('parents');
|
||||
if (parents && parents.length) {
|
||||
pQueue = pQueue.concat(parents);
|
||||
pQueue.sort(this.dateSortFunc);
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundTag) {
|
||||
throw new GitError({
|
||||
msg: intl.todo('Fatal: no tags found upstream')
|
||||
});
|
||||
}
|
||||
|
||||
if (numAway.length === 0) {
|
||||
throw new CommandResult({
|
||||
msg: foundTag
|
||||
});
|
||||
}
|
||||
|
||||
// then join
|
||||
throw new CommandResult({
|
||||
msg: foundTag + '_' + numAway.length + '_g' + numAway.pop()
|
||||
});
|
||||
};
|
||||
|
||||
GitEngine.prototype.validateAndDeleteBranch = function(name) {
|
||||
// trying to delete, lets check our refs
|
||||
var target = this.resolveID(name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue