|
| 1 | +var assert = require("assert"); |
| 2 | +var path = require("path"); |
| 3 | +var local = path.join.bind(path, __dirname); |
| 4 | + |
| 5 | +describe("Reset", function() { |
| 6 | + var Repository = require(local("../../lib/repository")); |
| 7 | + var Reset = require(local("../../lib/reset")); |
| 8 | + |
| 9 | + var reposPath = local("../repos/workdir/.git"); |
| 10 | + var currentCommitOid = "32789a79e71fbc9e04d3eff7425e1771eb595150"; |
| 11 | + var previousCommitOid = "c82fb078a192ea221c9f1093c64321c60d64aa0d"; |
| 12 | + var filePath = "package.json"; |
| 13 | + |
| 14 | + before(function() { |
| 15 | + var test = this; |
| 16 | + |
| 17 | + return Repository.open(reposPath) |
| 18 | + .then(function(repository) { |
| 19 | + test.repo = repository; |
| 20 | + |
| 21 | + return test.repo.getCommit(currentCommitOid); |
| 22 | + }) |
| 23 | + .then(function(commit) { |
| 24 | + test.currentCommit = commit; |
| 25 | + |
| 26 | + return commit.getEntry(filePath); |
| 27 | + }) |
| 28 | + .then(function(entry) { |
| 29 | + return entry.getBlob(); |
| 30 | + }) |
| 31 | + .then(function(blob) { |
| 32 | + test.currentCommitBlob = blob; |
| 33 | + |
| 34 | + return test.repo.getCommit(previousCommitOid); |
| 35 | + }) |
| 36 | + .then(function(commit) { |
| 37 | + test.previousCommit = commit; |
| 38 | + |
| 39 | + return commit.getEntry(filePath); |
| 40 | + }) |
| 41 | + .then(function(entry) { |
| 42 | + return entry.getBlob(); |
| 43 | + }) |
| 44 | + .then(function(blob) { |
| 45 | + test.previousCommitBlob = blob; |
| 46 | + }); |
| 47 | + }); |
| 48 | + |
| 49 | + it("can reset a file to a previous commit", function() { |
| 50 | + var test = this; |
| 51 | + |
| 52 | + return Reset.default(test.repo, test.previousCommit, filePath) |
| 53 | + .then(function() { |
| 54 | + return test.repo.openIndex(); |
| 55 | + }) |
| 56 | + .then(function(index) { |
| 57 | + return index.writeTree(); |
| 58 | + }) |
| 59 | + .then(function(oid) { |
| 60 | + return test.repo.getTree(oid); |
| 61 | + }) |
| 62 | + .then(function(tree) { |
| 63 | + return tree.getEntry(filePath); |
| 64 | + }) |
| 65 | + .then(function(entry) { |
| 66 | + return entry.getBlob(); |
| 67 | + }) |
| 68 | + .then(function(blob) { |
| 69 | + var currentCommitContents = test.currentCommitBlob.toString(); |
| 70 | + var previousCommitContents = test.previousCommitBlob.toString(); |
| 71 | + var resetContents = blob.toString(); |
| 72 | + |
| 73 | + assert(resetContents != currentCommitContents); |
| 74 | + assert(resetContents == previousCommitContents); |
| 75 | + }); |
| 76 | + }); |
| 77 | +}); |
0 commit comments