Skip to content

Commit

Permalink
Removes ignore-revs-file flag if blame will fail
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Nov 5, 2019
1 parent 31343b5 commit d959a2b
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/git/git.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
/* eslint-disable @typescript-eslint/camelcase */
import * as paths from 'path';
import * as fs from 'fs';
import * as iconv from 'iconv-lite';
import { GlyphChars } from '../constants';
import { Container } from '../container';
Expand Down Expand Up @@ -329,6 +330,8 @@ export namespace Git {
return git<string>({ cwd: repoPath, stdin: patch }, ...params);
}

const ignoreRevsFileMap = new Map<string, boolean>();

export async function blame(
repoPath: string | undefined,
fileName: string,
Expand All @@ -347,6 +350,38 @@ export namespace Git {
}
if (options.args != null) {
params.push(...options.args);

const index = params.indexOf('--ignore-revs-file');
if (index !== -1) {
// Ensure the version of Git supports the --ignore-revs-file flag, otherwise the blame will fail
let supported = Git.validateVersion(2, 23);
if (supported) {
let ignoreRevsFile = params[index + 1];
if (!paths.isAbsolute(ignoreRevsFile)) {
ignoreRevsFile = paths.join(repoPath || '', ignoreRevsFile);
}

const exists = ignoreRevsFileMap.get(ignoreRevsFile);
if (exists !== undefined) {
supported = exists;
} else {
// Ensure the specified --ignore-revs-file exists, otherwise the blame will fail
try {
supported = await new Promise(resolve =>
fs.exists(ignoreRevsFile, exists => resolve(exists))
);
} catch {
supported = false;
}

ignoreRevsFileMap.set(ignoreRevsFile, supported);
}
}

if (!supported) {
params.splice(index, 2);
}
}
}

let stdin;
Expand Down

0 comments on commit d959a2b

Please sign in to comment.