correct revert now

This commit is contained in:
Peter Cottle 2012-10-24 15:31:52 -07:00
parent f6a81c4ba0
commit fe5e29bfe1
2 changed files with 45 additions and 38 deletions

View file

@ -351,48 +351,59 @@ GitEngine.prototype.twoArgsImpliedHead = function(args, option) {
}; };
GitEngine.prototype.revertStarter = function() { GitEngine.prototype.revertStarter = function() {
this.validateArgBounds(this.generalArgs, 1, 1); this.validateArgBounds(this.generalArgs, 1, NaN);
if (this.generalArgs[0] == 'HEAD') { var response = this.revert(this.generalArgs);
// we could optionally not do anything here and just skip
// the command, but I think people need to understand it doesn't make sense if (response) {
throw new GitError({ animationFactory.rebaseAnimation(this.animationQueue, response, this);
msg: "Can't revert to HEAD! That's where you are now"
});
return;
} }
this.revert(this.generalArgs[0]);
}; };
GitEngine.prototype.revert = function(whichCommit) { GitEngine.prototype.revert = function(whichCommits) {
// first get that commit // for each commit, we want to revert it
var targetLocation = this.getCommitFromRef(whichCommit); var toRebase = [];
var here = this.getCommitFromRef('HEAD'); _.each(whichCommits, function(stringRef) {
// then BFS from here to that commit toRebase.push(this.getCommitFromRef(stringRef));
var toUndo = []; }, this);
var queue = [here];
while (queue.length) { // we animate reverts now!! we use the rebase animation though so that's
var popped = queue.pop(); // why the terminology is like it is
if (popped.get('id') == targetLocation.get('id')) { var animationResponse = {};
// we got all that we needed to get animationResponse.destinationBranch = this.resolveID(toRebase[0]);
break; animationResponse.toRebaseArray = toRebase.slice(0);
} animationResponse.rebaseSteps = [];
toUndo.push(popped);
queue = queue.concat(popped.get('parents')); beforeSnapshot = gitVisuals.genSnapshot();
queue.sort(this.idSortFunc); var afterSnapshot;
}
// now make a bunch of commits on top of where we are // now make a bunch of commits on top of where we are
var base = here; var base = this.getCommitFromRef('HEAD');
toUndo.sort(this.idSortFunc); _.each(toRebase, function(oldCommit) {
for (var i = 0; i < toUndo.length; i++) { var newId = this.rebaseAltID(oldCommit.get('id'));
var newId = this.rebaseAltID(toUndo[i].get('id'));
var newCommit = this.makeCommit([base], newId); var newCommit = this.makeCommit([base], newId, {
commitMessage: 'Reverting ' + this.resolveName(oldCommit) +
': "' + oldCommit.get('commitMessage') + '"'
});
base = newCommit; base = newCommit;
}
// animation stuff
afterSnapshot = gitVisuals.genSnapshot();
animationResponse.rebaseSteps.push({
oldCommit: oldCommit,
newCommit: newCommit,
beforeSnapshot: beforeSnapshot,
afterSnapshot: afterSnapshot
});
beforeSnapshot = afterSnapshot;
}, this);
// done! update our location // done! update our location
this.setTargetLocation('HEAD', base); this.setTargetLocation('HEAD', base);
// animation
return animationResponse;
}; };
GitEngine.prototype.resetStarter = function() { GitEngine.prototype.resetStarter = function() {
@ -851,8 +862,6 @@ GitEngine.prototype.rebase = function(targetSource, currentLocation) {
// it's not in the set, so we need to rebase this commit // it's not in the set, so we need to rebase this commit
toRebaseRough.push(popped); toRebaseRough.push(popped);
// keep searching // keep searching
pQueue = pQueue.concat(popped.get('parents'));
pQueue.sort(this.idSortFunc);
} }
return this.rebaseFinish(toRebaseRough, stopSet, targetSource, currentLocation); return this.rebaseFinish(toRebaseRough, stopSet, targetSource, currentLocation);

View file

@ -466,9 +466,7 @@ GitVisuals.prototype.addEdge = function(idTail, idHead) {
}; };
GitVisuals.prototype.collectionChanged = function() { GitVisuals.prototype.collectionChanged = function() {
console.log('git visuals... collection was changed'); // TODO ?
// redo stuff
// TODO
}; };
GitVisuals.prototype.zIndexReflow = function() { GitVisuals.prototype.zIndexReflow = function() {