import { Logger } from "../../bll/utils/logger" ; import { CpProxy } from "../../bll/moduleproxies/cp-proxy" ; export class GetLocalBranchNameCommand { constructor ( private readonly workspaceRootPath , private readonly gitPath , private readonly cpProxy ) { } public async execute ( ) { const END_SPACES_REGEXP = /\s*$/ ; const getLocalBranchResult = await this . cpProxy . execAsync ( this . getCommand ( ) ) ; if ( ! getLocalBranchResult || ! getLocalBranchResult . stdout ) { Logger . logWarning ( `GetLocalBranchNameCommand#exec: result is empty` ) ; throw new Error ( "Can't determine a local branch name." ) ; } return getLocalBranchResult . stdout . toString ( ) . replace ( END_SPACES_REGEXP , "" ) ; } private getCommand ( ) { const builder = [ ] ; builder . push ( `"${ this . gitPath }"` ) ; builder . push ( `-C "${ this . workspaceRootPath }"` ) ; builder . push ( "rev-parse" ) ; builder . push ( "--abbrev-ref" ) ; builder . push ( "HEAD" ) ; return builder . join ( " " ) ; } }