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 { IGitMergeCommandHandler } from '../types' ; @ injectable ( ) export class GitMergeCommandHandler implements IGitMergeCommandHandler { constructor ( @ inject ( IServiceContainer ) private serviceContainer , @ inject ( ICommitViewerFactory ) private commitViewerFactory , @ inject ( IApplicationShell ) private applicationShell ) { } @ command ( 'git.commit.merge' , IGitMergeCommandHandler ) public async merge ( 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 commitBranches = gitService . getRefsContainingCommit ( commit . logEntry . hash . full ) . filter ( value => value . name ! . length > 0 ) . map ( x => x . name ! ) ; const branchMsg = `Choose the commit/branch to merge into ${ currentBranch }` ; const rev = await this . applicationShell . showQuickPick ( [ commit . logEntry . hash . full , ... commitBranches ] , { placeHolder : branchMsg , } ) ; let type ; if ( rev === undefined || rev . length === 0 ) { return ; } if ( rev === commit . logEntry . hash . full ) { type = 'commit' ; } else { type = 'branch' ; } const msg = `Merge ${ type } '${ rev }' into ${ currentBranch }?` ; const yesNo = showPrompt ? await this . applicationShell . showQuickPick ( [ 'Yes' , 'No' ] , { placeHolder : msg } ) : 'Yes' ; if ( yesNo === undefined || yesNo === 'No' ) { return ; } gitService . merge ( rev ) . catch ( err => { if ( typeof err === 'string' ) { this . applicationShell . showErrorMessage ( err ) ; } } ) ; } }