From 6c40a968f42b464b38263c177e58108f71b973b6 Mon Sep 17 00:00:00 2001 From: BattleBas Date: Thu, 12 Oct 2017 20:19:07 -0500 Subject: [PATCH 1/2] Added setting "git.autoRepositoryDetection" When opening just one file, the setting "autoRepositoryDetection" allows the user to control whether the entire repository changes will be displayed or just the changes of the current file. --- extensions/git/package.json | 5 +++++ extensions/git/package.nls.json | 1 + extensions/git/src/repository.ts | 21 ++++++++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/extensions/git/package.json b/extensions/git/package.json index abb7f5400ea..de983bed86c 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -769,6 +769,11 @@ "default": null, "isExecutable": true }, + "git.autoRepositoryDetection": { + "type": "boolean", + "description": "%config.autoRepositoryDetection%", + "default": true + }, "git.autorefresh": { "type": "boolean", "description": "%config.autorefresh%", diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index d191adfadf4..d960307f53c 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -45,6 +45,7 @@ "command.stashPopLatest": "Pop Latest Stash", "config.enabled": "Whether git is enabled", "config.path": "Path to the git executable", + "config.autoRepositoryDetection": "Whether a repository should be automatically detected for a single file", "config.autorefresh": "Whether auto refreshing is enabled", "config.autofetch": "Whether auto fetching is enabled", "config.enableLongCommitWarning": "Whether long commit messages should be warned about", diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index 6c9f781c58f..b99158bbc96 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -742,9 +742,18 @@ export class Repository implements Disposable { const index: Resource[] = []; const workingTree: Resource[] = []; const merge: Resource[] = []; + const repoDetection = config.get('autoRepositoryDetection') === true; status.forEach(raw => { - const uri = Uri.file(path.join(this.repository.root, raw.path)); + const fullFilePath = path.join(this.repository.root, raw.path); + + if (!repoDetection && workspace.workspaceFolders === undefined) { + if (!this.detectActiveFile(fullFilePath)) { + return; + } + } + + const uri = Uri.file(fullFilePath); const renameUri = raw.rename ? Uri.file(path.join(this.repository.root, raw.rename)) : undefined; switch (raw.x + raw.y) { @@ -802,6 +811,16 @@ export class Repository implements Disposable { this._onDidChangeStatus.fire(); } + private detectActiveFile(fullFilePath: string): boolean { + if (window.activeTextEditor !== undefined) { + if (window.activeTextEditor.document.fileName === fullFilePath) { + return true; + } + } + + return false; + } + private onFSChange(uri: Uri): void { const config = workspace.getConfiguration('git'); const autorefresh = config.get('autorefresh'); From 170161d67febfc0d916707edb28bd58772be8ff2 Mon Sep 17 00:00:00 2001 From: BattleBas Date: Tue, 17 Oct 2017 22:23:52 -0500 Subject: [PATCH 2/2] Simplified method to check active file Updated the "detectActiveFile" method to be more simple and straightforward. Thanks to @lodenrogue suggestion! --- extensions/git/src/repository.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index b99158bbc96..ac2d24fe1be 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -811,14 +811,8 @@ export class Repository implements Disposable { this._onDidChangeStatus.fire(); } - private detectActiveFile(fullFilePath: string): boolean { - if (window.activeTextEditor !== undefined) { - if (window.activeTextEditor.document.fileName === fullFilePath) { - return true; - } - } - - return false; + private detectActiveFile(fullFilePath: string): boolean | undefined { + return window.activeTextEditor && window.activeTextEditor.document.fileName === fullFilePath; } private onFSChange(uri: Uri): void {