diff --git a/src/js/git/commands.js b/src/js/git/commands.js index 43bf328a..03b68cd0 100644 --- a/src/js/git/commands.js +++ b/src/js/git/commands.js @@ -615,7 +615,8 @@ var commandConfig = { '--interactive-test', '--aboveAll', '-p', - '--preserve-merges' + '--preserve-merges', + '--onto' ], regex: /^git +rebase($|\s)/, execute: function(engine, command) { @@ -645,6 +646,17 @@ var commandConfig = { return; } + if (commandOptions['--onto']) { + var args = commandOptions['--onto'].concat(generalArgs); + command.threeArgsImpliedHead(args, ' --onto'); + + engine.rebaseOnto(args[0], args[1], args[2], { + preserveMerges: commandOptions['-p'] || commandOptions['--preserve-merges'] + }); + + return; + } + command.twoArgsImpliedHead(generalArgs); engine.rebase(generalArgs[0], generalArgs[1], { preserveMerges: commandOptions['-p'] || commandOptions['--preserve-merges'] diff --git a/src/js/git/index.js b/src/js/git/index.js index 23ec0a95..b5970d2f 100644 --- a/src/js/git/index.js +++ b/src/js/git/index.js @@ -2165,6 +2165,21 @@ GitEngine.prototype.rebase = function(targetSource, currentLocation, options) { return this.rebaseFinish(toRebaseRough, stopSet, targetSource, currentLocation, options); }; +GitEngine.prototype.rebaseOnto = function(targetSource, oldSource, unit, options) { + if (this.isUpstreamOf(unit, targetSource)) { + this.setTargetLocation(unit, this.getCommitFromRef(targetSource)); + this.command.setResult(intl.str('git-result-fastforward')); + + this.checkout(unit); + return; + } + + var stopSet = Graph.getUpstreamSet(this, targetSource); + var oldBranchSet = Graph.getUpstreamSet(this, oldSource); + var toRebaseRough = this.getUpstreamDiffFromSet(oldBranchSet, unit); + return this.rebaseFinish(toRebaseRough, stopSet, targetSource, unit, options); +}; + GitEngine.prototype.getUpstreamDiffSetFromSet = function(stopSet, location) { var set = {}; this.getUpstreamDiffFromSet(stopSet, location).forEach(function (commit) { diff --git a/src/js/models/commandModel.js b/src/js/models/commandModel.js index 0580f3d5..bb99123e 100644 --- a/src/js/models/commandModel.js +++ b/src/js/models/commandModel.js @@ -124,17 +124,23 @@ var Command = Backbone.Model.extend({ } }, - oneArgImpliedHead: function(args, option) { - this.validateArgBounds(args, 0, 1, option); + argImpliedHead: function (args, lower, upper, option) { + // our args we expect to be between {lower} and {upper} + this.validateArgBounds(args, lower, upper, option); // and if it's one, add a HEAD to the back - this.impliedHead(args, 0); + this.impliedHead(args, lower); + }, + + oneArgImpliedHead: function(args, option) { + this.argImpliedHead(args, 0, 1, option); }, twoArgsImpliedHead: function(args, option) { - // our args we expect to be between 1 and 2 - this.validateArgBounds(args, 1, 2, option); - // and if it's one, add a HEAD to the back - this.impliedHead(args, 1); + this.argImpliedHead(args, 1, 2, option); + }, + + threeArgsImpliedHead: function(args, option) { + this.argImpliedHead(args, 2, 3, option); }, oneArgImpliedOrigin: function(args) {