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