FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Update Checkout and Merge by orderedlist · Pull Request #505 · nodegit/nodegit · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (3) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
58 changes: 38 additions & 20 deletions lib/repository.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 test/tests/checkout.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 test/tests/merge.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL