import { Injectable , NgZone , OnDestroy } from '@angular/core' ; import { EOL } from 'os' ; import { from , Observable } from 'rxjs' ; import { GitCloneOptions , GitCommitOptions , GitFindRemoteOptions , GitGetHistoryOptions , GitGetHistoryResult , GitSetRemoteOptions , GitSyncWithRemoteOptions , GitSyncWithRemoteResult , } from '../../core/git' ; import { VcsAccount , VcsAuthenticationInfo , VcsFileChange } from '../../core/vcs' ; import { IpcActionClient } from '../../libs/ipc' ; import { enterZone } from '../../libs/rx' ; @ Injectable ( ) export class GitService implements OnDestroy { private ipcClient = new IpcActionClient ( 'git' ) ; constructor ( private ngZone ) { } ngOnDestroy ( ) { this . ipcClient . destroy ( ) ; } getFileChanges ( dirPath ) { return from ( this . ipcClient . performAction < string , VcsFileChange [ ] > ( 'getFileChanges' , dirPath ) ) . pipe ( enterZone ( this . ngZone ) ) ; } cloneRepository ( url , localPath , authentication ? ) { const task = this . ipcClient . performAction < GitCloneOptions , void > ( 'cloneRepository' , { url , localPath , authentication } ) ; return from ( task ) ; } commit ( workspaceDirPath , author , message , fileChanges ) { const options = { workspaceDirPath , author , message : `${ message . summary }${ EOL }${ EOL }${ message . description }` , fileChanges , } ; const commitTask = this . ipcClient . performAction < GitCommitOptions , string > ( 'commit' , options ) ; return from ( commitTask ) ; } getCommitHistory ( options ) { return from ( this . ipcClient . performAction < GitGetHistoryOptions , GitGetHistoryResult > ( 'getCommitHistory' , options ) ) ; } isRemoteExists ( options ) { return from ( this . ipcClient . performAction < GitFindRemoteOptions , boolean > ( 'isRemoteExists' , options ) ) ; } getRemoteUrl ( options ) { return from ( this . ipcClient . performAction < GitFindRemoteOptions , string > ( 'getRemoteUrl' , options ) ) ; } setRemote ( options ) { return from ( this . ipcClient . performAction < GitSetRemoteOptions , void > ( 'setRemote' , options ) ) ; } syncWithRemote ( options ) { return from ( this . ipcClient . performAction < GitSyncWithRemoteOptions , GitSyncWithRemoteResult > ( 'syncWithRemote' , options ) ) ; } }