diff --git a/src/js/git/index.js b/src/js/git/index.js index 83ed6b8f..99960e3a 100644 --- a/src/js/git/index.js +++ b/src/js/git/index.js @@ -418,12 +418,24 @@ GitEngine.prototype.makeRemoteBranchForRemote = function(branchName) { }; GitEngine.prototype.findCommonAncestorForRemote = function(myTarget) { - // like the method below but opposite - while (!this.origin.refs[myTarget]) { - var parents = this.refs[myTarget].get('parents'); - myTarget = parents[0].get('id'); + if (this.origin.refs[myTarget]) { + return myTarget; } - return myTarget; + var parents = this.refs[myTarget].get('parents'); + if (parents.length === 1) { + // Easy, we only have one parent. lets just go upwards + myTarget = parents[0].get('id'); + // Recurse upwards to find where our remote has a commit. + return this.findCommonAncestorForRemote(myTarget); + } + // We have multiple parents so find out where these two meet. + var leftTarget = this.findCommonAncestorForRemote(parents[0].get('id')); + var rightTarget = this.findCommonAncestorForRemote(parents[1].get('id')); + return this.getCommonAncestor( + leftTarget, + rightTarget, + true // dont throw since we dont know the order here. + ).get('id'); }; GitEngine.prototype.findCommonAncestorWithRemote = function(originTarget) { @@ -2100,7 +2112,6 @@ GitEngine.prototype.hgRebase = function(destination, base) { GitEngine.prototype.rebase = function(targetSource, currentLocation, options) { // first some conditions - debugger; if (this.isUpstreamOf(targetSource, currentLocation)) { this.command.setResult(intl.str('git-result-uptodate')); @@ -2764,8 +2775,8 @@ GitEngine.prototype.log = function(ref, omitSet) { }); }; -GitEngine.prototype.getCommonAncestor = function(ancestor, cousin) { - if (this.isUpstreamOf(cousin, ancestor)) { +GitEngine.prototype.getCommonAncestor = function(ancestor, cousin, dontThrow) { + if (this.isUpstreamOf(cousin, ancestor) && !dontThrow) { throw new Error('Dont use common ancestor if we are upstream!'); } diff --git a/src/js/sandbox/index.js b/src/js/sandbox/index.js index 3d81ee9a..c9131e23 100644 --- a/src/js/sandbox/index.js +++ b/src/js/sandbox/index.js @@ -476,4 +476,3 @@ var Sandbox = Backbone.View.extend({ }); exports.Sandbox = Sandbox; - diff --git a/src/js/visuals/visualization.js b/src/js/visuals/visualization.js index 247851cf..7c9ebb97 100644 --- a/src/js/visuals/visualization.js +++ b/src/js/visuals/visualization.js @@ -290,4 +290,3 @@ var Visualization = Backbone.View.extend({ }); exports.Visualization = Visualization; -