import { inject , injectable } from 'inversify' ; import { IApplicationShell } from '../../application/types' ; import { CommitDetails } from '../../common/types' ; import { IServiceContainer } from '../../ioc/types' ; import { IGitServiceFactory } from '../../types' ; import { ICommitViewerFactory } from '../../viewers/types' ; import { command } from '../registration' ; import { IGitCherryPickCommandHandler } from '../types' ; @ injectable ( ) export class GitCherryPickCommandHandler implements IGitCherryPickCommandHandler { constructor ( @ inject ( IServiceContainer ) private serviceContainer , @ inject ( ICommitViewerFactory ) private commitViewerFactory , @ inject ( IApplicationShell ) private applicationShell ) { } @ command ( 'git.commit.cherryPick' , IGitCherryPickCommandHandler ) public async cherryPickCommit ( commit , showPrompt = true ) { commit = commit ? commit : this . commitViewerFactory . getCommitViewer ( ) . selectedCommit ; const gitService = await this . serviceContainer . get < IGitServiceFactory > ( IGitServiceFactory ) . createGitService ( commit . workspaceFolder ) ; const currentBranch = gitService . getCurrentBranch ( ) ; const msg = `Cherry pick ${ commit . logEntry . hash . short } into ${ currentBranch }?` ; const yesNo = showPrompt ? await this . applicationShell . showQuickPick ( [ 'Yes' , 'No' ] , { placeHolder : msg } ) : 'Yes' ; if ( yesNo === undefined || yesNo === 'No' ) { return ; } gitService . cherryPick ( commit . logEntry . hash . full ) . catch ( err => { if ( typeof err === 'string' ) { this . applicationShell . showErrorMessage ( err ) ; } } ) ; } }