Skip to content

Commit d959a2b

Browse files
committed
Removes ignore-revs-file flag if blame will fail
1 parent 31343b5 commit d959a2b

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/git/git.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22
/* eslint-disable @typescript-eslint/camelcase */
33
import * as paths from 'path';
4+
import * as fs from 'fs';
45
import * as iconv from 'iconv-lite';
56
import { GlyphChars } from '../constants';
67
import { 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

Comments
 (0)