diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e4033c..4a4cae9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ## [Unreleased] ### Added - Adds an indicator to the *GitLens* explorer's branch history to mark the the tips of all branches +- Adds `gitlens.advanced.blame.customArguments` setting to specify additional arguments to pass to the `git blame` command — closes [#337](https://github.com/eamodio/vscode-gitlens/issues/337) ### Changed - Changes the author name to "You" when appropriate — closes [#341](https://github.com/eamodio/vscode-gitlens/issues/341) diff --git a/README.md b/README.md index 7bd5f52..0476f09 100644 --- a/README.md +++ b/README.md @@ -691,6 +691,7 @@ See also [Explorer Settings](#explorer-settings "Jump to the Explorer settings") |Name | Description |-----|------------ +|`gitlens.advanced.blame.customArguments`|Specifies additional arguments to pass to the `git blame` command |`gitlens.advanced.blame.delayAfterEdit`|Specifies the time (in milliseconds) to wait before re-blaming an unsaved document after an edit. Use 0 to specify an infinite wait |`gitlens.advanced.blame.sizeThresholdAfterEdit`|Specifies the maximum document size (in lines) allowed to be re-blamed after an edit while still unsaved. Use 0 to specify no maximum |`gitlens.advanced.caching.enabled`|Specifies whether git output will be cached — changing the default is not recommended diff --git a/package.json b/package.json index 1427a75..93e19d1 100644 --- a/package.json +++ b/package.json @@ -809,6 +809,12 @@ "description": "Specifies the string to be shown in place of the `authors` code lens when there are unsaved changes", "scope": "window" }, + "gitlens.advanced.blame.customArguments": { + "type": "string[]", + "default": null, + "description": "Specifies additional arguments to pass to the `git blame` command", + "scope": "resource" + }, "gitlens.advanced.blame.delayAfterEdit": { "type": "number", "default": 5000, diff --git a/src/git/git.ts b/src/git/git.ts index 5d0fc9d..b34edee 100644 --- a/src/git/git.ts +++ b/src/git/git.ts @@ -267,7 +267,7 @@ export class Git { // Git commands - static async blame(repoPath: string | undefined, fileName: string, sha?: string, options: { ignoreWhitespace?: boolean, startLine?: number, endLine?: number } = {}) { + static async blame(repoPath: string | undefined, fileName: string, sha?: string, options: { args?: string[] | null, ignoreWhitespace?: boolean, startLine?: number, endLine?: number } = {}) { const [file, root] = Git.splitPath(fileName, repoPath); const params = [...defaultBlameParams]; @@ -278,6 +278,9 @@ export class Git { if (options.startLine != null && options.endLine != null) { params.push(`-L ${options.startLine},${options.endLine}`); } + if (options.args != null) { + params.push(...options.args); + } let stdin; if (sha) { @@ -296,7 +299,7 @@ export class Git { return gitCommand({ cwd: root, stdin: stdin }, ...params, '--', file); } - static async blame_contents(repoPath: string | undefined, fileName: string, contents: string, options: { correlationKey?: string, ignoreWhitespace?: boolean, startLine?: number, endLine?: number } = {}) { + static async blame_contents(repoPath: string | undefined, fileName: string, contents: string, options: { args?: string[] | null, correlationKey?: string, ignoreWhitespace?: boolean, startLine?: number, endLine?: number } = {}) { const [file, root] = Git.splitPath(fileName, repoPath); const params = [...defaultBlameParams]; @@ -307,6 +310,9 @@ export class Git { if (options.startLine != null && options.endLine != null) { params.push(`-L ${options.startLine},${options.endLine}`); } + if (options.args != null) { + params.push(...options.args); + } // Pipe the blame contents to stdin params.push('--contents', '-'); diff --git a/src/gitService.ts b/src/gitService.ts index 18638cf..261ae9a 100644 --- a/src/gitService.ts +++ b/src/gitService.ts @@ -456,7 +456,15 @@ export class GitService extends Disposable { const [file, root] = Git.splitPath(uri.fsPath, uri.repoPath, false); try { - const data = await Git.blame(root, file, uri.sha, { ignoreWhitespace: Container.config.blame.ignoreWhitespace }); + const data = await Git.blame( + root, + file, + uri.sha, + { + args: Container.config.advanced.blame.customArguments, + ignoreWhitespace: Container.config.blame.ignoreWhitespace + } + ); const blame = GitBlameParser.parse(data, root, file, await this.getCurrentUsername(root)); return blame; } @@ -525,7 +533,16 @@ export class GitService extends Disposable { const [file, root] = Git.splitPath(uri.fsPath, uri.repoPath, false); try { - const data = await Git.blame_contents(root, file, contents, { correlationKey: `:${key}`, ignoreWhitespace: Container.config.blame.ignoreWhitespace }); + const data = await Git.blame_contents( + root, + file, + contents, + { + args: Container.config.advanced.blame.customArguments, + correlationKey: `:${key}`, + ignoreWhitespace: Container.config.blame.ignoreWhitespace + } + ); const blame = GitBlameParser.parse(data, root, file, await this.getCurrentUsername(root)); return blame; } @@ -575,7 +592,17 @@ export class GitService extends Disposable { const fileName = uri.fsPath; try { - const data = await Git.blame(uri.repoPath, fileName, uri.sha, { ignoreWhitespace: Container.config.blame.ignoreWhitespace, startLine: lineToBlame, endLine: lineToBlame }); + const data = await Git.blame( + uri.repoPath, + fileName, + uri.sha, + { + args: Container.config.advanced.blame.customArguments, + ignoreWhitespace: Container.config.blame.ignoreWhitespace, + startLine: lineToBlame, + endLine: lineToBlame + } + ); const blame = GitBlameParser.parse(data, uri.repoPath, fileName, await this.getCurrentUsername(uri.repoPath!)); if (blame === undefined) return undefined; @@ -617,7 +644,17 @@ export class GitService extends Disposable { const fileName = uri.fsPath; try { - const data = await Git.blame_contents(uri.repoPath, fileName, contents, { ignoreWhitespace: Container.config.blame.ignoreWhitespace, startLine: lineToBlame, endLine: lineToBlame }); + const data = await Git.blame_contents( + uri.repoPath, + fileName, + contents, + { + args: Container.config.advanced.blame.customArguments, + ignoreWhitespace: Container.config.blame.ignoreWhitespace, + startLine: lineToBlame, + endLine: lineToBlame + } + ); const currentUser = await this.getCurrentUsername(uri.repoPath!); const blame = GitBlameParser.parse(data, uri.repoPath, fileName, currentUser); if (blame === undefined) return undefined; diff --git a/src/ui/config.ts b/src/ui/config.ts index 67e27ce..cc6b25c 100644 --- a/src/ui/config.ts +++ b/src/ui/config.ts @@ -103,6 +103,7 @@ export enum StatusBarCommand { export interface IAdvancedConfig { blame: { + customArguments: string[] | null; delayAfterEdit: number; sizeThresholdAfterEdit: number; };