@@ -17,11 +17,12 @@ import {
17
17
} from './__fixtures__' ;
18
18
import { SimpleGit , StatusResult } from '../../typings' ;
19
19
import { parseStatusSummary , StatusSummary } from '../../src/lib/responses/StatusSummary' ;
20
+ import { NULL } from '../../src/lib/utils' ;
20
21
21
22
describe ( 'status' , ( ) => {
22
23
let git : SimpleGit ;
23
24
let callback : jest . Mock ;
24
- let statusCommands = ( ...extras : string [ ] ) => [ 'status' , '--porcelain' , '-b' , '-u' , ...extras ] ;
25
+ let statusCommands = ( ...extras : string [ ] ) => [ 'status' , '--porcelain' , '-b' , '-u' , '--null' , ...extras ] ;
25
26
26
27
beforeEach ( ( ) => callback = jest . fn ( ) ) ;
27
28
@@ -62,6 +63,13 @@ describe('status', () => {
62
63
63
64
beforeEach ( ( ) => git = newSimpleGit ( ) ) ;
64
65
66
+ it ( 'ignores explicit --null option' , async ( ) => {
67
+ git . status ( [ '-a' , '--null' , '-b' , '-z' , '-c' ] ) ;
68
+ await closeWithSuccess ( ) ;
69
+
70
+ assertExecutedCommands ( ...statusCommands ( '-a' , '-b' , '-c' ) ) ;
71
+ } ) ;
72
+
65
73
it ( 'throws errors to the rejection handler' , async ( ) => {
66
74
const queue = git . status ( ) ;
67
75
await closeWithError ( 'unknown' ) ;
@@ -145,6 +153,20 @@ describe('status', () => {
145
153
} ) )
146
154
} ) ;
147
155
156
+ it ( 'Handles files with non ascii names' , ( ) => {
157
+ expect ( parseStatusSummary ( statusResponse ( 'main' , stagedModified ( '😀 file.ext' ) ) . stdOut ) ) . toEqual ( like ( {
158
+ current : 'main' ,
159
+ modified : [ '😀 file.ext' ] ,
160
+ } ) ) ;
161
+ } ) ;
162
+
163
+ it ( 'Handles files with spaces in their names' , ( ) => {
164
+ expect ( parseStatusSummary ( statusResponse ( 'main' , stagedModified ( 'foo bar.ext' ) ) . stdOut ) ) . toEqual ( like ( {
165
+ current : 'main' ,
166
+ modified : [ 'foo bar.ext' ] ,
167
+ } ) ) ;
168
+ } ) ;
169
+
148
170
it ( 'Handles ignored files' , ( ) => {
149
171
expect ( parseStatusSummary ( statusResponse ( 'main' , stagedIgnored ) . stdOut ) ) . toEqual ( like ( {
150
172
...empty ,
@@ -196,22 +218,18 @@ describe('status', () => {
196
218
} ) ;
197
219
198
220
it ( 'Initial repo with no commits' , ( ) => {
199
- const statusSummary = parseStatusSummary ( `
200
- ## No commits yet on master
201
- ` ) ;
221
+ const statusSummary = parseStatusSummary ( `## No commits yet on master` ) ;
202
222
203
223
expect ( statusSummary ) . toEqual ( like ( {
204
224
current : `master`
205
225
} ) )
206
226
} ) ;
207
227
208
228
it ( 'Complex status - renamed, new and un-tracked modifications' , ( ) => {
209
- const statusSummary = parseStatusSummary ( `
210
- ## master
211
- M other.txt
212
- A src/b.txt
213
- R src/a.txt -> src/c.txt
214
- ` ) ;
229
+ const statusSummary = parseStatusSummary ( statusResponse ( 'master' ,
230
+ ' M other.txt' ,
231
+ 'A src/b.txt' ,
232
+ 'R src/a.txt -> src/c.txt' ) . stdOut ) ;
215
233
216
234
expect ( statusSummary ) . toEqual ( like ( {
217
235
created : [ 'src/b.txt' ] ,
@@ -264,20 +282,23 @@ R src/a.txt -> src/c.txt
264
282
} ) ) ;
265
283
} ) ;
266
284
267
- it ( 'parses status - with untracked' , ( ) => {
268
- expect ( parseStatusSummary ( '?? Not tracked File\nUU Conflicted\n D Removed' ) ) . toEqual ( like ( {
269
- not_added : [ 'Not tracked File' ] ,
270
- conflicted : [ 'Conflicted' ] ,
271
- deleted : [ 'Removed' ] ,
272
- } ) ) ;
273
- } ) ;
274
-
275
- it ( 'parses status - modified, added and added-changed' , ( ) => {
276
- expect ( parseStatusSummary ( ' M Modified\n A Added\nAM Changed' ) ) . toEqual ( like ( {
277
- modified : [ 'Modified' , 'Changed' ] ,
278
- created : [ 'Added' , 'Changed' ] ,
279
- } ) ) ;
280
- } ) ;
285
+ it . each < [ string , any ] > ( [
286
+ [ '?? Not tracked File' , { not_added : [ 'Not tracked File' ] } ] ,
287
+ [ 'UU Conflicted' , { conflicted : [ 'Conflicted' ] } ] ,
288
+ [ ' D Removed' , { deleted : [ 'Removed' ] } ] ,
289
+ [ ' M Modified' , { modified : [ 'Modified' ] } ] ,
290
+ [ ' A Added' , { created : [ 'Added' ] } ] ,
291
+ [ 'AM Changed' , { created : [ 'Changed' ] , modified : [ 'Changed' ] } ] ,
292
+ ] ) ( 'parses file status - %s' , ( file , result ) => {
293
+ expect ( parseStatusSummary ( statusResponse ( 'branch' , file ) . stdOut ) ) . toEqual ( like ( {
294
+ modified : [ ] ,
295
+ created : [ ] ,
296
+ not_added : [ ] ,
297
+ conflicted : [ ] ,
298
+ deleted : [ ] ,
299
+ ...result ,
300
+ } ) )
301
+ } )
281
302
282
303
it ( 'parses status' , ( ) => {
283
304
expect ( parseStatusSummary ( statusResponse ( 'this_branch' ) . stdOut ) ) . toEqual ( like ( {
@@ -291,7 +312,7 @@ R src/a.txt -> src/c.txt
291
312
} ) ;
292
313
293
314
it ( 'allows isClean to be destructured' , ( ) => {
294
- const { isClean } = parseStatusSummary ( '\n' ) ;
315
+ const { isClean} = parseStatusSummary ( '\n' ) ;
295
316
expect ( isClean ( ) ) . toBe ( true ) ;
296
317
} ) ;
297
318
@@ -309,41 +330,23 @@ R src/a.txt -> src/c.txt
309
330
} ) ;
310
331
311
332
it ( 'staged modified files identified separately to other modified files' , ( ) => {
312
- const statusSummary = parseStatusSummary ( `
313
- ## master
314
- M aaa
315
- M bbb
316
- A ccc
317
- ?? ddd
318
- ` ) ;
333
+ const statusSummary = parseStatusSummary ( `## master${ NULL } M aaa${ NULL } M bbb${ NULL } A ccc${ NULL } ?? ddd` ) ;
319
334
expect ( statusSummary ) . toEqual ( like ( {
320
335
staged : [ 'bbb' , 'ccc' ] ,
321
336
modified : [ 'aaa' , 'bbb' ] ,
322
337
} ) ) ;
323
338
} ) ;
324
339
325
340
it ( 'staged modified file with modifications after staging' , ( ) => {
326
- const statusSummary = parseStatusSummary ( `
327
- ## master
328
- MM staged-modified
329
- M modified
330
- M staged
331
- ` ) ;
341
+ const statusSummary = parseStatusSummary ( `## master${ NULL } MM staged-modified${ NULL } M modified${ NULL } M staged` ) ;
332
342
expect ( statusSummary ) . toEqual ( like ( {
333
343
staged : [ 'staged-modified' , 'staged' ] ,
334
344
modified : [ 'staged-modified' , 'modified' , 'staged' ] ,
335
345
} ) ) ;
336
346
} ) ;
337
347
338
348
it ( 'modified status' , ( ) => {
339
- const statusSummary = parseStatusSummary ( `
340
- M package.json
341
- M src/git.js
342
- AM src/index.js
343
- A src/newfile.js
344
- ?? test
345
- UU test.js
346
- ` ) ;
349
+ const statusSummary = parseStatusSummary ( ` M package.json${ NULL } M src/git.js${ NULL } AM src/index.js${ NULL } A src/newfile.js${ NULL } ?? test${ NULL } UU test.js` ) ;
347
350
348
351
expect ( statusSummary ) . toEqual ( like ( {
349
352
created : [ 'src/index.js' , 'src/newfile.js' ] ,
@@ -356,10 +359,8 @@ R src/a.txt -> src/c.txt
356
359
} ) ;
357
360
358
361
it ( 'index/wd status' , ( ) => {
359
- const statusSummary = parseStatusSummary ( ` M src/git_wd.js
360
- MM src/git_ind_wd.js
361
- M src/git_ind.js
362
- ` ) ;
362
+ const statusSummary = parseStatusSummary ( statusResponse ( 'main' ,
363
+ ` M src/git_wd.js` , `MM src/git_ind_wd.js` , `M src/git_ind.js` ) . stdOut ) ;
363
364
expect ( statusSummary ) . toEqual ( like ( {
364
365
files : [
365
366
{ path : 'src/git_wd.js' , index : ' ' , working_dir : 'M' } ,
@@ -370,21 +371,16 @@ M src/git_ind.js
370
371
} ) ;
371
372
372
373
it ( 'Report conflict when both sides have added the same file' , ( ) => {
373
- expect ( parseStatusSummary ( `## master\nAA filename`) ) . toEqual ( like ( {
374
+ expect ( parseStatusSummary ( statusResponse ( ` master` , `AA filename`) . stdOut ) ) . toEqual ( like ( {
374
375
conflicted : [ 'filename' ] ,
375
376
} ) ) ;
376
377
} ) ;
377
378
378
379
it ( 'Report all types of merge conflict statuses' , ( ) => {
379
- const statusSummary = parseStatusSummary ( `
380
- UU package.json
381
- DD src/git.js
382
- DU src/index.js
383
- UD src/newfile.js
384
- AU test.js
385
- UA test
386
- AA test-foo.js
387
- ` ) ;
380
+ const statusSummary = parseStatusSummary ( statusResponse ( 'branch' ,
381
+ 'UU package.json' , 'DD src/git.js' , 'DU src/index.js' ,
382
+ 'UD src/newfile.js' , 'AU test.js' , 'UA test' , 'AA test-foo.js'
383
+ ) . stdOut ) ;
388
384
389
385
expect ( statusSummary ) . toEqual ( like ( {
390
386
conflicted : [ 'package.json' , 'src/git.js' , 'src/index.js' , 'src/newfile.js' , 'test.js' , 'test' , 'test-foo.js' ]
0 commit comments