From c78d585895293aad4df6c61bb032b8089871a08f Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Wed, 14 Dec 2022 15:35:47 +0100 Subject: [PATCH] Git - Disable git status bar items while commit is running (#169133) Disable git status bar items while commit is running --- extensions/git/src/statusbar.ts | 46 ++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/extensions/git/src/statusbar.ts b/extensions/git/src/statusbar.ts index 7a21b78a28a..da873692564 100644 --- a/extensions/git/src/statusbar.ts +++ b/extensions/git/src/statusbar.ts @@ -9,13 +9,29 @@ import { anyEvent, dispose, filterEvent } from './util'; import { Branch, RemoteSourcePublisher } from './api/git'; import { IRemoteSourcePublisherRegistry } from './remotePublisher'; +interface CheckoutStatusBarState { + readonly isCommitRunning: boolean; +} + class CheckoutStatusBar { private _onDidChange = new EventEmitter(); get onDidChange(): Event { return this._onDidChange.event; } private disposables: Disposable[] = []; + private _state: CheckoutStatusBarState; + private get state() { return this._state; } + private set state(state: CheckoutStatusBarState) { + this._state = state; + this._onDidChange.fire(); + } + constructor(private repository: Repository) { + this._state = { + isCommitRunning: false + }; + + repository.onDidChangeOperations(this.onDidChangeOperations, this, this.disposables); repository.onDidRunGitStatus(this._onDidChange.fire, this._onDidChange, this.disposables); } @@ -25,13 +41,19 @@ class CheckoutStatusBar { const label = `${this.repository.headLabel}${rebasing ? ` (${l10n.t('Rebasing')})` : ''}`; return { - command: 'git.checkout', - tooltip: l10n.t('{0}, Checkout branch/tag...', label), + command: this.state.isCommitRunning ? '' : 'git.checkout', + tooltip: this.state.isCommitRunning ? l10n.t('{0}, Committing changes...', label) : l10n.t('{0}, Checkout branch/tag...', label), title: `${isBranchProtected ? '$(lock)' : '$(git-branch)'} ${label}`, arguments: [this.repository.sourceControl] }; } + private onDidChangeOperations(): void { + const isCommitRunning = this.repository.operations.isRunning(Operation.Commit); + + this.state = { ...this.state, isCommitRunning }; + } + dispose(): void { this.disposables.forEach(d => d.dispose()); } @@ -39,6 +61,7 @@ class CheckoutStatusBar { interface SyncStatusBarState { readonly enabled: boolean; + readonly isCommitRunning: boolean; readonly isSyncRunning: boolean; readonly hasRemotes: boolean; readonly HEAD: Branch | undefined; @@ -61,6 +84,7 @@ class SyncStatusBar { constructor(private repository: Repository, private remoteSourcePublisherRegistry: IRemoteSourcePublisherRegistry) { this._state = { enabled: true, + isCommitRunning: false, isSyncRunning: false, hasRemotes: false, HEAD: undefined, @@ -86,11 +110,12 @@ class SyncStatusBar { } private onDidChangeOperations(): void { + const isCommitRunning = this.repository.operations.isRunning(Operation.Commit); const isSyncRunning = this.repository.operations.isRunning(Operation.Sync) || this.repository.operations.isRunning(Operation.Push) || this.repository.operations.isRunning(Operation.Pull); - this.state = { ...this.state, isSyncRunning }; + this.state = { ...this.state, isCommitRunning, isSyncRunning }; } private onDidRunGitStatus(): void { @@ -118,12 +143,14 @@ class SyncStatusBar { return; } - const tooltip = this.state.remoteSourcePublishers.length === 1 - ? l10n.t('Publish to {0}', this.state.remoteSourcePublishers[0].name) - : l10n.t('Publish to...'); + const command = this.state.isCommitRunning ? '' : 'git.publish'; + const tooltip = this.state.isCommitRunning ? l10n.t('Committing Changes...') : + this.state.remoteSourcePublishers.length === 1 + ? l10n.t('Publish to {0}', this.state.remoteSourcePublishers[0].name) + : l10n.t('Publish to...'); return { - command: 'git.publish', + command, title: `$(cloud-upload)`, tooltip, arguments: [this.repository.sourceControl] @@ -154,6 +181,11 @@ class SyncStatusBar { tooltip = ''; } + if (this.state.isCommitRunning) { + command = ''; + tooltip = l10n.t('Committing Changes...'); + } + if (this.state.isSyncRunning) { icon = '$(sync~spin)'; command = '';