Skip to content

Commit 9c5c5bf

Browse files
committed
Closes #337 - adds custom args for blame
1 parent cd7eeda commit 9c5c5bf

File tree

6 files changed

+58
-6
lines changed

6 files changed

+58
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
77
## [Unreleased]
88
### Added
99
- Adds an indicator to the *GitLens* explorer's branch history to mark the the tips of all branches
10+
- 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)
1011

1112
### Changed
1213
- Changes the author name to "You" when appropriate — closes [#341](https://github.com/eamodio/vscode-gitlens/issues/341)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ See also [Explorer Settings](#explorer-settings "Jump to the Explorer settings")
691691

692692
|Name | Description
693693
|-----|------------
694+
|`gitlens.advanced.blame.customArguments`|Specifies additional arguments to pass to the `git blame` command
694695
|`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
695696
|`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
696697
|`gitlens.advanced.caching.enabled`|Specifies whether git output will be cached — changing the default is not recommended

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,12 @@
809809
"description": "Specifies the string to be shown in place of the `authors` code lens when there are unsaved changes",
810810
"scope": "window"
811811
},
812+
"gitlens.advanced.blame.customArguments": {
813+
"type": "string[]",
814+
"default": null,
815+
"description": "Specifies additional arguments to pass to the `git blame` command",
816+
"scope": "resource"
817+
},
812818
"gitlens.advanced.blame.delayAfterEdit": {
813819
"type": "number",
814820
"default": 5000,

src/git/git.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export class Git {
267267

268268
// Git commands
269269

270-
static async blame(repoPath: string | undefined, fileName: string, sha?: string, options: { ignoreWhitespace?: boolean, startLine?: number, endLine?: number } = {}) {
270+
static async blame(repoPath: string | undefined, fileName: string, sha?: string, options: { args?: string[] | null, ignoreWhitespace?: boolean, startLine?: number, endLine?: number } = {}) {
271271
const [file, root] = Git.splitPath(fileName, repoPath);
272272

273273
const params = [...defaultBlameParams];
@@ -278,6 +278,9 @@ export class Git {
278278
if (options.startLine != null && options.endLine != null) {
279279
params.push(`-L ${options.startLine},${options.endLine}`);
280280
}
281+
if (options.args != null) {
282+
params.push(...options.args);
283+
}
281284

282285
let stdin;
283286
if (sha) {
@@ -296,7 +299,7 @@ export class Git {
296299
return gitCommand({ cwd: root, stdin: stdin }, ...params, '--', file);
297300
}
298301

299-
static async blame_contents(repoPath: string | undefined, fileName: string, contents: string, options: { correlationKey?: string, ignoreWhitespace?: boolean, startLine?: number, endLine?: number } = {}) {
302+
static async blame_contents(repoPath: string | undefined, fileName: string, contents: string, options: { args?: string[] | null, correlationKey?: string, ignoreWhitespace?: boolean, startLine?: number, endLine?: number } = {}) {
300303
const [file, root] = Git.splitPath(fileName, repoPath);
301304

302305
const params = [...defaultBlameParams];
@@ -307,6 +310,9 @@ export class Git {
307310
if (options.startLine != null && options.endLine != null) {
308311
params.push(`-L ${options.startLine},${options.endLine}`);
309312
}
313+
if (options.args != null) {
314+
params.push(...options.args);
315+
}
310316

311317
// Pipe the blame contents to stdin
312318
params.push('--contents', '-');

src/gitService.ts

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,15 @@ export class GitService extends Disposable {
456456
const [file, root] = Git.splitPath(uri.fsPath, uri.repoPath, false);
457457

458458
try {
459-
const data = await Git.blame(root, file, uri.sha, { ignoreWhitespace: Container.config.blame.ignoreWhitespace });
459+
const data = await Git.blame(
460+
root,
461+
file,
462+
uri.sha,
463+
{
464+
args: Container.config.advanced.blame.customArguments,
465+
ignoreWhitespace: Container.config.blame.ignoreWhitespace
466+
}
467+
);
460468
const blame = GitBlameParser.parse(data, root, file, await this.getCurrentUsername(root));
461469
return blame;
462470
}
@@ -525,7 +533,16 @@ export class GitService extends Disposable {
525533
const [file, root] = Git.splitPath(uri.fsPath, uri.repoPath, false);
526534

527535
try {
528-
const data = await Git.blame_contents(root, file, contents, { correlationKey: `:${key}`, ignoreWhitespace: Container.config.blame.ignoreWhitespace });
536+
const data = await Git.blame_contents(
537+
root,
538+
file,
539+
contents,
540+
{
541+
args: Container.config.advanced.blame.customArguments,
542+
correlationKey: `:${key}`,
543+
ignoreWhitespace: Container.config.blame.ignoreWhitespace
544+
}
545+
);
529546
const blame = GitBlameParser.parse(data, root, file, await this.getCurrentUsername(root));
530547
return blame;
531548
}
@@ -575,7 +592,17 @@ export class GitService extends Disposable {
575592
const fileName = uri.fsPath;
576593

577594
try {
578-
const data = await Git.blame(uri.repoPath, fileName, uri.sha, { ignoreWhitespace: Container.config.blame.ignoreWhitespace, startLine: lineToBlame, endLine: lineToBlame });
595+
const data = await Git.blame(
596+
uri.repoPath,
597+
fileName,
598+
uri.sha,
599+
{
600+
args: Container.config.advanced.blame.customArguments,
601+
ignoreWhitespace: Container.config.blame.ignoreWhitespace,
602+
startLine: lineToBlame,
603+
endLine: lineToBlame
604+
}
605+
);
579606
const blame = GitBlameParser.parse(data, uri.repoPath, fileName, await this.getCurrentUsername(uri.repoPath!));
580607
if (blame === undefined) return undefined;
581608

@@ -617,7 +644,17 @@ export class GitService extends Disposable {
617644
const fileName = uri.fsPath;
618645

619646
try {
620-
const data = await Git.blame_contents(uri.repoPath, fileName, contents, { ignoreWhitespace: Container.config.blame.ignoreWhitespace, startLine: lineToBlame, endLine: lineToBlame });
647+
const data = await Git.blame_contents(
648+
uri.repoPath,
649+
fileName,
650+
contents,
651+
{
652+
args: Container.config.advanced.blame.customArguments,
653+
ignoreWhitespace: Container.config.blame.ignoreWhitespace,
654+
startLine: lineToBlame,
655+
endLine: lineToBlame
656+
}
657+
);
621658
const currentUser = await this.getCurrentUsername(uri.repoPath!);
622659
const blame = GitBlameParser.parse(data, uri.repoPath, fileName, currentUser);
623660
if (blame === undefined) return undefined;

src/ui/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export enum StatusBarCommand {
103103

104104
export interface IAdvancedConfig {
105105
blame: {
106+
customArguments: string[] | null;
106107
delayAfterEdit: number;
107108
sizeThresholdAfterEdit: number;
108109
};

0 commit comments

Comments
 (0)