| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2109,6 +2109,17 @@ | |||
| 2109 | 2109 | "return": { | |
| 2110 | 2110 | "isErrorCode": true | |
| 2111 | 2111 | } | |
| 2112 | + }, | ||
| 2113 | + "git_reset_from_annotated": { | ||
| 2114 | + "args": { | ||
| 2115 | + "checkout_opts": { | ||
| 2116 | + "isOptional": true | ||
| 2117 | + } | ||
| 2118 | + }, | ||
| 2119 | + "isAsync": true, | ||
| 2120 | + "return": { | ||
| 2121 | + "isErrorCode": true | ||
| 2122 | + } | ||
| 2112 | 2123 | } | |
| 2113 | 2124 | } | |
| 2114 | 2125 | }, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ var normalizeOptions = NodeGit.Utils.normalizeOptions; | |||
| 4 | 4 | var Reset = NodeGit.Reset; | |
| 5 | 5 | var _default = Reset.default; | |
| 6 | 6 | var _reset = Reset.reset; | |
| 7 | + var _fromAnnotated = Reset.fromAnnotated; | ||
| 7 | 8 | ||
| 8 | 9 | /** | |
| 9 | 10 | * Look up a refs's commit. | |
@@ -50,3 +51,25 @@ Reset.reset = function(repo, target, resetType, opts) { | |||
| 50 | 51 | ||
| 51 | 52 | return _reset.call(this, repo, target, resetType, opts); | |
| 52 | 53 | }; | |
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * Sets the current head to the specified commit oid and optionally | ||
| 57 | + * resets the index and working tree to match. | ||
| 58 | + * | ||
| 59 | + * This behaves like reset but takes an annotated commit, which lets | ||
| 60 | + * you specify which extended sha syntax string was specified by a | ||
| 61 | + * user, allowing for more exact reflog messages. | ||
| 62 | + * | ||
| 63 | + * See the documentation for reset. | ||
| 64 | + * | ||
| 65 | + * @async | ||
| 66 | + * @param {Repository} repo | ||
| 67 | + * @param {AnnotatedCommit} target | ||
| 68 | + * @param {Number} resetType | ||
| 69 | + * @param {CheckoutOptions} opts | ||
| 70 | + */ | ||
| 71 | + Reset.fromAnnotated = function(repo, target, resetType, opts) { | ||
| 72 | + opts = normalizeOptions(opts, NodeGit.CheckoutOptions); | ||
| 73 | + | ||
| 74 | + return _fromAnnotated.call(this, repo, target, resetType, opts); | ||
| 75 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ describe("Reset", function() { | |||
| 8 | 8 | var NodeGit = require("../../"); | |
| 9 | 9 | var Repository = NodeGit.Repository; | |
| 10 | 10 | var Reset = NodeGit.Reset; | |
| 11 | + var AnnotatedCommit = NodeGit.AnnotatedCommit; | ||
| 11 | 12 | ||
| 12 | 13 | var reposPath = local("../repos/workdir"); | |
| 13 | 14 | var currentCommitOid = "32789a79e71fbc9e04d3eff7425e1771eb595150"; | |
@@ -104,33 +105,65 @@ describe("Reset", function() { | |||
| 104 | 105 | }); | |
| 105 | 106 | }); | |
| 106 | 107 | ||
| 107 | - it("can perform a soft reset", function() { | ||
| 108 | - var test = this; | ||
| 109 | - | ||
| 110 | - return Reset.reset(test.repo, test.previousCommit, Reset.TYPE.SOFT) | ||
| 108 | + function resetFrom(repo, commit, resetType, annotated) { | ||
| 109 | + var promise = null; | ||
| 110 | + if (annotated) { | ||
| 111 | + promise = AnnotatedCommit.lookup(repo, commit.id()) | ||
| 112 | + .then(function(annotatedCommit) { | ||
| 113 | + return Reset.fromAnnotated(repo, annotatedCommit, resetType); | ||
| 114 | + }); | ||
| 115 | + } else { | ||
| 116 | + promise = Reset.reset(repo, commit, resetType); | ||
| 117 | + } | ||
| 118 | + return promise | ||
| 111 | 119 | .then(function() { | |
| 112 | - return test.repo.refreshIndex(); | ||
| 120 | + return repo.refreshIndex(); | ||
| 113 | 121 | }) | |
| 114 | 122 | .then(function(index) { | |
| 115 | 123 | return index.writeTree(); | |
| 116 | 124 | }) | |
| 117 | 125 | .then(function(oid) { | |
| 118 | - return test.repo.getTree(oid); | ||
| 126 | + return repo.getTree(oid); | ||
| 119 | 127 | }) | |
| 120 | 128 | .then(function(tree) { | |
| 121 | 129 | return tree.getEntry(filePath); | |
| 122 | 130 | }) | |
| 123 | 131 | .then(function(entry) { | |
| 124 | 132 | return entry.getBlob(); | |
| 125 | - }) | ||
| 133 | + }); | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + it("can perform a soft reset", function() { | ||
| 137 | + var test = this; | ||
| 138 | + | ||
| 139 | + return resetFrom(test.repo, test.previousCommit, Reset.TYPE.SOFT, false) | ||
| 140 | + .then(function(blob) { | ||
| 141 | + var currentCommitContents = test.currentCommitBlob.toString(); | ||
| 142 | + var previousCommitContents = test.previousCommitBlob.toString(); | ||
| 143 | + var resetContents = blob.toString(); | ||
| 144 | + | ||
| 145 | + // With a soft reset all of the changes should be in the index | ||
| 146 | + // still so the index should still == what we had at the current | ||
| 147 | + // commit and not the one nwe reset to | ||
| 148 | + assert(resetContents == currentCommitContents); | ||
| 149 | + assert(resetContents != previousCommitContents); | ||
| 150 | + | ||
| 151 | + return Reset(test.repo, test.currentCommit, Reset.TYPE.HARD); | ||
| 152 | + }); | ||
| 153 | + }); | ||
| 154 | + | ||
| 155 | + it("can perform an annotated soft reset", function() { | ||
| 156 | + var test = this; | ||
| 157 | + | ||
| 158 | + return resetFrom(test.repo, test.previousCommit, Reset.TYPE.SOFT, true) | ||
| 126 | 159 | .then(function(blob) { | |
| 127 | 160 | var currentCommitContents = test.currentCommitBlob.toString(); | |
| 128 | 161 | var previousCommitContents = test.previousCommitBlob.toString(); | |
| 129 | 162 | var resetContents = blob.toString(); | |
| 130 | 163 | ||
| 131 | 164 | // With a soft reset all of the changes should be in the index | |
| 132 | 165 | // still so the index should still == what we had at the current | |
| 133 | - // commit and not the one we reset to | ||
| 166 | + // commit and not the one nwe reset to | ||
| 134 | 167 | assert(resetContents == currentCommitContents); | |
| 135 | 168 | assert(resetContents != previousCommitContents); | |
| 136 | 169 | ||
@@ -141,22 +174,32 @@ describe("Reset", function() { | |||
| 141 | 174 | it("can perform a mixed reset", function() { | |
| 142 | 175 | var test = this; | |
| 143 | 176 | ||
| 144 | - return Reset.reset(test.repo, test.previousCommit, Reset.TYPE.MIXED) | ||
| 145 | - .then(function() { | ||
| 146 | - return test.repo.refreshIndex(); | ||
| 147 | - }) | ||
| 148 | - .then(function(index) { | ||
| 149 | - return index.writeTree(); | ||
| 150 | - }) | ||
| 151 | - .then(function(oid) { | ||
| 152 | - return test.repo.getTree(oid); | ||
| 153 | - }) | ||
| 154 | - .then(function(tree) { | ||
| 155 | - return tree.getEntry(filePath); | ||
| 156 | - }) | ||
| 157 | - .then(function(entry) { | ||
| 158 | - return entry.getBlob(); | ||
| 177 | + return resetFrom(test.repo, test.previousCommit, Reset.TYPE.MIXED, false) | ||
| 178 | + .then(function(blob) { | ||
| 179 | + var currentCommitContents = test.currentCommitBlob.toString(); | ||
| 180 | + var previousCommitContents = test.previousCommitBlob.toString(); | ||
| 181 | + var resetContents = blob.toString(); | ||
| 182 | + | ||
| 183 | + // With a mixed reset all of the changes should removed from the index | ||
| 184 | + // but still in the working directory. (i.e. unstaged) | ||
| 185 | + assert(resetContents != currentCommitContents); | ||
| 186 | + assert(resetContents == previousCommitContents); | ||
| 187 | + | ||
| 188 | + return fse.readFile(path.join(test.repo.workdir(), filePath)); | ||
| 159 | 189 | }) | |
| 190 | + .then(function(fileContents) { | ||
| 191 | + var currentCommitContents = test.currentCommitBlob.toString(); | ||
| 192 | + | ||
| 193 | + assert(fileContents == currentCommitContents); | ||
| 194 | + | ||
| 195 | + return Reset.reset(test.repo, test.currentCommit, Reset.TYPE.HARD); | ||
| 196 | + }); | ||
| 197 | + }); | ||
| 198 | + | ||
| 199 | + it("can perform an annotated mixed reset", function() { | ||
| 200 | + var test = this; | ||
| 201 | + | ||
| 202 | + return resetFrom(test.repo, test.previousCommit, Reset.TYPE.MIXED, true) | ||
| 160 | 203 | .then(function(blob) { | |
| 161 | 204 | var currentCommitContents = test.currentCommitBlob.toString(); | |
| 162 | 205 | var previousCommitContents = test.previousCommitBlob.toString(); | |
@@ -181,22 +224,32 @@ describe("Reset", function() { | |||
| 181 | 224 | it("can perform a hard reset", function() { | |
| 182 | 225 | var test = this; | |
| 183 | 226 | ||
| 184 | - return Reset.reset(test.repo, test.previousCommit, Reset.TYPE.HARD) | ||
| 185 | - .then(function() { | ||
| 186 | - return test.repo.refreshIndex(); | ||
| 187 | - }) | ||
| 188 | - .then(function(index) { | ||
| 189 | - return index.writeTree(); | ||
| 190 | - }) | ||
| 191 | - .then(function(oid) { | ||
| 192 | - return test.repo.getTree(oid); | ||
| 193 | - }) | ||
| 194 | - .then(function(tree) { | ||
| 195 | - return tree.getEntry(filePath); | ||
| 196 | - }) | ||
| 197 | - .then(function(entry) { | ||
| 198 | - return entry.getBlob(); | ||
| 227 | + return resetFrom(test.repo, test.previousCommit, Reset.TYPE.HARD, false) | ||
| 228 | + .then(function(blob) { | ||
| 229 | + var currentCommitContents = test.currentCommitBlob.toString(); | ||
| 230 | + var previousCommitContents = test.previousCommitBlob.toString(); | ||
| 231 | + var resetContents = blob.toString(); | ||
| 232 | + | ||
| 233 | + // With a hard reset all of the changes should removed from the index | ||
| 234 | + // and also removed from the working directory | ||
| 235 | + assert(resetContents != currentCommitContents); | ||
| 236 | + assert(resetContents == previousCommitContents); | ||
| 237 | + | ||
| 238 | + return fse.readFile(path.join(test.repo.workdir(), filePath)); | ||
| 199 | 239 | }) | |
| 240 | + .then(function(fileContents) { | ||
| 241 | + var previousCommitContents = test.previousCommitBlob.toString(); | ||
| 242 | + | ||
| 243 | + assert(fileContents == previousCommitContents); | ||
| 244 | + | ||
| 245 | + return Reset.reset(test.repo, test.currentCommit, Reset.TYPE.HARD); | ||
| 246 | + }); | ||
| 247 | + }); | ||
| 248 | + | ||
| 249 | + it("can perform an annotated hard reset", function() { | ||
| 250 | + var test = this; | ||
| 251 | + | ||
| 252 | + return resetFrom(test.repo, test.previousCommit, Reset.TYPE.HARD, true) | ||
| 200 | 253 | .then(function(blob) { | |
| 201 | 254 | var currentCommitContents = test.currentCommitBlob.toString(); | |
| 202 | 255 | var previousCommitContents = test.previousCommitBlob.toString(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments