Skip to content

Commit b18f9e0

Browse files
authored
Git - Do not show Sync Changes and Publish Branch action button when commit is in progress (microsoft#153821)
Do not show Sync Changes and Publish Branch action button when commit is in progress
1 parent 3635164 commit b18f9e0

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

extensions/git/src/actionButton.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const localize = nls.loadMessageBundle();
1313

1414
interface ActionButtonState {
1515
readonly HEAD: Branch | undefined;
16-
readonly isActionRunning: boolean;
16+
readonly isCommitInProgress: boolean;
17+
readonly isSyncInProgress: boolean;
1718
readonly repositoryHasChanges: boolean;
1819
}
1920

@@ -33,7 +34,7 @@ export class ActionButtonCommand {
3334
private disposables: Disposable[] = [];
3435

3536
constructor(readonly repository: Repository) {
36-
this._state = { HEAD: undefined, isActionRunning: false, repositoryHasChanges: false };
37+
this._state = { HEAD: undefined, isCommitInProgress: false, isSyncInProgress: false, repositoryHasChanges: false };
3738

3839
repository.onDidRunGitStatus(this.onDidRunGitStatus, this, this.disposables);
3940
repository.onDidChangeOperations(this.onDidChangeOperations, this, this.disposables);
@@ -75,21 +76,21 @@ export class ActionButtonCommand {
7576
switch (postCommitCommand) {
7677
case 'push': {
7778
title = localize('scm button commit and push title', "$(arrow-up) Commit & Push");
78-
tooltip = this.state.isActionRunning ?
79+
tooltip = this.state.isCommitInProgress ?
7980
localize('scm button committing pushing tooltip', "Committing & Pushing Changes...") :
8081
localize('scm button commit push tooltip', "Commit & Push Changes");
8182
break;
8283
}
8384
case 'sync': {
8485
title = localize('scm button commit and sync title', "$(sync) Commit & Sync");
85-
tooltip = this.state.isActionRunning ?
86+
tooltip = this.state.isCommitInProgress ?
8687
localize('scm button committing synching tooltip', "Committing & Synching Changes...") :
8788
localize('scm button commit sync tooltip', "Commit & Sync Changes");
8889
break;
8990
}
9091
default: {
9192
title = localize('scm button commit title', "$(check) Commit");
92-
tooltip = this.state.isActionRunning ?
93+
tooltip = this.state.isCommitInProgress ?
9394
localize('scm button committing tooltip', "Committing Changes...") :
9495
localize('scm button commit tooltip', "Commit Changes");
9596
break;
@@ -122,65 +123,67 @@ export class ActionButtonCommand {
122123
},
123124
]
124125
],
125-
enabled: this.state.repositoryHasChanges && !this.state.isActionRunning
126+
enabled: this.state.repositoryHasChanges && !this.state.isCommitInProgress
126127
};
127128
}
128129

129130
private getPublishBranchActionButton(): SourceControlActionButton | undefined {
130131
const config = workspace.getConfiguration('git', Uri.file(this.repository.root));
131132
const showActionButton = config.get<{ publish: boolean }>('showActionButton', { publish: true });
132133

133-
// Branch does have an upstream or the button is disabled
134-
if (this.state.HEAD?.upstream || !showActionButton.publish) { return undefined; }
134+
// Branch does have an upstream, commit is in progress, or the button is disabled
135+
if (this.state.HEAD?.upstream || this.state.isCommitInProgress || !showActionButton.publish) { return undefined; }
135136

136137
return {
137138
command: {
138139
command: 'git.publish',
139140
title: localize('scm publish branch action button title', "{0} Publish Branch", '$(cloud-upload)'),
140-
tooltip: this.state.isActionRunning ?
141+
tooltip: this.state.isSyncInProgress ?
141142
localize('scm button publish branch running', "Publishing Branch...") :
142143
localize('scm button publish branch', "Publish Branch"),
143144
arguments: [this.repository.sourceControl],
144145
},
145-
enabled: !this.state.isActionRunning
146+
enabled: !this.state.isSyncInProgress
146147
};
147148
}
148149

149150
private getSyncChangesActionButton(): SourceControlActionButton | undefined {
150151
const config = workspace.getConfiguration('git', Uri.file(this.repository.root));
151152
const showActionButton = config.get<{ sync: boolean }>('showActionButton', { sync: true });
152153

153-
// Branch does not have an upstream or the button is disabled
154-
if (!this.state.HEAD?.upstream || !showActionButton.sync) { return undefined; }
154+
// Branch does not have an upstream, commit is in progress, or the button is disabled
155+
if (!this.state.HEAD?.upstream || this.state.isCommitInProgress || !showActionButton.sync) { return undefined; }
155156

156157
const ahead = this.state.HEAD.ahead ? ` ${this.state.HEAD.ahead}$(arrow-up)` : '';
157158
const behind = this.state.HEAD.behind ? ` ${this.state.HEAD.behind}$(arrow-down)` : '';
158-
const icon = this.state.isActionRunning ? '$(sync~spin)' : '$(sync)';
159+
const icon = this.state.isSyncInProgress ? '$(sync~spin)' : '$(sync)';
159160

160161
const rebaseWhenSync = config.get<string>('rebaseWhenSync');
161162

162163
return {
163164
command: {
164165
command: rebaseWhenSync ? 'git.syncRebase' : 'git.sync',
165166
title: `${icon}${behind}${ahead}`,
166-
tooltip: this.state.isActionRunning ?
167+
tooltip: this.state.isSyncInProgress ?
167168
localize('syncing changes', "Synchronizing Changes...")
168169
: this.repository.syncTooltip,
169170
arguments: [this.repository.sourceControl],
170171
},
171172
description: localize('scm button sync description', "{0} Sync Changes{1}{2}", icon, behind, ahead),
172-
enabled: !this.state.isActionRunning
173+
enabled: !this.state.isSyncInProgress
173174
};
174175
}
175176

176177
private onDidChangeOperations(): void {
177-
const isActionRunning =
178+
const isCommitInProgress =
179+
this.repository.operations.isRunning(Operation.Commit);
180+
181+
const isSyncInProgress =
178182
this.repository.operations.isRunning(Operation.Sync) ||
179183
this.repository.operations.isRunning(Operation.Push) ||
180-
this.repository.operations.isRunning(Operation.Pull) ||
181-
this.repository.operations.isRunning(Operation.Commit);
184+
this.repository.operations.isRunning(Operation.Pull);
182185

183-
this.state = { ...this.state, isActionRunning };
186+
this.state = { ...this.state, isCommitInProgress, isSyncInProgress };
184187
}
185188

186189
private onDidRunGitStatus(): void {

0 commit comments

Comments
 (0)