11'use strict' ;
22/* eslint-disable @typescript-eslint/camelcase */
33import * as paths from 'path' ;
4+ import * as fs from 'fs' ;
45import * as iconv from 'iconv-lite' ;
56import { GlyphChars } from '../constants' ;
67import { Container } from '../container' ;
@@ -329,6 +330,8 @@ export namespace Git {
329330 return git < string > ( { cwd : repoPath , stdin : patch } , ...params ) ;
330331 }
331332
333+ const ignoreRevsFileMap = new Map < string , boolean > ( ) ;
334+
332335 export async function blame (
333336 repoPath : string | undefined ,
334337 fileName : string ,
@@ -347,6 +350,38 @@ export namespace Git {
347350 }
348351 if ( options . args != null ) {
349352 params . push ( ...options . args ) ;
353+
354+ const index = params . indexOf ( '--ignore-revs-file' ) ;
355+ if ( index !== - 1 ) {
356+ // Ensure the version of Git supports the --ignore-revs-file flag, otherwise the blame will fail
357+ let supported = Git . validateVersion ( 2 , 23 ) ;
358+ if ( supported ) {
359+ let ignoreRevsFile = params [ index + 1 ] ;
360+ if ( ! paths . isAbsolute ( ignoreRevsFile ) ) {
361+ ignoreRevsFile = paths . join ( repoPath || '' , ignoreRevsFile ) ;
362+ }
363+
364+ const exists = ignoreRevsFileMap . get ( ignoreRevsFile ) ;
365+ if ( exists !== undefined ) {
366+ supported = exists ;
367+ } else {
368+ // Ensure the specified --ignore-revs-file exists, otherwise the blame will fail
369+ try {
370+ supported = await new Promise ( resolve =>
371+ fs . exists ( ignoreRevsFile , exists => resolve ( exists ) )
372+ ) ;
373+ } catch {
374+ supported = false ;
375+ }
376+
377+ ignoreRevsFileMap . set ( ignoreRevsFile , supported ) ;
378+ }
379+ }
380+
381+ if ( ! supported ) {
382+ params . splice ( index , 2 ) ;
383+ }
384+ }
350385 }
351386
352387 let stdin ;
0 commit comments