Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
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
58 changes: 38 additions & 20 deletions 58 lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,17 +665,18 @@ Repository.prototype.mergeBranches = function(to, from, signature) {
signature = signature || repo.defaultSignature();

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

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 @@ -694,12 +695,24 @@ Repository.prototype.mergeBranches = function(to, from, signature) {
" to branch " +
fromBranch.shorthand();

return toBranch.setTarget(
fromCommitOid,
signature,
message)
return branchCommits[1].getTree()
.then(function(tree) {
if (toBranch.isHead()) {
// Checkout the tree if we're on the branch
var opts = {
checkoutStrategy: NodeGit.Checkout.STRATEGY.SAFE_CREATE
};
return NodeGit.Checkout.tree(repo, tree, opts);
}
})
.then(function() {
return fromCommitOid;
return toBranch.setTarget(
fromCommitOid,
signature,
message)
.then(function() {
return fromCommitOid;
});
});
}
else {
Expand Down Expand Up @@ -804,24 +817,29 @@ Repository.prototype.getStatusExt = function(opts) {
*/
Repository.prototype.checkoutBranch = function(branch, opts) {
var repo = this;

var reference;
opts = opts || {};
opts.checkoutStrategy = opts.checkoutStrategy || Checkout.STRATEGY.SAFE;

opts.checkoutStrategy = opts.checkoutStrategy ||
Checkout.STRATEGY.SAFE_CREATE;
return repo.getReference(branch)
.then(function(ref) {
if (!ref.isBranch()) {
return false;
}

var name = ref.name();

reference = ref;
return repo.getBranchCommit(ref.name());
})
.then(function(commit) {
return commit.getTree();
})
.then(function(tree) {
return Checkout.tree(repo, tree, opts);
})
.then(function() {
var name = reference.name();
return repo.setHead(name,
repo.defaultSignature(),
"Switch HEAD to " + name);
})
.then(function() {
return Checkout.head(repo, opts);
});
};

Expand Down
14 changes: 8 additions & 6 deletions 14 test/tests/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,20 @@ describe("Checkout", function() {
it("can checkout a branch", function() {
var test = this;

return test.repository.checkoutBranch(checkoutBranchName, {
checkoutStrategy: Checkout.STRATEGY.FORCE
})
return test.repository.checkoutBranch(checkoutBranchName)
.then(function() {
var packageContent = fse.readFileSync(packageJsonPath, "utf-8");

assert.ok(!~packageContent.indexOf("\"ejs\": \"~1.0.0\","));
})
.then(function() {
return test.repository.checkoutBranch("master", {
checkoutStrategy: Checkout.STRATEGY.FORCE
});
return test.repository.getStatus();
})
.then(function(statuses) {
assert.equal(statuses.length, 0);
})
.then(function() {
return test.repository.checkoutBranch("master");
})
.then(function() {
var packageContent = fse.readFileSync(packageJsonPath, "utf-8");
Expand Down
11 changes: 11 additions & 0 deletions 11 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.