diff --git a/extensions/git/package.json b/extensions/git/package.json index 6a0e20b3eb3..5ca55fe1aca 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -1185,6 +1185,11 @@ "default": true, "description": "%config.decorations.enabled%" }, + "git.statusBarSync.enabled": { + "type": "boolean", + "default": true, + "description": "%config.statusBarSync.enabled%" + }, "git.promptToSaveFilesBeforeCommit": { "type": "string", "enum": [ diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index 151b62d4458..e4523b45744 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -96,6 +96,7 @@ "config.enableCommitSigning": "Enables commit signing with GPG.", "config.discardAllScope": "Controls what changes are discarded by the `Discard all changes` command. `all` discards all changes. `tracked` discards only tracked files. `prompt` shows a prompt dialog every time the action is run.", "config.decorations.enabled": "Controls whether Git contributes colors and badges to the explorer and the open editors view.", + "config.statusBarSync.enabled": "Controls whether Git sync appears in the status bar.", "config.promptToSaveFilesBeforeCommit": "Controls whether Git should check for unsaved files before committing.", "config.promptToSaveFilesBeforeCommit.always": "Check for any unsaved files.", "config.promptToSaveFilesBeforeCommit.staged": "Check only for unsaved staged files.", diff --git a/extensions/git/src/statusbar.ts b/extensions/git/src/statusbar.ts index cc007172d5f..e89e1ff9c9b 100644 --- a/extensions/git/src/statusbar.ts +++ b/extensions/git/src/statusbar.ts @@ -5,7 +5,7 @@ import { Disposable, Command, EventEmitter, Event, workspace, Uri } from 'vscode'; import { Repository, Operation } from './repository'; -import { anyEvent, dispose } from './util'; +import { anyEvent, dispose, filterEvent } from './util'; import * as nls from 'vscode-nls'; import { Branch } from './api/git'; @@ -39,6 +39,7 @@ class CheckoutStatusBar { } interface SyncStatusBarState { + isEnabled: boolean; isSyncRunning: boolean; hasRemotes: boolean; HEAD: Branch | undefined; @@ -47,6 +48,7 @@ interface SyncStatusBarState { class SyncStatusBar { private static StartState: SyncStatusBarState = { + isEnabled: true, isSyncRunning: false, hasRemotes: false, HEAD: undefined @@ -66,9 +68,23 @@ class SyncStatusBar { constructor(private repository: Repository) { repository.onDidRunGitStatus(this.onModelChange, this, this.disposables); repository.onDidChangeOperations(this.onOperationsChange, this, this.disposables); + + const onEnablementChange = filterEvent(workspace.onDidChangeConfiguration, e => e.affectsConfiguration('git.statusBarSync.enabled')); + onEnablementChange(this.updateEnablement, this, this.disposables); + this._onDidChange.fire(); } + private updateEnablement(): void { + const isEnabled = workspace.getConfiguration('git').get('statusBarSync.enabled'); + + if (isEnabled) { + this.state = { ... this.state, isEnabled: true }; + } else { + this.state = { ... this.state, isEnabled: false }; + } + } + private onOperationsChange(): void { const isSyncRunning = this.repository.operations.isRunning(Operation.Sync) || this.repository.operations.isRunning(Operation.Push) || @@ -86,7 +102,7 @@ class SyncStatusBar { } get command(): Command | undefined { - if (!this.state.hasRemotes) { + if (!this.state.isEnabled || !this.state.hasRemotes) { return undefined; }