diff --git a/__tests__/treeCompare.spec.js b/__tests__/treeCompare.spec.js index 052d8df2..ffa27466 100644 --- a/__tests__/treeCompare.spec.js +++ b/__tests__/treeCompare.spec.js @@ -49,6 +49,18 @@ describe('Tree Compare', function() { ); }); + it('compares with considering leftover branches', function() { + testMethod( + { + compareAllBranchesAndEnforceBranchCleanup: true, + }, + '{"branches":{"master":{"target":"C2","id":"master","remoteTrackingBranchID":null},"foo":{"target":"C2","id":"foo","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"tags":{},"HEAD":{"target":"foo","id":"HEAD"}}', + { + '{"branches":{"master":{"target":"C2","id":"master","remoteTrackingBranchID":null},"foo":{"target":"C2","id":"foo","remoteTrackingBranchID":null},"randoBran":{"target":"C2","id":"randoBran","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"tags":{},"HEAD":{"target":"foo","id":"HEAD"}}': false, + }, + ); + }); + it('deep compares on origin tree', function() { testMethod( {}, // checked for all methods so this doesn't matter diff --git a/src/js/graph/treeCompare.js b/src/js/graph/treeCompare.js index 8652f172..f01cf457 100644 --- a/src/js/graph/treeCompare.js +++ b/src/js/graph/treeCompare.js @@ -54,6 +54,10 @@ TreeCompare.dispatchShallow = function(levelBlob, goalTreeString, treeToCompare) return TreeCompare.compareBranchWithinTrees( treeToCompare, goalTreeString, 'master' ); + case !!levelBlob.compareAllBranchesAndEnforceBranchCleanup: + return TreeCompare.compareAllBranchesAndEnforceBranchCleanup( + treeToCompare, goalTreeString + ); case !!levelBlob.compareOnlyBranches: return TreeCompare.compareAllBranchesWithinTrees( treeToCompare, goalTreeString @@ -88,6 +92,26 @@ TreeCompare.compareAllBranchesWithinTreesAndHEAD = function(treeToCompare, goalT this.compareAllTagsWithinTrees(treeToCompare, goalTree); }; +TreeCompare.compareAllBranchesAndEnforceBranchCleanup = function(treeToCompare, goalTree) { + treeToCompare = this.convertTreeSafe(treeToCompare); + goalTree = this.convertTreeSafe(goalTree); + + // Unlike compareAllBranchesWithinTrees, here we consider both the branches + // in the goalTree and the branches in the treeToCompare. This means that + // we enfoce that you clean up any branches that you have locally that + // the goal does not have. this is helpful when we want to verify that you + // have deleted branch, for instance. + var allBranches = Object.assign( + {}, + treeToCompare.branches, + goalTree.branches + ); + return Object.keys(allBranches).every(function(branch) { + return this.compareBranchWithinTrees(treeToCompare, goalTree, branch); + }.bind(this)); +}; + + TreeCompare.compareAllBranchesWithinTrees = function(treeToCompare, goalTree) { treeToCompare = this.convertTreeSafe(treeToCompare); goalTree = this.convertTreeSafe(goalTree);