@@ -3,7 +3,7 @@ import * as path from "path"
3
3
4
4
import { spawnSafeSync } from "../src/spawnSafe"
5
5
import { executeEffects } from "../src/patch/apply"
6
- import { parsePatch } from "../src/patch/parse"
6
+ import { parsePatchFile } from "../src/patch/parse"
7
7
import { reversePatch } from "../src/patch/reverse"
8
8
9
9
import { TestCase , Files } from "./testCases"
@@ -38,6 +38,11 @@ jest.mock("fs-extra", () => {
38
38
getWorkingFiles ( ) [ to ] = getWorkingFiles ( ) [ from ]
39
39
delete getWorkingFiles ( ) [ from ]
40
40
} ) ,
41
+ statSync : jest . fn ( path => getWorkingFiles ( ) [ path ] ) ,
42
+ chmodSync : jest . fn ( ( path , mode ) => {
43
+ const { contents } = getWorkingFiles ( ) [ path ]
44
+ getWorkingFiles ( ) [ path ] = { contents, mode }
45
+ } ) ,
41
46
}
42
47
} )
43
48
@@ -85,12 +90,14 @@ export function executeTestCase(testCase: TestCase) {
85
90
writeFiles ( tmpDir . name , testCase . cleanFiles )
86
91
87
92
spawnSafeSync ( "git" , [ "add" , "-A" ] , { cwd : tmpDir . name } )
88
- spawnSafeSync ( "git" , [ "commit" , "-m" , "blah" ] , {
89
- cwd : tmpDir . name ,
90
- } )
91
- spawnSafeSync ( "git" , [ "rm" , "-rf" , "*" ] , {
93
+ spawnSafeSync ( "git" , [ "commit" , "--allow-empty" , "-m" , "blah" ] , {
92
94
cwd : tmpDir . name ,
93
95
} )
96
+ if ( Object . keys ( testCase . cleanFiles ) . length > 0 ) {
97
+ spawnSafeSync ( "git" , [ "rm" , "-rf" , "*" ] , {
98
+ cwd : tmpDir . name ,
99
+ } )
100
+ }
94
101
95
102
writeFiles ( tmpDir . name , testCase . modifiedFiles )
96
103
spawnSafeSync ( "git" , [ "add" , "-A" ] , { cwd : tmpDir . name } )
@@ -113,8 +120,8 @@ export function executeTestCase(testCase: TestCase) {
113
120
114
121
it ( "looks the same whether parsed with blank lines or not" , ( ) => {
115
122
reportingFailures ( ( ) => {
116
- expect ( parsePatch ( patchFileContents ) ) . toEqual (
117
- parsePatch ( patchFileContentsWithBlankLines ) ,
123
+ expect ( parsePatchFile ( patchFileContents ) ) . toEqual (
124
+ parsePatchFile ( patchFileContentsWithBlankLines ) ,
118
125
)
119
126
} )
120
127
} )
@@ -124,7 +131,7 @@ export function executeTestCase(testCase: TestCase) {
124
131
it ( "works forwards" , ( ) => {
125
132
fs . setWorkingFiles ( { ...testCase . cleanFiles } )
126
133
reportingFailures ( ( ) => {
127
- const effects = parsePatch ( patchFileContents )
134
+ const effects = parsePatchFile ( patchFileContents )
128
135
executeEffects ( effects , { dryRun : false } )
129
136
expect ( fs . getWorkingFiles ( ) ) . toEqual ( testCase . modifiedFiles )
130
137
} )
@@ -133,7 +140,7 @@ export function executeTestCase(testCase: TestCase) {
133
140
it ( "works backwards" , ( ) => {
134
141
fs . setWorkingFiles ( { ...testCase . modifiedFiles } )
135
142
reportingFailures ( ( ) => {
136
- const effects = reversePatch ( parsePatch ( patchFileContents ) )
143
+ const effects = reversePatch ( parsePatchFile ( patchFileContents ) )
137
144
executeEffects ( effects , { dryRun : false } )
138
145
expect ( fs . getWorkingFiles ( ) ) . toEqual ( testCase . cleanFiles )
139
146
} )
0 commit comments