1- import * as exec from './exec' ;
1+ import * as mexec from './exec' ;
2+ import * as exec from '@actions/exec' ;
23
34export const defaults = {
45 targetBranch : 'gh-pages' ,
@@ -7,51 +8,51 @@ export const defaults = {
78 message : 'Deploy to GitHub pages'
89} ;
910
10- const git = async ( args : string [ ] = [ ] ) : Promise < string > = > {
11- return await exec . exec ( ` git` , args , true ) . then ( res => {
11+ export async function remoteBranchExists ( remoteURL : string , branch : string ) : Promise < boolean > {
12+ return await mexec . exec ( ' git' , [ 'ls-remote' , '--heads' , remoteURL , branch ] , true ) . then ( res => {
1213 if ( res . stderr != '' && ! res . success ) {
1314 throw new Error ( res . stderr ) ;
1415 }
15- return res . stdout . trim ( ) ;
16- } ) ;
17- } ;
18-
19- export async function remoteBranchExists ( remoteURL : string , branch : string ) : Promise < boolean > {
20- return await git ( [ 'ls-remote' , '--heads' , remoteURL , branch ] ) . then ( output => {
21- return output . trim ( ) . length > 0 ;
16+ return res . stdout . trim ( ) . length > 0 ;
2217 } ) ;
2318}
2419
2520export async function clone ( remoteURL : string , branch : string , dest : string ) : Promise < void > {
26- await git ( [ 'clone' , '--quiet' , '--branch' , branch , '--depth' , '1' , remoteURL , dest ] ) ;
21+ await exec . exec ( 'git' , [ 'clone' , '--quiet' , '--branch' , branch , '--depth' , '1' , remoteURL , dest ] ) ;
2722}
2823
2924export async function init ( dest : string ) : Promise < void > {
30- await git ( [ 'init' , dest ] ) ;
25+ await exec . exec ( 'git' , [ 'init' , dest ] ) ;
3126}
3227
3328export async function checkout ( branch : string ) : Promise < void > {
34- await git ( [ 'checkout' , '--orphan' , branch ] ) ;
29+ await exec . exec ( 'git' , [ 'checkout' , '--orphan' , branch ] ) ;
3530}
3631
3732export async function isDirty ( ) : Promise < boolean > {
38- return await git ( [ 'status' , '--short' ] ) . then ( output => {
39- return output . trim ( ) . length > 0 ;
33+ return await mexec . exec ( 'git' , [ 'status' , '--short' ] , true ) . then ( res => {
34+ if ( res . stderr != '' && ! res . success ) {
35+ throw new Error ( res . stderr ) ;
36+ }
37+ return res . stdout . trim ( ) . length > 0 ;
4038 } ) ;
4139}
4240
4341export async function hasChanges ( ) : Promise < boolean > {
44- return await git ( [ 'status' , '--porcelain' ] ) . then ( output => {
45- return output . trim ( ) . length > 0 ;
42+ return await mexec . exec ( 'git' , [ 'status' , '--porcelain' ] , true ) . then ( res => {
43+ if ( res . stderr != '' && ! res . success ) {
44+ throw new Error ( res . stderr ) ;
45+ }
46+ return res . stdout . trim ( ) . length > 0 ;
4647 } ) ;
4748}
4849
4950export async function setConfig ( key : string , value : string ) : Promise < void > {
50- await git ( [ 'config' , key , value ] ) ;
51+ await exec . exec ( 'git' , [ 'config' , key , value ] ) ;
5152}
5253
5354export async function add ( pattern : string ) : Promise < void > {
54- await git ( [ 'add' , '--all' , pattern ] ) ;
55+ await exec . exec ( 'git' , [ 'add' , '--all' , pattern ] ) ;
5556}
5657
5758export async function commit ( allowEmptyCommit : boolean , author : string , message : string ) : Promise < void > {
@@ -64,12 +65,15 @@ export async function commit(allowEmptyCommit: boolean, author: string, message:
6465 args . push ( '--author' , author ) ;
6566 }
6667 args . push ( '--message' , message ) ;
67- await git ( args ) ;
68+ await exec . exec ( 'git' , args ) ;
6869}
6970
7071export async function showStat ( ) : Promise < string > {
71- return await git ( [ 'show' , `--stat-count=2000` , 'HEAD' ] ) . then ( output => {
72- return output ;
72+ return await mexec . exec ( 'git' , [ 'show' , `--stat-count=2000` , 'HEAD' ] , true ) . then ( res => {
73+ if ( res . stderr != '' && ! res . success ) {
74+ throw new Error ( res . stderr ) ;
75+ }
76+ return res . stdout . trim ( ) ;
7377 } ) ;
7478}
7579
@@ -80,5 +84,5 @@ export async function push(remoteURL: string, branch: string, force: boolean): P
8084 args . push ( '--force' ) ;
8185 }
8286 args . push ( remoteURL , branch ) ;
83- await git ( args ) ;
87+ await exec . exec ( 'git' , args ) ;
8488}
0 commit comments