| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6c049ab commit 7ac4dc3
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,18 +1,21 @@ | |||
| 1 | 1 | var assert = require("assert"); | |
| 2 | 2 | var path = require("path"); | |
| 3 | - var fs = require("fs"); | ||
| 4 | - var exec = require("child_process").exec; | ||
| 3 | + var promisify = require("promisify-node"); | ||
| 4 | + var fse = promisify(require("fs-extra")); | ||
| 5 | 5 | var Diff = require("../../lib/diff"); | |
| 6 | 6 | ||
| 7 | 7 | describe("Diff", function() { | |
| 8 | + var Repository = require("../../lib/repository"); | ||
| 8 | 9 | var reposPath = path.resolve("test/repos/workdir/.git"); | |
| 9 | 10 | var oid = "fce88902e66c72b5b93e75bdb5ae717038b221f6"; | |
| 10 | - | ||
| 11 | - var Repository = require("../../lib/repository"); | ||
| 11 | + var diffFilename = "wddiff.txt"; | ||
| 12 | + var diffFilepath = path.join( | ||
| 13 | + path.resolve("test/repos/workdir"), | ||
| 14 | + diffFilename | ||
| 15 | + ); | ||
| 12 | 16 | ||
| 13 | 17 | before(function(done) { | |
| 14 | 18 | var test = this; | |
| 15 | - var newFilePath = path.join(path.resolve("test/repos/workdir"), "wddiff.txt"); | ||
| 16 | 19 | ||
| 17 | 20 | return Repository.open(reposPath).then(function(repository) { | |
| 18 | 21 | test.repository = repository; | |
@@ -27,13 +30,33 @@ describe("Diff", function() { | |||
| 27 | 30 | ||
| 28 | 31 | return commit.getDiff().then(function(diff) { | |
| 29 | 32 | test.diff = diff; | |
| 30 | - fs.writeFileSync(newFilePath, "1 line\n2 line\n3 line\n\n4"); | ||
| 31 | 33 | ||
| 32 | - exec("git add wddiff.txt", {cwd: path.resolve("test/repos/workdir")}, function() { | ||
| 33 | - Diff.treeToWorkdirWithIndex(test.repository, test.masterCommitTree, null) | ||
| 34 | + fse.writeFile(diffFilepath, "1 line\n2 line\n3 line\n\n4") | ||
| 35 | + .then(function() { | ||
| 36 | + return test.repository.openIndex(); | ||
| 37 | + }) | ||
| 38 | + .then(function(indexResult) { | ||
| 39 | + test.index = indexResult; | ||
| 40 | + return test.index.read(1); | ||
| 41 | + }) | ||
| 42 | + .then(function() { | ||
| 43 | + return test.index.addByPath(diffFilename); | ||
| 44 | + }) | ||
| 45 | + .then(function() { | ||
| 46 | + return test.index.write(); | ||
| 47 | + }) | ||
| 48 | + .then(function() { | ||
| 49 | + return test.index.writeTree(); | ||
| 50 | + }) | ||
| 51 | + .then(function() { | ||
| 52 | + Diff.treeToWorkdirWithIndex( | ||
| 53 | + test.repository, | ||
| 54 | + test.masterCommitTree, | ||
| 55 | + null | ||
| 56 | + ) | ||
| 34 | 57 | .then(function(workdirDiff) { | |
| 35 | - test.workdirDiff = workdirDiff; | ||
| 36 | - done(); | ||
| 58 | + test.workdirDiff = workdirDiff; | ||
| 59 | + done(); | ||
| 37 | 60 | }); | |
| 38 | 61 | }); | |
| 39 | 62 | }); | |
@@ -81,6 +104,9 @@ describe("Diff", function() { | |||
| 81 | 104 | assert.equal(hunks.length, 1); | |
| 82 | 105 | ||
| 83 | 106 | var lines = hunks[0].lines(); | |
| 84 | - assert.equal(lines[0].content().substr(0, lines[0].contentLen()), "1 line\n"); | ||
| 107 | + assert.equal( | ||
| 108 | + lines[0].content().substr(0, lines[0].contentLen()), | ||
| 109 | + "1 line\n" | ||
| 110 | + ); | ||
| 85 | 111 | }); | |
| 86 | 112 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments