@@ -334,17 +334,15 @@ export class GitService extends Disposable {
334334 : await this . findNextFileNameCore ( repoPath , fileName , ref ) ;
335335 }
336336
337- private async findNextFileNameCore ( repoPath : string , fileName : string , sha ?: string ) : Promise < string | undefined > {
338- if ( sha === undefined ) {
337+ private async findNextFileNameCore ( repoPath : string , fileName : string , ref ?: string ) : Promise < string | undefined > {
338+ if ( ref === undefined ) {
339339 // Get the most recent commit for this file name
340- const c = await this . getRecentLogCommitForFile ( repoPath , fileName ) ;
341- if ( c === undefined ) return undefined ;
342-
343- sha = c . sha ;
340+ ref = await this . getRecentShaForFile ( repoPath , fileName ) ;
341+ if ( ref === undefined ) return undefined ;
344342 }
345343
346344 // Get the full commit (so we can see if there are any matching renames in the file statuses)
347- const log = await this . getLog ( repoPath , { maxCount : 1 , ref : sha } ) ;
345+ const log = await this . getLog ( repoPath , { maxCount : 1 , ref : ref } ) ;
348346 if ( log === undefined ) return undefined ;
349347
350348 const c = Iterables . first ( log . commits . values ( ) ) ;
@@ -354,28 +352,31 @@ export class GitService extends Disposable {
354352 return status . fileName ;
355353 }
356354
357- async findWorkingFileName ( commit : GitCommit ) : Promise < string | undefined > ;
358- async findWorkingFileName ( repoPath : string | undefined , fileName : string ) : Promise < string | undefined > ;
359- async findWorkingFileName ( commitOrRepoPath : GitCommit | string | undefined , fileName ?: string ) : Promise < string | undefined > {
360- let repoPath : string | undefined ;
361- if ( commitOrRepoPath === undefined || typeof commitOrRepoPath === 'string' ) {
362- repoPath = commitOrRepoPath ;
363- if ( fileName === undefined ) throw new Error ( 'Invalid fileName' ) ;
355+ async findWorkingFileName ( commit : GitCommit ) : Promise < [ string | undefined , string | undefined ] > ;
356+ async findWorkingFileName ( fileName : string , repoPath ?: string , ref ?: string ) : Promise < [ string | undefined , string | undefined ] > ;
357+ async findWorkingFileName ( commitOrFileName : GitCommit | string , repoPath ?: string , ref ?: string ) : Promise < [ string | undefined , string | undefined ] > {
358+ let fileName ;
359+ if ( typeof commitOrFileName === 'string' ) {
360+ fileName = commitOrFileName ;
361+ if ( repoPath === undefined ) {
362+ repoPath = await this . getRepoPath ( fileName , { ref : ref } ) ;
363+ [ fileName , repoPath ] = Git . splitPath ( fileName , repoPath ) ;
364+ }
364365
365- [ fileName ] = Git . splitPath ( fileName , repoPath ) ;
366366 }
367367 else {
368- const c = commitOrRepoPath ;
368+ const c = commitOrFileName ;
369369 repoPath = c . repoPath ;
370- if ( c . workingFileName && await this . fileExists ( repoPath , c . workingFileName ) ) return c . workingFileName ;
370+ if ( c . workingFileName && await this . fileExists ( repoPath , c . workingFileName ) ) return [ c . workingFileName , repoPath ] ;
371371 fileName = c . fileName ;
372372 }
373373
374+ // Keep walking up to the most recent commit for a given filename, until it exists on disk
374375 while ( true ) {
375- if ( await this . fileExists ( repoPath ! , fileName ) ) return fileName ;
376+ if ( await this . fileExists ( repoPath , fileName ) ) return [ fileName , repoPath ] ;
376377
377- fileName = await this . findNextFileNameCore ( repoPath ! , fileName ) ;
378- if ( fileName === undefined ) return undefined ;
378+ fileName = await this . findNextFileNameCore ( repoPath , fileName ) ;
379+ if ( fileName === undefined ) return [ undefined , undefined ] ;
379380 }
380381 }
381382
@@ -823,6 +824,10 @@ export class GitService extends Disposable {
823824 return this . getLogCommitForFile ( repoPath , fileName , undefined ) ;
824825 }
825826
827+ async getRecentShaForFile ( repoPath : string , fileName : string ) {
828+ return await Git . log_recent ( repoPath , fileName ) ;
829+ }
830+
826831 async getLogCommit ( repoPath : string , ref : string ) : Promise < GitLogCommit | undefined > {
827832 Logger . log ( `getLogCommit('${ repoPath } ', '${ ref } '` ) ;
828833
0 commit comments