From b6a34ec17e707a2e42d672004d3746ac94cf42d0 Mon Sep 17 00:00:00 2001 From: Peter Cottle Date: Mon, 9 Apr 2018 08:34:01 -0700 Subject: [PATCH] Resolves #459 -- parent ordering can break some operations --- src/js/git/index.js | 27 +++++++++++++++++++-------- src/js/sandbox/index.js | 1 - src/js/visuals/visualization.js | 1 - 3 files changed, 19 insertions(+), 10 deletions(-) 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; -