Skip to content

Commit d8d739d

Browse files
committed
fix: handle consecutive-empty-files
1 parent 4bf6dff commit d8d739d

File tree

5 files changed

+79
-3
lines changed

5 files changed

+79
-3
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
diff --git a/content b/content
2+
new file mode 100644
3+
index 0000000..6b584e8
4+
--- /dev/null
5+
+++ b/content
6+
@@ -0,0 +1 @@
7+
+content
8+
\ No newline at end of file
9+
diff --git a/empty b/empty
10+
new file mode 100644
11+
index 0000000..e69de29
12+
diff --git a/empty2 b/empty2
13+
new file mode 100644
14+
index 0000000..e69de29

src/__tests__/__snapshots__/31.test.ts.snap

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
exports[`issue 31 parse \`31\` 1`] = `
44
{
55
"files": [
6+
{
7+
"chunks": [],
8+
"path": "var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/epicshop/diff/advanced-react-apis/04.01.solution/7h2jowvfi2q/index.test.tsx",
9+
"type": "AddedFile",
10+
},
611
{
712
"chunks": [
813
{
@@ -406,7 +411,7 @@ exports[`issue 31 parse \`31\` 1`] = `
406411
},
407412
],
408413
"path": "var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/epicshop/diff/advanced-react-apis/04.01.solution/7h2jowvfi2q/index.tsx",
409-
"type": "AddedFile",
414+
"type": "ChangedFile",
410415
},
411416
],
412417
"type": "GitDiff",
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`consecutive-empty-files parse \`consecutive-empty-files\` 1`] = `
4+
{
5+
"files": [
6+
{
7+
"chunks": [
8+
{
9+
"changes": [
10+
{
11+
"content": "content",
12+
"lineAfter": 1,
13+
"type": "AddedLine",
14+
},
15+
{
16+
"content": "No newline at end of file",
17+
"type": "MessageLine",
18+
},
19+
],
20+
"context": undefined,
21+
"fromFileRange": {
22+
"lines": 0,
23+
"start": 0,
24+
},
25+
"toFileRange": {
26+
"lines": 1,
27+
"start": 1,
28+
},
29+
"type": "Chunk",
30+
},
31+
],
32+
"path": "content",
33+
"type": "AddedFile",
34+
},
35+
{
36+
"chunks": [],
37+
"path": "empty",
38+
"type": "AddedFile",
39+
},
40+
{
41+
"chunks": [],
42+
"path": "empty2",
43+
"type": "AddedFile",
44+
},
45+
],
46+
"type": "GitDiff",
47+
}
48+
`;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { getFixture } from './test-utils';
2+
import parseGitDiff from '../parse-git-diff';
3+
4+
describe('consecutive-empty-files', () => {
5+
const fixture = getFixture('consecutive-empty-files');
6+
7+
it('parse `consecutive-empty-files`', () => {
8+
expect(parseGitDiff(fixture)).toMatchSnapshot();
9+
});
10+
});

src/parse-git-diff.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ function parseChunk(context: Context): AnyChunk | undefined {
210210

211211
function parseExtendedHeader(ctx: Context) {
212212
if (isComparisonInputLine(ctx.getCurLine())) {
213-
ctx.nextLine();
213+
return null;
214214
}
215215
const line = ctx.getCurLine();
216216
const type = ExtendedHeaderValues.find((v) => line.startsWith(v));
@@ -279,7 +279,6 @@ function parseChunkHeader(ctx: Context) {
279279
toFileRange: getRange(addStart, addLines),
280280
} as const;
281281
}
282-
283282
const [all, delStart, delLines, addStart, addLines, context] =
284283
normalChunkExec;
285284
ctx.nextLine();

0 commit comments

Comments
 (0)