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

Checkout branch with tree instead of head · javascript-forks/nodegit.nodegit@f613b52 · GitHub

Repository navigation

Commit f613b52

Browse files
committed
Checkout branch with tree instead of head
Checkout.head futzes with the index, and that's not what we want in a branch checkout
1 parent 7c981b0 commit f613b52

2 files changed

Lines changed: 23 additions & 16 deletions

File tree

‎lib/repository.js‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -804,24 +804,29 @@ Repository.prototype.getStatusExt = function(opts) {
804804
*/
805805
Repository.prototype.checkoutBranch = function(branch, opts) {
806806
var repo = this;
807-
807+
var reference;
808808
opts = opts || {};
809-
opts.checkoutStrategy = opts.checkoutStrategy || Checkout.STRATEGY.SAFE;
810-
809+
opts.checkoutStrategy = opts.checkoutStrategy ||
810+
Checkout.STRATEGY.SAFE_CREATE;
811811
return repo.getReference(branch)
812812
.then(function(ref) {
813813
if (!ref.isBranch()) {
814814
return false;
815815
}
816-
817-
var name = ref.name();
818-
816+
reference = ref;
817+
return repo.getBranchCommit(ref.name());
818+
})
819+
.then(function(commit) {
820+
return commit.getTree();
821+
})
822+
.then(function(tree) {
823+
return Checkout.tree(repo, tree, opts);
824+
})
825+
.then(function() {
826+
var name = reference.name();
819827
return repo.setHead(name,
820828
repo.defaultSignature(),
821829
"Switch HEAD to " + name);
822-
})
823-
.then(function() {
824-
return Checkout.head(repo, opts);
825830
});
826831
};
827832

‎test/tests/checkout.js‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,23 @@ describe("Checkout", function() {
8383
});
8484
});
8585

86-
it("can checkout a branch", function() {
86+
it.only("can checkout a branch", function() {
8787
var test = this;
8888

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

9593
assert.ok(!~packageContent.indexOf("\"ejs\": \"~1.0.0\","));
9694
})
9795
.then(function() {
98-
return test.repository.checkoutBranch("master", {
99-
checkoutStrategy: Checkout.STRATEGY.FORCE
100-
});
96+
return test.repository.getStatus();
97+
})
98+
.then(function(statuses) {
99+
assert.equal(statuses.length, 0);
100+
})
101+
.then(function() {
102+
return test.repository.checkoutBranch("master");
101103
})
102104
.then(function() {
103105
var packageContent = fse.readFileSync(packageJsonPath, "utf-8");

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL