mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-25 15:38:33 +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
|
@ -733,12 +733,30 @@ var commandConfig = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
describe: {
|
||||||
|
regex: /^git +describe($|\s)/,
|
||||||
|
execute: function(engine, command) {
|
||||||
|
// first if there are no tags, we cant do anything so just throw
|
||||||
|
if (engine.tagCollection.toArray().length === 0) {
|
||||||
|
throw new GitError({
|
||||||
|
msg: intl.todo(
|
||||||
|
'fatal: No tags found, cannot describe anything.'
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var generalArgs = command.getGeneralArgs();
|
||||||
|
command.oneArgImpliedHead(generalArgs);
|
||||||
|
assertIsRef(engine, generalArgs[0]);
|
||||||
|
|
||||||
|
engine.describe(generalArgs[0]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
tag: {
|
tag: {
|
||||||
regex: /^git +tag($|\s)/,
|
regex: /^git +tag($|\s)/,
|
||||||
execute: function(engine, command) {
|
execute: function(engine, command) {
|
||||||
var generalArgs = command.getGeneralArgs();
|
var generalArgs = command.getGeneralArgs();
|
||||||
|
|
||||||
|
|
||||||
if (generalArgs.length === 0) {
|
if (generalArgs.length === 0) {
|
||||||
var tags = engine.getTags();
|
var tags = engine.getTags();
|
||||||
engine.printTags(tags);
|
engine.printTags(tags);
|
||||||
|
@ -747,7 +765,6 @@ var commandConfig = {
|
||||||
|
|
||||||
command.twoArgsImpliedHead(generalArgs);
|
command.twoArgsImpliedHead(generalArgs);
|
||||||
engine.tag(generalArgs[0], generalArgs[1]);
|
engine.tag(generalArgs[0], generalArgs[1]);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -2378,6 +2378,53 @@ GitEngine.prototype.tag = function(name, ref) {
|
||||||
this.validateAndMakeTag(name, target);
|
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) {
|
GitEngine.prototype.validateAndDeleteBranch = function(name) {
|
||||||
// trying to delete, lets check our refs
|
// trying to delete, lets check our refs
|
||||||
var target = this.resolveID(name);
|
var target = this.resolveID(name);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue