1- import exec from '. /exec'
1+ import { getExecOutput } from '@actions /exec'
22import * as core from '@actions/core'
33import { File , ChangeStatus } from './file'
44
@@ -9,7 +9,7 @@ export async function getChangesInLastCommit(): Promise<File[]> {
99 core . startGroup ( `Change detection in last commit` )
1010 let output = ''
1111 try {
12- output = ( await exec ( 'git' , [ 'log' , '--format=' , '--no-renames' , '--name-status' , '-z' , '-n' , '1' ] ) ) . stdout
12+ output = ( await getExecOutput ( 'git' , [ 'log' , '--format=' , '--no-renames' , '--name-status' , '-z' , '-n' , '1' ] ) ) . stdout
1313 } finally {
1414 fixStdOutNullTermination ( )
1515 core . endGroup ( )
@@ -27,7 +27,8 @@ export async function getChanges(base: string, head: string): Promise<File[]> {
2727 let output = ''
2828 try {
2929 // Two dots '..' change detection - directly compares two versions
30- output = ( await exec ( 'git' , [ 'diff' , '--no-renames' , '--name-status' , '-z' , `${ baseRef } ..${ headRef } ` ] ) ) . stdout
30+ output = ( await getExecOutput ( 'git' , [ 'diff' , '--no-renames' , '--name-status' , '-z' , `${ baseRef } ..${ headRef } ` ] ) )
31+ . stdout
3132 } finally {
3233 fixStdOutNullTermination ( )
3334 core . endGroup ( )
@@ -41,7 +42,7 @@ export async function getChangesOnHead(): Promise<File[]> {
4142 core . startGroup ( `Change detection on HEAD` )
4243 let output = ''
4344 try {
44- output = ( await exec ( 'git' , [ 'diff' , '--no-renames' , '--name-status' , '-z' , 'HEAD' ] ) ) . stdout
45+ output = ( await getExecOutput ( 'git' , [ 'diff' , '--no-renames' , '--name-status' , '-z' , 'HEAD' ] ) ) . stdout
4546 } finally {
4647 fixStdOutNullTermination ( )
4748 core . endGroup ( )
@@ -57,7 +58,7 @@ export async function getChangesSinceMergeBase(base: string, head: string, initi
5758 if ( baseRef === undefined || headRef === undefined ) {
5859 return false
5960 }
60- return ( await exec ( 'git' , [ 'merge-base' , baseRef , headRef ] , { ignoreReturnCode : true } ) ) . code === 0
61+ return ( await getExecOutput ( 'git' , [ 'merge-base' , baseRef , headRef ] , { ignoreReturnCode : true } ) ) . exitCode === 0
6162 }
6263
6364 let noMergeBase = false
@@ -66,12 +67,12 @@ export async function getChangesSinceMergeBase(base: string, head: string, initi
6667 baseRef = await getLocalRef ( base )
6768 headRef = await getLocalRef ( head )
6869 if ( ! ( await hasMergeBase ( ) ) ) {
69- await exec ( 'git' , [ 'fetch' , '--no-tags' , `--depth=${ initialFetchDepth } ` , 'origin' , base , head ] )
70+ await getExecOutput ( 'git' , [ 'fetch' , '--no-tags' , `--depth=${ initialFetchDepth } ` , 'origin' , base , head ] )
7071 if ( baseRef === undefined || headRef === undefined ) {
7172 baseRef = baseRef ?? ( await getLocalRef ( base ) )
7273 headRef = headRef ?? ( await getLocalRef ( head ) )
7374 if ( baseRef === undefined || headRef === undefined ) {
74- await exec ( 'git' , [ 'fetch' , '--tags' , '--depth=1' , 'origin' , base , head ] , {
75+ await getExecOutput ( 'git' , [ 'fetch' , '--tags' , '--depth=1' , 'origin' , base , head ] , {
7576 ignoreReturnCode : true // returns exit code 1 if tags on remote were updated - we can safely ignore it
7677 } )
7778 baseRef = baseRef ?? ( await getLocalRef ( base ) )
@@ -93,12 +94,12 @@ export async function getChangesSinceMergeBase(base: string, head: string, initi
9394 let lastCommitCount = await getCommitCount ( )
9495 while ( ! ( await hasMergeBase ( ) ) ) {
9596 depth = Math . min ( depth * 2 , Number . MAX_SAFE_INTEGER )
96- await exec ( 'git' , [ 'fetch' , `--deepen=${ depth } ` , 'origin' , base , head ] )
97+ await getExecOutput ( 'git' , [ 'fetch' , `--deepen=${ depth } ` , 'origin' , base , head ] )
9798 const commitCount = await getCommitCount ( )
9899 if ( commitCount === lastCommitCount ) {
99100 core . info ( 'No more commits were fetched' )
100101 core . info ( 'Last attempt will be to fetch full history' )
101- await exec ( 'git' , [ 'fetch' ] )
102+ await getExecOutput ( 'git' , [ 'fetch' ] )
102103 if ( ! ( await hasMergeBase ( ) ) ) {
103104 noMergeBase = true
104105 }
@@ -122,7 +123,7 @@ export async function getChangesSinceMergeBase(base: string, head: string, initi
122123 core . startGroup ( `Change detection ${ diffArg } ` )
123124 let output = ''
124125 try {
125- output = ( await exec ( 'git' , [ 'diff' , '--no-renames' , '--name-status' , '-z' , diffArg ] ) ) . stdout
126+ output = ( await getExecOutput ( 'git' , [ 'diff' , '--no-renames' , '--name-status' , '-z' , diffArg ] ) ) . stdout
126127 } finally {
127128 fixStdOutNullTermination ( )
128129 core . endGroup ( )
@@ -147,7 +148,7 @@ export async function listAllFilesAsAdded(): Promise<File[]> {
147148 core . startGroup ( 'Listing all files tracked by git' )
148149 let output = ''
149150 try {
150- output = ( await exec ( 'git' , [ 'ls-files' , '-z' ] ) ) . stdout
151+ output = ( await getExecOutput ( 'git' , [ 'ls-files' , '-z' ] ) ) . stdout
151152 } finally {
152153 fixStdOutNullTermination ( )
153154 core . endGroup ( )
@@ -165,17 +166,17 @@ export async function listAllFilesAsAdded(): Promise<File[]> {
165166export async function getCurrentRef ( ) : Promise < string > {
166167 core . startGroup ( `Get current git ref` )
167168 try {
168- const branch = ( await exec ( 'git' , [ 'branch' , '--show-current' ] ) ) . stdout . trim ( )
169+ const branch = ( await getExecOutput ( 'git' , [ 'branch' , '--show-current' ] ) ) . stdout . trim ( )
169170 if ( branch ) {
170171 return branch
171172 }
172173
173- const describe = await exec ( 'git' , [ 'describe' , '--tags' , '--exact-match' ] , { ignoreReturnCode : true } )
174- if ( describe . code === 0 ) {
174+ const describe = await getExecOutput ( 'git' , [ 'describe' , '--tags' , '--exact-match' ] , { ignoreReturnCode : true } )
175+ if ( describe . exitCode === 0 ) {
175176 return describe . stdout . trim ( )
176177 }
177178
178- return ( await exec ( 'git' , [ 'rev-parse' , HEAD ] ) ) . stdout . trim ( )
179+ return ( await getExecOutput ( 'git' , [ 'rev-parse' , HEAD ] ) ) . stdout . trim ( )
179180 } finally {
180181 core . endGroup ( )
181182 }
@@ -198,11 +199,11 @@ export function isGitSha(ref: string): boolean {
198199}
199200
200201async function hasCommit ( ref : string ) : Promise < boolean > {
201- return ( await exec ( 'git' , [ 'cat-file' , '-e' , `${ ref } ^{commit}` ] , { ignoreReturnCode : true } ) ) . code === 0
202+ return ( await getExecOutput ( 'git' , [ 'cat-file' , '-e' , `${ ref } ^{commit}` ] , { ignoreReturnCode : true } ) ) . exitCode === 0
202203}
203204
204205async function getCommitCount ( ) : Promise < number > {
205- const output = ( await exec ( 'git' , [ 'rev-list' , '--count' , '--all' ] ) ) . stdout
206+ const output = ( await getExecOutput ( 'git' , [ 'rev-list' , '--count' , '--all' ] ) ) . stdout
206207 const count = parseInt ( output )
207208 return isNaN ( count ) ? 0 : count
208209}
@@ -212,7 +213,7 @@ async function getLocalRef(shortName: string): Promise<string | undefined> {
212213 return ( await hasCommit ( shortName ) ) ? shortName : undefined
213214 }
214215
215- const output = ( await exec ( 'git' , [ 'show-ref' , shortName ] , { ignoreReturnCode : true } ) ) . stdout
216+ const output = ( await getExecOutput ( 'git' , [ 'show-ref' , shortName ] , { ignoreReturnCode : true } ) ) . stdout
216217 const refs = output
217218 . split ( / \r ? \n / g)
218219 . map ( l => l . match ( / r e f s \/ (?: (?: h e a d s ) | (?: t a g s ) | (?: r e m o t e s \/ o r i g i n ) ) \/ ( .* ) $ / ) )
@@ -236,10 +237,10 @@ async function ensureRefAvailable(name: string): Promise<string> {
236237 try {
237238 let ref = await getLocalRef ( name )
238239 if ( ref === undefined ) {
239- await exec ( 'git' , [ 'fetch' , '--depth=1' , '--no-tags' , 'origin' , name ] )
240+ await getExecOutput ( 'git' , [ 'fetch' , '--depth=1' , '--no-tags' , 'origin' , name ] )
240241 ref = await getLocalRef ( name )
241242 if ( ref === undefined ) {
242- await exec ( 'git' , [ 'fetch' , '--depth=1' , '--tags' , 'origin' , name ] )
243+ await getExecOutput ( 'git' , [ 'fetch' , '--depth=1' , '--tags' , 'origin' , name ] )
243244 ref = await getLocalRef ( name )
244245 if ( ref === undefined ) {
245246 throw new Error ( `Could not determine what is ${ name } - fetch works but it's not a branch, tag or commit SHA` )
0 commit comments