@@ -33,7 +33,6 @@ test.serial(
3333
3434 const actualRef = await gitUtils . getRef ( ) ;
3535 t . deepEqual ( actualRef , expectedRef ) ;
36- callback . restore ( ) ;
3736 } ) ;
3837 } ,
3938) ;
@@ -54,7 +53,6 @@ test.serial(
5453
5554 const actualRef = await gitUtils . getRef ( ) ;
5655 t . deepEqual ( actualRef , expectedRef ) ;
57- callback . restore ( ) ;
5856 } ) ;
5957 } ,
6058) ;
@@ -73,7 +71,6 @@ test.serial(
7371
7472 const actualRef = await gitUtils . getRef ( ) ;
7573 t . deepEqual ( actualRef , "refs/pull/1/head" ) ;
76- callback . restore ( ) ;
7774 } ) ;
7875 } ,
7976) ;
@@ -100,8 +97,6 @@ test.serial(
10097
10198 const actualRef = await gitUtils . getRef ( ) ;
10299 t . deepEqual ( actualRef , "refs/pull/2/merge" ) ;
103- callback . restore ( ) ;
104- getAdditionalInputStub . restore ( ) ;
105100 } ) ;
106101 } ,
107102) ;
@@ -161,7 +156,6 @@ test.serial(
161156 "Both 'ref' and 'sha' are required if one of them is provided." ,
162157 } ,
163158 ) ;
164- getAdditionalInputStub . restore ( ) ;
165159 } ) ;
166160 } ,
167161) ;
@@ -188,7 +182,6 @@ test.serial(
188182 "Both 'ref' and 'sha' are required if one of them is provided." ,
189183 } ,
190184 ) ;
191- getAdditionalInputStub . restore ( ) ;
192185 } ) ;
193186 } ,
194187) ;
@@ -242,7 +235,6 @@ test.serial("isAnalyzingDefaultBranch()", async (t) => {
242235 process . env [ "GITHUB_EVENT_NAME" ] = "schedule" ;
243236 process . env [ "GITHUB_REF" ] = "refs/heads/main" ;
244237 t . deepEqual ( await gitUtils . isAnalyzingDefaultBranch ( ) , false ) ;
245- getAdditionalInputStub . restore ( ) ;
246238 } ) ;
247239} ) ;
248240
@@ -254,8 +246,6 @@ test.serial("determineBaseBranchHeadCommitOid non-pullrequest", async (t) => {
254246 const result = await gitUtils . determineBaseBranchHeadCommitOid ( __dirname ) ;
255247 t . deepEqual ( result , undefined ) ;
256248 t . deepEqual ( 0 , infoStub . callCount ) ;
257-
258- infoStub . restore ( ) ;
259249} ) ;
260250
261251test . serial (
@@ -276,8 +266,6 @@ test.serial(
276266 "git call failed. Will calculate the base branch SHA on the server. Error: " +
277267 "The checkout path provided to the action does not appear to be a git repository." ,
278268 ) ;
279-
280- infoStub . restore ( ) ;
281269 } ,
282270) ;
283271
@@ -301,10 +289,27 @@ test.serial("determineBaseBranchHeadCommitOid other error", async (t) => {
301289 "The checkout path provided to the action does not appear to be a git repository." ,
302290 ) ,
303291 ) ;
304-
305- infoStub . restore ( ) ;
306292} ) ;
307293
294+ test . serial (
295+ "determineBaseBranchHeadCommitOid accepts SHA-256 OIDs" ,
296+ async ( t ) => {
297+ const mergeSha = "a" . repeat ( 64 ) ;
298+ const baseOid = "b" . repeat ( 64 ) ;
299+ const headOid = "c" . repeat ( 64 ) ;
300+
301+ process . env [ "GITHUB_EVENT_NAME" ] = "pull_request" ;
302+ process . env [ "GITHUB_SHA" ] = mergeSha ;
303+
304+ sinon
305+ . stub ( gitUtils as any , "runGitCommand" )
306+ . resolves ( `commit ${ mergeSha } \nparent ${ baseOid } \nparent ${ headOid } \n` ) ;
307+
308+ const result = await gitUtils . determineBaseBranchHeadCommitOid ( __dirname ) ;
309+ t . deepEqual ( result , baseOid ) ;
310+ } ,
311+ ) ;
312+
308313test . serial ( "decodeGitFilePath unquoted strings" , async ( t ) => {
309314 t . deepEqual ( gitUtils . decodeGitFilePath ( "foo" ) , "foo" ) ;
310315 t . deepEqual ( gitUtils . decodeGitFilePath ( "foo bar" ) , "foo bar" ) ;
@@ -436,6 +441,64 @@ test.serial("getFileOidsUnderPath handles quoted paths", async (t) => {
436441 } ) ;
437442} ) ;
438443
444+ test . serial ( "getFileOidsUnderPath handles SHA-256 OIDs" , async ( t ) => {
445+ await withTmpDir ( async ( tmpDir ) => {
446+ const sha256OidA =
447+ "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2c0d4b7e8f9a1234567890ab" ;
448+ const sha256OidB =
449+ "aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899" ;
450+
451+ sinon
452+ . stub ( gitUtils as any , "runGitCommand" )
453+ . callsFake ( async ( _cwd : any , args : any ) => {
454+ if ( args [ 0 ] === "rev-parse" ) {
455+ return `${ tmpDir } \n` ;
456+ }
457+ return (
458+ `100644 ${ sha256OidA } 0\tlib/sha256-file-a.js\n` +
459+ `100644 ${ sha256OidB } 0\tsrc/sha256-file-b.ts`
460+ ) ;
461+ } ) ;
462+
463+ const result = await gitUtils . getFileOidsUnderPath ( "/fake/path" ) ;
464+
465+ t . deepEqual ( result , {
466+ "lib/sha256-file-a.js" : sha256OidA ,
467+ "src/sha256-file-b.ts" : sha256OidB ,
468+ } ) ;
469+ } ) ;
470+ } ) ;
471+
472+ test . serial (
473+ "getFileOidsUnderPath rejects OIDs of unsupported length" ,
474+ async ( t ) => {
475+ await withTmpDir ( async ( tmpDir ) => {
476+ // 50-char OID: not a valid SHA-1 (40) or SHA-256 (64) length. The regex
477+ // must not accept this even though every character is a valid hex digit.
478+ const invalidLine =
479+ "100644 30d998ded095371488be3a729eb61d86ed721a1830d998ded0 0\tlib/bad.js" ;
480+ sinon
481+ . stub ( gitUtils as any , "runGitCommand" )
482+ . callsFake ( async ( _cwd : any , args : any ) => {
483+ if ( args [ 0 ] === "rev-parse" ) {
484+ return `${ tmpDir } \n` ;
485+ }
486+ return invalidLine ;
487+ } ) ;
488+
489+ await t . throwsAsync (
490+ async ( ) => {
491+ await gitUtils . getFileOidsUnderPath ( "/fake/path" ) ;
492+ } ,
493+ {
494+ instanceOf : Error ,
495+ message : `Unexpected "git ls-files" output: ${ invalidLine } ` ,
496+ } ,
497+ ) ;
498+ } ) ;
499+ } ,
500+ ) ;
501+
439502test . serial ( "getFileOidsUnderPath handles empty output" , async ( t ) => {
440503 await withTmpDir ( async ( tmpDir ) => {
441504 sinon
0 commit comments