| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7c981b0 commit f613b52
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -804,24 +804,29 @@ Repository.prototype.getStatusExt = function(opts) { | |||
| 804 | 804 | */ | |
| 805 | 805 | Repository.prototype.checkoutBranch = function(branch, opts) { | |
| 806 | 806 | var repo = this; | |
| 807 | - | ||
| 807 | + var reference; | ||
| 808 | 808 | opts = opts || {}; | |
| 809 | - opts.checkoutStrategy = opts.checkoutStrategy || Checkout.STRATEGY.SAFE; | ||
| 810 | - | ||
| 809 | + opts.checkoutStrategy = opts.checkoutStrategy || | ||
| 810 | + Checkout.STRATEGY.SAFE_CREATE; | ||
| 811 | 811 | return repo.getReference(branch) | |
| 812 | 812 | .then(function(ref) { | |
| 813 | 813 | if (!ref.isBranch()) { | |
| 814 | 814 | return false; | |
| 815 | 815 | } | |
| 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(); | ||
| 819 | 827 | return repo.setHead(name, | |
| 820 | 828 | repo.defaultSignature(), | |
| 821 | 829 | "Switch HEAD to " + name); | |
| 822 | - }) | ||
| 823 | - .then(function() { | ||
| 824 | - return Checkout.head(repo, opts); | ||
| 825 | 830 | }); | |
| 826 | 831 | }; | |
| 827 | 832 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -83,21 +83,23 @@ describe("Checkout", function() { | |||
| 83 | 83 | }); | |
| 84 | 84 | }); | |
| 85 | 85 | ||
| 86 | - it("can checkout a branch", function() { | ||
| 86 | + it.only("can checkout a branch", function() { | ||
| 87 | 87 | var test = this; | |
| 88 | 88 | ||
| 89 | - return test.repository.checkoutBranch(checkoutBranchName, { | ||
| 90 | - checkoutStrategy: Checkout.STRATEGY.FORCE | ||
| 91 | - }) | ||
| 89 | + return test.repository.checkoutBranch(checkoutBranchName) | ||
| 92 | 90 | .then(function() { | |
| 93 | 91 | var packageContent = fse.readFileSync(packageJsonPath, "utf-8"); | |
| 94 | 92 | ||
| 95 | 93 | assert.ok(!~packageContent.indexOf("\"ejs\": \"~1.0.0\",")); | |
| 96 | 94 | }) | |
| 97 | 95 | .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"); | ||
| 101 | 103 | }) | |
| 102 | 104 | .then(function() { | |
| 103 | 105 | var packageContent = fse.readFileSync(packageJsonPath, "utf-8"); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments