@@ -315,147 +315,109 @@ test("getFileOidsUnderPath returns correct file mapping", async (t) => {
315315 "a47c11f5bfdca7661942d2c8f1b7209fb0dfdf96_src/git-utils.ts" ,
316316 ) ;
317317
318- try {
319- const result = await gitUtils . getFileOidsUnderPath ( "/fake/path" ) ;
320-
321- t . deepEqual ( result , {
322- "lib/git-utils.js" : "30d998ded095371488be3a729eb61d86ed721a18" ,
323- "lib/git-utils.js.map" : "d89514599a9a99f22b4085766d40af7b99974827" ,
324- "src/git-utils.ts" : "a47c11f5bfdca7661942d2c8f1b7209fb0dfdf96" ,
325- } ) ;
326-
327- t . deepEqual ( runGitCommandStub . firstCall . args , [
328- "/fake/path" ,
329- [ "ls-files" , "--recurse-submodules" , "--format=%(objectname)_%(path)" ] ,
330- "Cannot list Git OIDs of tracked files." ,
331- ] ) ;
332- } finally {
333- runGitCommandStub . restore ( ) ;
334- }
318+ const result = await gitUtils . getFileOidsUnderPath ( "/fake/path" ) ;
319+
320+ t . deepEqual ( result , {
321+ "lib/git-utils.js" : "30d998ded095371488be3a729eb61d86ed721a18" ,
322+ "lib/git-utils.js.map" : "d89514599a9a99f22b4085766d40af7b99974827" ,
323+ "src/git-utils.ts" : "a47c11f5bfdca7661942d2c8f1b7209fb0dfdf96" ,
324+ } ) ;
325+
326+ t . deepEqual ( runGitCommandStub . firstCall . args , [
327+ "/fake/path" ,
328+ [ "ls-files" , "--recurse-submodules" , "--format=%(objectname)_%(path)" ] ,
329+ "Cannot list Git OIDs of tracked files." ,
330+ ] ) ;
335331} ) ;
336332
337333test ( "getFileOidsUnderPath handles quoted paths" , async ( t ) => {
338- const runGitCommandStub = sinon
334+ sinon
339335 . stub ( gitUtils as any , "runGitCommand" )
340336 . resolves (
341337 "30d998ded095371488be3a729eb61d86ed721a18_lib/normal-file.js\n" +
342338 'd89514599a9a99f22b4085766d40af7b99974827_"lib/file with spaces.js"\n' +
343339 'a47c11f5bfdca7661942d2c8f1b7209fb0dfdf96_"lib/file\\twith\\ttabs.js"' ,
344340 ) ;
345341
346- try {
347- const result = await gitUtils . getFileOidsUnderPath ( "/fake/path" ) ;
348-
349- t . deepEqual ( result , {
350- "lib/normal-file.js" : "30d998ded095371488be3a729eb61d86ed721a18" ,
351- "lib/file with spaces.js" : "d89514599a9a99f22b4085766d40af7b99974827" ,
352- "lib/file\twith\ttabs.js" : "a47c11f5bfdca7661942d2c8f1b7209fb0dfdf96" ,
353- } ) ;
354- } finally {
355- runGitCommandStub . restore ( ) ;
356- }
342+ const result = await gitUtils . getFileOidsUnderPath ( "/fake/path" ) ;
343+
344+ t . deepEqual ( result , {
345+ "lib/normal-file.js" : "30d998ded095371488be3a729eb61d86ed721a18" ,
346+ "lib/file with spaces.js" : "d89514599a9a99f22b4085766d40af7b99974827" ,
347+ "lib/file\twith\ttabs.js" : "a47c11f5bfdca7661942d2c8f1b7209fb0dfdf96" ,
348+ } ) ;
357349} ) ;
358350
359351test ( "getFileOidsUnderPath handles empty output" , async ( t ) => {
360- const runGitCommandStub = sinon
361- . stub ( gitUtils as any , "runGitCommand" )
362- . resolves ( "" ) ;
363-
364- try {
365- const result = await gitUtils . getFileOidsUnderPath ( "/fake/path" ) ;
366- t . deepEqual ( result , { } ) ;
367- } finally {
368- runGitCommandStub . restore ( ) ;
369- }
352+ sinon . stub ( gitUtils as any , "runGitCommand" ) . resolves ( "" ) ;
353+
354+ const result = await gitUtils . getFileOidsUnderPath ( "/fake/path" ) ;
355+ t . deepEqual ( result , { } ) ;
370356} ) ;
371357
372358test ( "getFileOidsUnderPath throws on unexpected output format" , async ( t ) => {
373- const runGitCommandStub = sinon
359+ sinon
374360 . stub ( gitUtils as any , "runGitCommand" )
375361 . resolves (
376362 "30d998ded095371488be3a729eb61d86ed721a18_lib/git-utils.js\n" +
377363 "invalid-line-format\n" +
378364 "a47c11f5bfdca7661942d2c8f1b7209fb0dfdf96_src/git-utils.ts" ,
379365 ) ;
380366
381- try {
382- await t . throwsAsync (
383- async ( ) => {
384- await gitUtils . getFileOidsUnderPath ( "/fake/path" ) ;
385- } ,
386- {
387- instanceOf : Error ,
388- message : 'Unexpected "git ls-files" output: invalid-line-format' ,
389- } ,
390- ) ;
391- } finally {
392- runGitCommandStub . restore ( ) ;
393- }
367+ await t . throwsAsync (
368+ async ( ) => {
369+ await gitUtils . getFileOidsUnderPath ( "/fake/path" ) ;
370+ } ,
371+ {
372+ instanceOf : Error ,
373+ message : 'Unexpected "git ls-files" output: invalid-line-format' ,
374+ } ,
375+ ) ;
394376} ) ;
395377
396378test ( "getGitVersionOrThrow returns version for valid git output" , async ( t ) => {
397- const runGitCommandStub = sinon
398- . stub ( gitUtils as any , "runGitCommand" )
399- . resolves ( "git version 2.40.0\n" ) ;
400-
401- try {
402- const version = await gitUtils . getGitVersionOrThrow ( ) ;
403- t . is ( version , "2.40.0" ) ;
404- } finally {
405- runGitCommandStub . restore ( ) ;
406- }
379+ sinon . stub ( gitUtils as any , "runGitCommand" ) . resolves ( "git version 2.40.0\n" ) ;
380+
381+ const version = await gitUtils . getGitVersionOrThrow ( ) ;
382+ t . is ( version , "2.40.0" ) ;
407383} ) ;
408384
409385test ( "getGitVersionOrThrow throws for invalid git output" , async ( t ) => {
410- const runGitCommandStub = sinon
411- . stub ( gitUtils as any , "runGitCommand" )
412- . resolves ( "invalid output" ) ;
413-
414- try {
415- await t . throwsAsync (
416- async ( ) => {
417- await gitUtils . getGitVersionOrThrow ( ) ;
418- } ,
419- {
420- instanceOf : Error ,
421- message : "Could not parse Git version from output: invalid output" ,
422- } ,
423- ) ;
424- } finally {
425- runGitCommandStub . restore ( ) ;
426- }
386+ sinon . stub ( gitUtils as any , "runGitCommand" ) . resolves ( "invalid output" ) ;
387+
388+ await t . throwsAsync (
389+ async ( ) => {
390+ await gitUtils . getGitVersionOrThrow ( ) ;
391+ } ,
392+ {
393+ instanceOf : Error ,
394+ message : "Could not parse Git version from output: invalid output" ,
395+ } ,
396+ ) ;
427397} ) ;
428398
429399test ( "getGitVersionOrThrow handles Windows-style git output" , async ( t ) => {
430- const runGitCommandStub = sinon
400+ sinon
431401 . stub ( gitUtils as any , "runGitCommand" )
432402 . resolves ( "git version 2.40.0.windows.1\n" ) ;
433403
434- try {
435- const version = await gitUtils . getGitVersionOrThrow ( ) ;
436- // Should extract just the major.minor.patch portion
437- t . is ( version , "2.40.0" ) ;
438- } finally {
439- runGitCommandStub . restore ( ) ;
440- }
404+ const version = await gitUtils . getGitVersionOrThrow ( ) ;
405+ // Should extract just the major.minor.patch portion
406+ t . is ( version , "2.40.0" ) ;
441407} ) ;
442408
443409test ( "getGitVersionOrThrow throws when git command fails" , async ( t ) => {
444- const runGitCommandStub = sinon
410+ sinon
445411 . stub ( gitUtils as any , "runGitCommand" )
446412 . rejects ( new Error ( "git not found" ) ) ;
447413
448- try {
449- await t . throwsAsync (
450- async ( ) => {
451- await gitUtils . getGitVersionOrThrow ( ) ;
452- } ,
453- {
454- instanceOf : Error ,
455- message : "git not found" ,
456- } ,
457- ) ;
458- } finally {
459- runGitCommandStub . restore ( ) ;
460- }
414+ await t . throwsAsync (
415+ async ( ) => {
416+ await gitUtils . getGitVersionOrThrow ( ) ;
417+ } ,
418+ {
419+ instanceOf : Error ,
420+ message : "git not found" ,
421+ } ,
422+ ) ;
461423} ) ;
0 commit comments