Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fast forward checking out the tree instead of the head
Don't need to manipulate the index in this scenario
  • Loading branch information
orderedlist committed Mar 22, 2015
commit 7775aa70c1dd296996054af71a14b2b50d52c210
21 changes: 9 additions & 12 deletions lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,24 +661,22 @@ Repository.prototype.mergeBranches = function(to, from, signature) {
var repo = this;
var fromBranch;
var toBranch;
var headCommit;

signature = signature || repo.defaultSignature();

return Promise.all([
repo.getBranch(to),
repo.getBranch(from),
repo.getHeadCommit()
repo.getBranch(to),
repo.getBranch(from)
]).then(function(objects) {
toBranch = objects[0];
fromBranch = objects[1];
headCommit = objects[2];

return Promise.all([
repo.getBranchCommit(toBranch),
repo.getBranchCommit(fromBranch)
]);
}).then(function(branchCommits) {
})
.then(function(branchCommits) {
var toCommitOid = branchCommits[0].toString();
var fromCommitOid = branchCommits[1].toString();

Expand All @@ -699,13 +697,12 @@ Repository.prototype.mergeBranches = function(to, from, signature) {

return branchCommits[1].getTree()
.then(function(tree) {
if (headCommit.toString() == toCommitOid) {
if (toBranch.isHead()) {
// Checkout the tree if we're on the branch
var opts = {checkoutStrategy: NodeGit.Checkout.STRATEGY.SAFE};
var opts = {
checkoutStrategy: NodeGit.Checkout.STRATEGY.SAFE_CREATE
};
return NodeGit.Checkout.tree(repo, tree, opts);
} else {
// Otherwise, just point the ref
return;
}
})
.then(function() {
Expand All @@ -716,7 +713,7 @@ Repository.prototype.mergeBranches = function(to, from, signature) {
.then(function() {
return fromCommitOid;
});
})
});
}
else {
// We have to merge. Lets do it!
Expand Down
11 changes: 11 additions & 0 deletions test/tests/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ describe("Merge", function() {
theirCommit = commit;
});
})
.then(function() {
var opts = {checkoutStrategy: NodeGit.Checkout.STRATEGY.FORCE};
return repository.checkoutBranch(ourBranchName, opts);
})
.then(function() {
return repository.mergeBranches(
ourBranchName,
Expand All @@ -228,6 +232,13 @@ describe("Merge", function() {
.then(function(branchCommit) {
assert.equal(oid.toString(), branchCommit.toString());
});
})
.then(function() {
return repository.getStatus();
})
.then(function(statuses) {
// make sure we didn't change the index
assert.equal(statuses.length, 0);
});
});

Expand Down