@@ -8,67 +8,61 @@ const exec = async (req: any, action: Action): Promise<Action> => {
88 try {
99 const repoPath = `${ action . proxyGitPath } /${ action . repoName } ` ;
1010
11- const introducedCommits = new Set < string > ( ) ;
12-
13- // Retrieve the single ref update
1411 const oldOid = action . commitFrom ;
1512 const newOid = action . commitTo ;
1613 if ( ! oldOid || ! newOid ) {
1714 throw new Error ( 'Both action.commitFrom and action.commitTo must be defined' ) ;
1815 }
1916
20- const revisionRange : string =
17+ // build introducedCommits set
18+ const introducedCommits = new Set < string > ( ) ;
19+ const revRange =
2120 oldOid === '0000000000000000000000000000000000000000' ? newOid : `${ oldOid } ..${ newOid } ` ;
22-
23- const revListOutput = spawnSync ( 'git' , [ 'rev-list' , revisionRange ] , {
24- cwd : repoPath ,
25- encoding : 'utf-8' ,
26- } ) . stdout ;
27- revListOutput
28- . trim ( )
21+ const revList = spawnSync ( 'git' , [ 'rev-list' , revRange ] , { cwd : repoPath , encoding : 'utf-8' } )
22+ . stdout . trim ( )
2923 . split ( '\n' )
30- . filter ( Boolean )
31- . forEach ( ( sha ) => introducedCommits . add ( sha ) ) ;
24+ . filter ( Boolean ) ;
25+ revList . forEach ( ( sha ) => introducedCommits . add ( sha ) ) ;
3226 step . log ( `Total introduced commits: ${ introducedCommits . size } ` ) ;
33- const packPath = path . join ( '.git' , 'objects' , 'pack' ) ;
3427
28+ // build packCommits set
29+ const packPath = path . join ( '.git' , 'objects' , 'pack' ) ;
3530 const packCommits = new Set < string > ( ) ;
36-
3731 ( action . newIdxFiles || [ ] ) . forEach ( ( idxFile ) => {
3832 const idxPath = path . join ( packPath , idxFile ) ;
3933 const out = spawnSync ( 'git' , [ 'verify-pack' , '-v' , idxPath ] , {
4034 cwd : repoPath ,
4135 encoding : 'utf-8' ,
42- } ) . stdout ;
43-
44- out
45- . trim ( )
46- . split ( '\n' )
47- . forEach ( ( line ) => {
48- const [ sha , type ] = line . split ( / \s + / ) ;
49- if ( type === 'commit' ) packCommits . add ( sha ) ;
50- } ) ;
36+ } )
37+ . stdout . trim ( )
38+ . split ( '\n' ) ;
39+ out . forEach ( ( line ) => {
40+ const [ sha , type ] = line . split ( / \s + / ) ;
41+ if ( type === 'commit' ) packCommits . add ( sha ) ;
42+ } ) ;
5143 } ) ;
52- step . log ( `Commits nel pack: ${ packCommits . size } ` ) ;
53- console . log ( 'Pack commits:' , packCommits ) ;
44+ step . log ( `Total commits in the pack: ${ packCommits . size } ` ) ;
5445
55- const referenced : string [ ] = [ ] ;
56- const unreferenced : string [ ] = [ ] ;
57- [ ... packCommits ] . forEach ( ( sha ) => {
58- if ( introducedCommits . has ( sha ) ) referenced . push ( sha ) ;
59- else unreferenced . push ( sha ) ;
60- } ) ;
46+ // subset check
47+ const isSubset = [ ... packCommits ] . every ( ( sha ) => introducedCommits . has ( sha ) ) ;
48+ if ( ! isSubset ) {
49+ // build detailed lists
50+ const unreferenced = [ ... packCommits ] . filter ( ( sha ) => ! introducedCommits . has ( sha ) ) ;
51+ const referenced = [ ... packCommits ] . filter ( ( sha ) => introducedCommits . has ( sha ) ) ;
6152
62- step . log ( `✅ Referenced commits: ${ referenced . length } ` ) ;
63- step . log ( `❌ Unreferenced commits: ${ unreferenced . length } ` ) ;
53+ step . log ( `✅ Referenced commits: ${ referenced . length } ` ) ;
54+ step . log ( `❌ Unreferenced commits: ${ unreferenced . length } ` ) ;
6455
65- if ( unreferenced . length > 0 ) {
6656 step . setError (
6757 `Unreferenced commits in pack (${ unreferenced . length } ): ${ unreferenced . join ( ', ' ) } ` ,
6858 ) ;
6959 action . error = true ;
60+ step . setContent ( `Referenced: ${ referenced . length } , Unreferenced: ${ unreferenced . length } ` ) ;
61+ } else {
62+ // all good, no logging of individual SHAs needed
63+ step . log ( 'All pack commits are referenced in the introduced range.' ) ;
64+ step . setContent ( `All ${ packCommits . size } pack commits are within introduced commits.` ) ;
7065 }
71- step . setContent ( `Referenced: ${ referenced . length } , Unreferenced: ${ unreferenced . length } ` ) ;
7266 } catch ( e : any ) {
7367 step . setError ( e . message ) ;
7468 throw e ;
0 commit comments