| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2343430 commit c01531e
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1416,6 +1416,17 @@ | |||
| 1416 | 1416 | "reset": { | |
| 1417 | 1417 | "functions": { | |
| 1418 | 1418 | "git_reset": { | |
| 1419 | + "args": { | ||
| 1420 | + "checkout_opts": { | ||
| 1421 | + "isOptional": true | ||
| 1422 | + }, | ||
| 1423 | + "log_message": { | ||
| 1424 | + "isOptional": true | ||
| 1425 | + }, | ||
| 1426 | + "signature": { | ||
| 1427 | + "isOptional": true | ||
| 1428 | + } | ||
| 1429 | + }, | ||
| 1419 | 1430 | "isAsync": true, | |
| 1420 | 1431 | "return": { | |
| 1421 | 1432 | "isErrorCode": true | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,11 +9,17 @@ Reset.default = function(repo, target, pathspecs) { | |||
| 9 | 9 | }; | |
| 10 | 10 | ||
| 11 | 11 | var reset = Reset.reset; | |
| 12 | - Reset.reset = function(target, resetType, checkoutOpts, signature, logMessage) { | ||
| 12 | + Reset.reset = function( repo, | ||
| 13 | + target, | ||
| 14 | + resetType, | ||
| 15 | + checkoutOpts, | ||
| 16 | + signature, | ||
| 17 | + logMessage) { | ||
| 13 | 18 | checkoutOpts = normalizeOptions(checkoutOpts, NodeGit.CheckoutOptions); | |
| 14 | 19 | ||
| 15 | 20 | return reset.call( | |
| 16 | 21 | this, | |
| 22 | + repo, | ||
| 17 | 23 | target, | |
| 18 | 24 | resetType, | |
| 19 | 25 | checkoutOpts, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,8 @@ | |||
| 1 | 1 | var assert = require("assert"); | |
| 2 | 2 | var path = require("path"); | |
| 3 | 3 | var local = path.join.bind(path, __dirname); | |
| 4 | + var promisify = require("promisify-node"); | ||
| 5 | + var fse = promisify(require("fs-extra")); | ||
| 4 | 6 | ||
| 5 | 7 | describe("Reset", function() { | |
| 6 | 8 | var Repository = require(local("../../lib/repository")); | |
@@ -72,6 +74,146 @@ describe("Reset", function() { | |||
| 72 | 74 | ||
| 73 | 75 | assert(resetContents != currentCommitContents); | |
| 74 | 76 | assert(resetContents == previousCommitContents); | |
| 77 | + }) | ||
| 78 | + .then(function() { | ||
| 79 | + return Reset.default(test.repo, test.currentCommit, filePath); | ||
| 80 | + }) | ||
| 81 | + .then(function() { | ||
| 82 | + return test.repo.openIndex(); | ||
| 83 | + }) | ||
| 84 | + .then(function(index) { | ||
| 85 | + return index.writeTree(); | ||
| 86 | + }) | ||
| 87 | + .then(function(oid) { | ||
| 88 | + return test.repo.getTree(oid); | ||
| 89 | + }) | ||
| 90 | + .then(function(tree) { | ||
| 91 | + return tree.getEntry(filePath); | ||
| 92 | + }) | ||
| 93 | + .then(function(entry) { | ||
| 94 | + return entry.getBlob(); | ||
| 95 | + }) | ||
| 96 | + .then(function(blob) { | ||
| 97 | + var currentCommitContents = test.currentCommitBlob.toString(); | ||
| 98 | + var previousCommitContents = test.previousCommitBlob.toString(); | ||
| 99 | + var resetContents = blob.toString(); | ||
| 100 | + | ||
| 101 | + assert(resetContents == currentCommitContents); | ||
| 102 | + assert(resetContents != previousCommitContents); | ||
| 103 | + }); | ||
| 104 | + }); | ||
| 105 | + | ||
| 106 | + it("can perform a soft reset", function() { | ||
| 107 | + var test = this; | ||
| 108 | + | ||
| 109 | + return Reset.reset(test.repo, test.previousCommit, Reset.TYPE.SOFT) | ||
| 110 | + .then(function() { | ||
| 111 | + return test.repo.openIndex(); | ||
| 112 | + }) | ||
| 113 | + .then(function(index) { | ||
| 114 | + return index.writeTree(); | ||
| 115 | + }) | ||
| 116 | + .then(function(oid) { | ||
| 117 | + return test.repo.getTree(oid); | ||
| 118 | + }) | ||
| 119 | + .then(function(tree) { | ||
| 120 | + return tree.getEntry(filePath); | ||
| 121 | + }) | ||
| 122 | + .then(function(entry) { | ||
| 123 | + return entry.getBlob(); | ||
| 124 | + }) | ||
| 125 | + .then(function(blob) { | ||
| 126 | + var currentCommitContents = test.currentCommitBlob.toString(); | ||
| 127 | + var previousCommitContents = test.previousCommitBlob.toString(); | ||
| 128 | + var resetContents = blob.toString(); | ||
| 129 | + | ||
| 130 | + // With a soft reset all of the changes should be in the index | ||
| 131 | + // still so the index should still == what we had at the current | ||
| 132 | + // commit and not the one we reset to | ||
| 133 | + assert(resetContents == currentCommitContents); | ||
| 134 | + assert(resetContents != previousCommitContents); | ||
| 135 | + | ||
| 136 | + return Reset.reset(test.repo, test.currentCommit, Reset.TYPE.HARD); | ||
| 137 | + }); | ||
| 138 | + }); | ||
| 139 | + | ||
| 140 | + it("can perform a mixed reset", function() { | ||
| 141 | + var test = this; | ||
| 142 | + | ||
| 143 | + return Reset.reset(test.repo, test.previousCommit, Reset.TYPE.MIXED) | ||
| 144 | + .then(function() { | ||
| 145 | + return test.repo.openIndex(); | ||
| 146 | + }) | ||
| 147 | + .then(function(index) { | ||
| 148 | + return index.writeTree(); | ||
| 149 | + }) | ||
| 150 | + .then(function(oid) { | ||
| 151 | + return test.repo.getTree(oid); | ||
| 152 | + }) | ||
| 153 | + .then(function(tree) { | ||
| 154 | + return tree.getEntry(filePath); | ||
| 155 | + }) | ||
| 156 | + .then(function(entry) { | ||
| 157 | + return entry.getBlob(); | ||
| 158 | + }) | ||
| 159 | + .then(function(blob) { | ||
| 160 | + var currentCommitContents = test.currentCommitBlob.toString(); | ||
| 161 | + var previousCommitContents = test.previousCommitBlob.toString(); | ||
| 162 | + var resetContents = blob.toString(); | ||
| 163 | + | ||
| 164 | + // With a mixed reset all of the changes should removed from the index | ||
| 165 | + // but still in the working directory. (i.e. unstaged) | ||
| 166 | + assert(resetContents != currentCommitContents); | ||
| 167 | + assert(resetContents == previousCommitContents); | ||
| 168 | + | ||
| 169 | + return fse.readFile(path.join(test.repo.workdir(), filePath)); | ||
| 170 | + }) | ||
| 171 | + .then(function(fileContents) { | ||
| 172 | + var currentCommitContents = test.currentCommitBlob.toString(); | ||
| 173 | + | ||
| 174 | + assert(fileContents == currentCommitContents); | ||
| 175 | + | ||
| 176 | + return Reset.reset(test.repo, test.currentCommit, Reset.TYPE.HARD); | ||
| 177 | + }); | ||
| 178 | + }); | ||
| 179 | + | ||
| 180 | + it("can perform a hard reset", function() { | ||
| 181 | + var test = this; | ||
| 182 | + | ||
| 183 | + return Reset.reset(test.repo, test.previousCommit, Reset.TYPE.HARD) | ||
| 184 | + .then(function() { | ||
| 185 | + return test.repo.openIndex(); | ||
| 186 | + }) | ||
| 187 | + .then(function(index) { | ||
| 188 | + return index.writeTree(); | ||
| 189 | + }) | ||
| 190 | + .then(function(oid) { | ||
| 191 | + return test.repo.getTree(oid); | ||
| 192 | + }) | ||
| 193 | + .then(function(tree) { | ||
| 194 | + return tree.getEntry(filePath); | ||
| 195 | + }) | ||
| 196 | + .then(function(entry) { | ||
| 197 | + return entry.getBlob(); | ||
| 198 | + }) | ||
| 199 | + .then(function(blob) { | ||
| 200 | + var currentCommitContents = test.currentCommitBlob.toString(); | ||
| 201 | + var previousCommitContents = test.previousCommitBlob.toString(); | ||
| 202 | + var resetContents = blob.toString(); | ||
| 203 | + | ||
| 204 | + // With a hard reset all of the changes should removed from the index | ||
| 205 | + // and also removed from the working directory | ||
| 206 | + assert(resetContents != currentCommitContents); | ||
| 207 | + assert(resetContents == previousCommitContents); | ||
| 208 | + | ||
| 209 | + return fse.readFile(path.join(test.repo.workdir(), filePath)); | ||
| 210 | + }) | ||
| 211 | + .then(function(fileContents) { | ||
| 212 | + var previousCommitContents = test.previousCommitBlob.toString(); | ||
| 213 | + | ||
| 214 | + assert(fileContents == previousCommitContents); | ||
| 215 | + | ||
| 216 | + return Reset.reset(test.repo, test.currentCommit, Reset.TYPE.HARD); | ||
| 75 | 217 | }); | |
| 76 | 218 | }); | |
| 77 | 219 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments