| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ var fse = promisify(require("fs-extra")); | |||
| 5 | 5 | ||
| 6 | 6 | var exec = require("../../utils/execPromise"); | |
| 7 | 7 | ||
| 8 | - describe("Stage", function() { | ||
| 8 | + describe.only("Stage", function() { | ||
| 9 | 9 | var RepoUtils = require("../utils/repository_setup"); | |
| 10 | 10 | var NodeGit = require("../../"); | |
| 11 | 11 | var test; | |
@@ -25,7 +25,7 @@ describe("Stage", function() { | |||
| 25 | 25 | return fse.remove(test.repository.workdir()); | |
| 26 | 26 | }); | |
| 27 | 27 | ||
| 28 | - function stagingTest(staging, newFileContent) { | ||
| 28 | + function stagingTest(isUnstaged, newFileContent, discarding) { | ||
| 29 | 29 | var fileContent = newFileContent || | |
| 30 | 30 | "One line of text\n" + | |
| 31 | 31 | "Two lines of text\n"+ | |
@@ -48,13 +48,22 @@ describe("Stage", function() { | |||
| 48 | 48 | "Nineteen lines of text\n"+ | |
| 49 | 49 | "Twenty lines of text\n"; | |
| 50 | 50 | var fileName = "stagedLinesTest.txt"; | |
| 51 | - var stagedFile; | ||
| 51 | + var expectedContent; | ||
| 52 | 52 | var workingDirFile; | |
| 53 | 53 | var getDiffFunction; | |
| 54 | - if (staging) { | ||
| 55 | - stagedFile = fileContent.replace("Fifteen", "Changed fifteen"); | ||
| 56 | - workingDirFile = stagedFile.replace("Three", "Changed three") | ||
| 54 | + | ||
| 55 | + if (!isUnstaged || discarding) { | ||
| 56 | + expectedContent = fileContent.replace("Three", "Changed three") | ||
| 57 | 57 | .replace("Seventeen", "Changed seventeen"); | |
| 58 | + workingDirFile = expectedContent.replace("Fifteen", "Changed fifteen"); | ||
| 59 | + } | ||
| 60 | + else { | ||
| 61 | + expectedContent = fileContent.replace("Fifteen", "Changed fifteen"); | ||
| 62 | + workingDirFile = expectedContent.replace("Three", "Changed three") | ||
| 63 | + .replace("Seventeen", "Changed seventeen"); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + if (isUnstaged) { | ||
| 58 | 67 | getDiffFunction = function() { | |
| 59 | 68 | return test.repository.refreshIndex() | |
| 60 | 69 | .then(function(index) { | |
@@ -71,10 +80,6 @@ describe("Stage", function() { | |||
| 71 | 80 | }; | |
| 72 | 81 | } | |
| 73 | 82 | else { | |
| 74 | - stagedFile = fileContent.replace("Three", "Changed three") | ||
| 75 | - .replace("Seventeen", "Changed seventeen"); | ||
| 76 | - workingDirFile = stagedFile.replace("Fifteen", "Changed fifteen"); | ||
| 77 | - | ||
| 78 | 83 | getDiffFunction = function() { | |
| 79 | 84 | return RepoUtils.addFileToIndex(test.repository, fileName) | |
| 80 | 85 | .then(function() { | |
@@ -138,17 +143,28 @@ describe("Stage", function() { | |||
| 138 | 143 | } | |
| 139 | 144 | }); | |
| 140 | 145 | }); | |
| 141 | - return test.repository.stageLines(fileName, linesToStage, !staging); | ||
| 146 | + | ||
| 147 | + if (discarding) { | ||
| 148 | + return test.repository.discardLines(fileName, linesToStage); | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + return test.repository.stageLines(fileName, linesToStage, !isUnstaged); | ||
| 142 | 152 | }) | |
| 143 | 153 | .then(function() { | |
| 144 | - return test.repository.refreshIndex(); | ||
| 145 | - }) | ||
| 146 | - .then(function(reloadedIndex) { | ||
| 147 | - var pathOid = reloadedIndex.getByPath(fileName).id; | ||
| 148 | - return test.repository.getBlob(pathOid); | ||
| 154 | + if (discarding) { | ||
| 155 | + return fse.readFile( | ||
| 156 | + path.join(test.repository.workdir(), fileName), "utf8" | ||
| 157 | + ); | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + return test.repository.refreshIndex() | ||
| 161 | + .then(function(reloadedIndex) { | ||
| 162 | + var pathOid = reloadedIndex.getByPath(fileName).id; | ||
| 163 | + return test.repository.getBlob(pathOid); | ||
| 164 | + }); | ||
| 149 | 165 | }) | |
| 150 | 166 | .then(function(resultFileContents) { | |
| 151 | - assert.equal(resultFileContents.toString(), stagedFile); | ||
| 167 | + assert.equal(resultFileContents.toString(), expectedContent); | ||
| 152 | 168 | }); | |
| 153 | 169 | } | |
| 154 | 170 | ||
@@ -501,4 +517,8 @@ describe("Stage", function() { | |||
| 501 | 517 | return compareFilemodes(false, freshIndex, 0 /* expect nochange */); | |
| 502 | 518 | }); | |
| 503 | 519 | }); | |
| 520 | + | ||
| 521 | + it("can discard selected lines", function() { | ||
| 522 | + return stagingTest(true, null, true); | ||
| 523 | + }); | ||
| 504 | 524 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments