import { ITfsWorkFoldInfo } from "./ITfsWorkFoldInfo" ; import { CpProxy } from "../../bll/moduleproxies/cp-proxy" ; import * as path from "path" ; import { Logger } from "../../bll/utils/logger" ; export class GetPrevResourceName { private static readonly PARSE_HISTORY_REGEXP : RegExp = /(\$.*)$/ ; constructor ( private readonly tfPath , private readonly tfsInfo , private readonly cpProxy ) { } public async execute ( fileAbsPath ) { const result = await this . cpProxy . execAsync ( this . getCommand ( fileAbsPath ) ) ; if ( ! result || ! result . stdout ) { return undefined ; } const historyRowsArray = result . stdout . trim ( ) . split ( "\n" ) ; const lastHistoryRow = historyRowsArray [ historyRowsArray . length - 1 ] ; const parsedLastHistoryRow = GetPrevResourceName . PARSE_HISTORY_REGEXP . exec ( lastHistoryRow ) ; if ( GetPrevResourceName . isInCorrectFormat ( parsedLastHistoryRow ) ) { const prevRelativePath = parsedLastHistoryRow [ 1 ] . replace ( this . tfsInfo . projectRemotePath , "" ) ; return path . join ( this . tfsInfo . projectLocalPath , prevRelativePath ) ; } Logger . logWarning ( `BriefDiffRowsParser: can't parse last history command row` ) ; return undefined ; } private getCommand ( fileAbsPath ) { return `"${ this . tfPath }" history /format:detailed /stopafter:1 ${ fileAbsPath }` ; } private static isInCorrectFormat ( parsedLastHistoryRow ) { return parsedLastHistoryRow && parsedLastHistoryRow . length === 2 ; } }