Skip to content

Commit a4a4c8b

Browse files
committed
Properly update the index on Merge FF
1 parent f613b52 commit a4a4c8b

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

lib/repository.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -661,15 +661,18 @@ Repository.prototype.mergeBranches = function(to, from, signature) {
661661
var repo = this;
662662
var fromBranch;
663663
var toBranch;
664+
var headCommit;
664665

665666
signature = signature || repo.defaultSignature();
666667

667668
return Promise.all([
668669
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];
673676

674677
return Promise.all([
675678
repo.getBranchCommit(toBranch),
@@ -694,13 +697,26 @@ Repository.prototype.mergeBranches = function(to, from, signature) {
694697
" to branch " +
695698
fromBranch.shorthand();
696699

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+
})
701711
.then(function() {
702-
return fromCommitOid;
703-
});
712+
return toBranch.setTarget(
713+
fromCommitOid,
714+
signature,
715+
message)
716+
.then(function() {
717+
return fromCommitOid;
718+
});
719+
})
704720
}
705721
else {
706722
// We have to merge. Lets do it!

0 commit comments

Comments
 (0)