| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f613b52 commit a4a4c8b
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -661,15 +661,18 @@ Repository.prototype.mergeBranches = function(to, from, signature) { | |||
| 661 | 661 | var repo = this; | |
| 662 | 662 | var fromBranch; | |
| 663 | 663 | var toBranch; | |
| 664 | + var headCommit; | ||
| 664 | 665 | ||
| 665 | 666 | signature = signature || repo.defaultSignature(); | |
| 666 | 667 | ||
| 667 | 668 | return Promise.all([ | |
| 668 | 669 | repo.getBranch(to), | |
| 669 | - repo.getBranch(from) | ||
| 670 | - ]).then(function(branches) { | ||
| 671 | - toBranch = branches[0]; | ||
| 672 | - fromBranch = branches[1]; | ||
| 670 | + repo.getBranch(from), | ||
| 671 | + repo.getHeadCommit() | ||
| 672 | + ]).then(function(objects) { | ||
| 673 | + toBranch = objects[0]; | ||
| 674 | + fromBranch = objects[1]; | ||
| 675 | + headCommit = objects[2]; | ||
| 673 | 676 | ||
| 674 | 677 | return Promise.all([ | |
| 675 | 678 | repo.getBranchCommit(toBranch), | |
@@ -694,13 +697,26 @@ Repository.prototype.mergeBranches = function(to, from, signature) { | |||
| 694 | 697 | " to branch " + | |
| 695 | 698 | fromBranch.shorthand(); | |
| 696 | 699 | ||
| 697 | - return toBranch.setTarget( | ||
| 698 | - fromCommitOid, | ||
| 699 | - signature, | ||
| 700 | - message) | ||
| 700 | + return branchCommits[1].getTree() | ||
| 701 | + .then(function(tree) { | ||
| 702 | + if (headCommit.toString() == toCommitOid) { | ||
| 703 | + // Checkout the tree if we're on the branch | ||
| 704 | + var opts = {checkoutStrategy: NodeGit.Checkout.STRATEGY.SAFE}; | ||
| 705 | + return NodeGit.Checkout.tree(repo, tree, opts); | ||
| 706 | + } else { | ||
| 707 | + // Otherwise, just point the ref | ||
| 708 | + return; | ||
| 709 | + } | ||
| 710 | + }) | ||
| 701 | 711 | .then(function() { | |
| 702 | - return fromCommitOid; | ||
| 703 | - }); | ||
| 712 | + return toBranch.setTarget( | ||
| 713 | + fromCommitOid, | ||
| 714 | + signature, | ||
| 715 | + message) | ||
| 716 | + .then(function() { | ||
| 717 | + return fromCommitOid; | ||
| 718 | + }); | ||
| 719 | + }) | ||
| 704 | 720 | } | |
| 705 | 721 | else { | |
| 706 | 722 | // We have to merge. Lets do it! | |
| Back | FazBrowse Home | New Git URL |
0 commit comments