import * as shell from './shell' ; param repositoryUrl param targetDir export function clone ( repositoryUrl , targetDir ) { const gitHubToken = process . env . GITHUB_TOKEN ; if ( ! gitHubToken ) { throw new Error ( 'GITHUB_TOKEN env variable is required' ) ; } shell . run ( `git clone https://${ gitHubToken }@${ repositoryUrl }.git ${ targetDir }` ) ; } return export function diffIndex ( ) { try { shell . run ( 'git diff-index --exit-code HEAD --' ) ; return false ; } catch ( err ) { return true ; } } param p export function add ( p ) { shell . run ( `git add ${ p }` ) ; } param message export function commit ( message ) { shell . run ( `git commit -m "${ message }"` ) ; } /**
 * Initialize a repository.
 */ export function init ( ) { shell . run ( 'git init' ) ; } param name returns export function tag ( name ) { try { shell . run ( `git tag -a ${ name } -m ${ name }` , { capture : true } ) ; return true ; } catch ( e ) { if ( e . message . includes ( 'already exists' ) ) { return false ; } throw e ; } } param ref export function push ( ref ) { shell . run ( `git push origin ${ ref }` ) ; } param branch param options export function checkout ( branch , options ) { if ( options . createIfMissing ) { try { shell . run ( `git show-branch origin/${ branch }` ) ; } catch ( e ) { if ( e instanceof Error && e . message . includes ( 'fatal: bad sha1 reference' ) ) { console . log ( 'Remote branch not found, creating new branch.' ) ; shell . run ( `git checkout -B ${ branch }` ) ; return ; } } } shell . run ( `git checkout ${ branch }` ) ; } /**
 * Fetch the configured git user name for the current directory.
 * Returns undefined if not configured.
 */ export function username ( ) { try { return shell . run ( 'git config user.name' , { capture : true } ) ; } catch ( err ) { console . warn ( err . message ) ; return undefined ; } } /**
 * Fetch the configured git user email for the current directory.
 * Returns undefined if not configured.
 */ export function email ( ) { try { return shell . run ( 'git config user.email' , { capture : true } ) ; } catch ( err ) { console . warn ( err . message ) ; return undefined ; } } param user param email export function identify ( user , address ) { shell . run ( `git config user.name "${ user }"` ) ; shell . run ( `git config user.email "${ address }"` ) ; }