const util = require ( 'util' ) ; const exec = util . promisify ( require ( 'child_process' ) . exec ) ; import { getWorkspaceFolder } from './workspace' ; export class Git { static exists ( ) { return this . execute ( getWorkspaceFolder ( ) , '' , [ '--version' ] ) ; } static async add ( ) { const { stdout : changes } = await this . diff ( [ '--cached' ] ) ; if ( changes . length === 0 ) { return this . execute ( getWorkspaceFolder ( ) , 'add' , [ `--all` ] ) ; } } static async commit ( message , options ) { return this . execute ( getWorkspaceFolder ( ) , 'commit' , [ `--message="${ message }"` , ... options ] ) ; } static execute ( cwd , command ? , options = [ ] ) { return exec ( `git ${ command } ${ options . join ( ' ' ) }` , { cwd } ) ; } private static async diff ( options = [ ] ) { return this . execute ( getWorkspaceFolder ( ) , 'diff' , [ ... options ] ) ; } }