From 28f5eb66a657aee2afcfd6c2d48d6c6e9f1b308f Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 17 Jul 2018 22:40:41 -0400 Subject: [PATCH] Fixes issue with saving settings with default values --- CHANGELOG.md | 1 + src/configuration.ts | 30 +++++++++++++++++------------- src/views/gitExplorer.ts | 23 +++++++---------------- src/views/historyExplorer.ts | 26 ++++++++++++++++---------- src/views/resultsExplorer.ts | 9 ++------- 5 files changed, 43 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index afe5adf..1e092e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Fixed - Fixes [#444](https://github.com/eamodio/vscode-gitlens/issues/444) - GitLens custom viewlet icon slightly larger than standard - Fixes [#437](https://github.com/eamodio/vscode-gitlens/issues/437) - Remove --first-parent from git commands to show file history from merged in repositories +- Fixes issue where GitLens saves a couple settings with default values into user settings (rather than just removing the setting) ## [8.5.0] - 2018-07-16 ### Added diff --git a/src/configuration.ts b/src/configuration.ts index 417e561..f92f053 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -256,22 +256,26 @@ export class Configuration { async updateEffective(section: string, value: any, resource: Uri | null = null) { const inspect = await configuration.inspect(section, resource)!; if (inspect.workspaceFolderValue !== undefined) { - if (inspect.workspaceFolderValue === value) return; - await configuration.update(section, value, ConfigurationTarget.WorkspaceFolder, resource); + if (value === inspect.workspaceFolderValue) return; + + return await configuration.update(section, value, ConfigurationTarget.WorkspaceFolder, resource); } - else if (inspect.workspaceValue !== undefined) { - if (inspect.workspaceValue === value) return; - await configuration.update(section, value, ConfigurationTarget.Workspace); + + if (inspect.workspaceValue !== undefined) { + if (value === inspect.workspaceValue) return; + + return await configuration.update(section, value, ConfigurationTarget.Workspace); } - else { - if ( - inspect.globalValue === value || - (inspect.globalValue === undefined && inspect.defaultValue === value) - ) { - return; - } - await configuration.update(section, value, ConfigurationTarget.Global); + + if (inspect.globalValue === value || (inspect.globalValue === undefined && value === inspect.defaultValue)) { + return; } + + return await configuration.update( + section, + value === inspect.defaultValue ? undefined : value, + ConfigurationTarget.Global + ); } } diff --git a/src/views/gitExplorer.ts b/src/views/gitExplorer.ts index 502ed5d..71db866 100644 --- a/src/views/gitExplorer.ts +++ b/src/views/gitExplorer.ts @@ -2,7 +2,6 @@ import { commands, ConfigurationChangeEvent, - ConfigurationTarget, Disposable, Event, EventEmitter, @@ -86,12 +85,12 @@ export class GitExplorer extends Disposable implements TreeDataProvider GitExplorer.setRenameFollowing(true), + () => HistoryExplorer.setRenameFollowing(true), this ); commands.registerCommand( 'gitlens.gitExplorer.setRenameFollowingOff', - () => GitExplorer.setRenameFollowing(false), + () => HistoryExplorer.setRenameFollowing(false), this ); commands.registerCommand( @@ -428,16 +427,12 @@ export class GitExplorer extends Disposable implements TreeDataProvider { + private getHistoryNode(editor: TextEditor | undefined): Promise { return HistoryExplorer.getHistoryNode(this, editor, this._root); } - private async setFilesLayout(layout: ExplorerFilesLayout) { - return configuration.update( - configuration.name('gitExplorer')('files')('layout').value, - layout, - ConfigurationTarget.Global - ); + private setFilesLayout(layout: ExplorerFilesLayout) { + return configuration.updateEffective(configuration.name('gitExplorer')('files')('layout').value, layout); } private setRoot(root: ExplorerNode | undefined): boolean { @@ -451,11 +446,7 @@ export class GitExplorer extends Disposable implements TreeDataProvider GitExplorer.setRenameFollowing(true), + () => HistoryExplorer.setRenameFollowing(true), this ); commands.registerCommand( 'gitlens.historyExplorer.setRenameFollowingOff', - () => GitExplorer.setRenameFollowing(false), + () => HistoryExplorer.setRenameFollowing(false), this ); @@ -158,12 +157,12 @@ export class HistoryExplorer extends Disposable implements TreeDataProvider { + private getRootNode(editor: TextEditor | undefined): Promise { return HistoryExplorer.getHistoryNode(this, editor, this._root); } @@ -285,4 +284,11 @@ export class HistoryExplorer extends Disposable implements TreeDataProvider