@@ -8,67 +8,61 @@ const exec = async (req: any, action: Action): Promise<Action> => {
8
8
try {
9
9
const repoPath = `${ action . proxyGitPath } /${ action . repoName } ` ;
10
10
11
- const introducedCommits = new Set < string > ( ) ;
12
-
13
- // Retrieve the single ref update
14
11
const oldOid = action . commitFrom ;
15
12
const newOid = action . commitTo ;
16
13
if ( ! oldOid || ! newOid ) {
17
14
throw new Error ( 'Both action.commitFrom and action.commitTo must be defined' ) ;
18
15
}
19
16
20
- const revisionRange : string =
17
+ // build introducedCommits set
18
+ const introducedCommits = new Set < string > ( ) ;
19
+ const revRange =
21
20
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 ( )
29
23
. split ( '\n' )
30
- . filter ( Boolean )
31
- . forEach ( ( sha ) => introducedCommits . add ( sha ) ) ;
24
+ . filter ( Boolean ) ;
25
+ revList . forEach ( ( sha ) => introducedCommits . add ( sha ) ) ;
32
26
step . log ( `Total introduced commits: ${ introducedCommits . size } ` ) ;
33
- const packPath = path . join ( '.git' , 'objects' , 'pack' ) ;
34
27
28
+ // build packCommits set
29
+ const packPath = path . join ( '.git' , 'objects' , 'pack' ) ;
35
30
const packCommits = new Set < string > ( ) ;
36
-
37
31
( action . newIdxFiles || [ ] ) . forEach ( ( idxFile ) => {
38
32
const idxPath = path . join ( packPath , idxFile ) ;
39
33
const out = spawnSync ( 'git' , [ 'verify-pack' , '-v' , idxPath ] , {
40
34
cwd : repoPath ,
41
35
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
+ } ) ;
51
43
} ) ;
52
- step . log ( `Commits nel pack: ${ packCommits . size } ` ) ;
53
- console . log ( 'Pack commits:' , packCommits ) ;
44
+ step . log ( `Total commits in the pack: ${ packCommits . size } ` ) ;
54
45
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 ) ) ;
61
52
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 } ` ) ;
64
55
65
- if ( unreferenced . length > 0 ) {
66
56
step . setError (
67
57
`Unreferenced commits in pack (${ unreferenced . length } ): ${ unreferenced . join ( ', ' ) } ` ,
68
58
) ;
69
59
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.` ) ;
70
65
}
71
- step . setContent ( `Referenced: ${ referenced . length } , Unreferenced: ${ unreferenced . length } ` ) ;
72
66
} catch ( e : any ) {
73
67
step . setError ( e . message ) ;
74
68
throw e ;
0 commit comments