Commit Action button polish (#164746)

This commit is contained in:
Ladislau Szomoru
2022-10-28 15:23:19 +02:00
committed by GitHub
parent c21a6a0ecd
commit 67b8c25157
4 changed files with 54 additions and 34 deletions

View File

@@ -27,7 +27,9 @@ export class GitPostCommitCommandsProvider implements PostCommitCommandsProvider
const alwaysCommitToNewBranch = isBranchProtected && branchProtectionPrompt === 'alwaysCommitToNewBranch';
// Icon
const icon = alwaysPrompt ? '$(lock)' : alwaysCommitToNewBranch ? '$(git-branch)' : undefined;
const repository = apiRepository.repository;
const isCommitInProgress = repository.operations.isRunning(Operation.Commit) || repository.operations.isRunning(Operation.PostCommitCommand);
const icon = isCommitInProgress ? '$(sync~spin)' : alwaysPrompt ? '$(lock)' : alwaysCommitToNewBranch ? '$(git-branch)' : undefined;
// Tooltip (default)
let pushCommandTooltip = !alwaysCommitToNewBranch ?
@@ -39,7 +41,7 @@ export class GitPostCommitCommandsProvider implements PostCommitCommandsProvider
l10n.t('Commit to New Branch & Synchronize Changes');
// Tooltip (in progress)
if (apiRepository.repository.operations.isRunning(Operation.Commit)) {
if (isCommitInProgress) {
pushCommandTooltip = !alwaysCommitToNewBranch ?
l10n.t('Committing & Pushing Changes...') :
l10n.t('Committing to New Branch & Pushing Changes...');
@@ -71,6 +73,17 @@ export class CommitCommandsCenter {
private disposables: Disposable[] = [];
set postCommitCommand(command: string | null | undefined) {
if (command === undefined) {
// Commit WAS NOT initiated using the action button
// so there is no need to store the post-commit command
return;
}
this.globalState.update(this.repository.root, command)
.then(() => this._onDidChange.fire());
}
constructor(
private readonly globalState: Memento,
private readonly repository: Repository,
@@ -119,19 +132,32 @@ export class CommitCommandsCenter {
return commandGroups;
}
async executePostCommitCommand(command: string | undefined): Promise<void> {
if (command === undefined) {
// Commit WAS NOT initiated using the action button (ex: keybinding, toolbar action,
// command palette) so we have to honour the default post commit command (memento/setting).
const primaryCommand = this.getPrimaryCommand();
command = primaryCommand.arguments?.length === 2 ? primaryCommand.arguments[1] : '';
}
async executePostCommitCommand(command: string | null | undefined): Promise<void> {
try {
if (command === null) {
// No post-commit command
return;
}
if (command?.length) {
await commands.executeCommand(command, new ApiRepository(this.repository));
}
if (command === undefined) {
// Commit WAS NOT initiated using the action button (ex: keybinding, toolbar action,
// command palette) so we have to honour the default post commit command (memento/setting).
const primaryCommand = this.getPrimaryCommand();
command = primaryCommand.arguments?.length === 2 ? primaryCommand.arguments[1] : null;
}
await this.savePostCommitCommand(command);
if (command !== null) {
await commands.executeCommand(command!.toString(), new ApiRepository(this.repository));
}
} catch (err) {
throw err;
}
finally {
if (!this.isRememberPostCommitCommandEnabled()) {
await this.globalState.update(this.repository.root, undefined);
this._onDidChange.fire();
}
}
}
private getCommitCommand(): Command {
@@ -158,7 +184,7 @@ export class CommitCommandsCenter {
l10n.t('Committing Changes to New Branch...');
}
return { command: 'git.commit', title: l10n.t('{0} Commit', icon ?? '$(check)'), tooltip, arguments: [this.repository.sourceControl, ''] };
return { command: 'git.commit', title: l10n.t('{0} Commit', icon ?? '$(check)'), tooltip, arguments: [this.repository.sourceControl, null] };
}
private getPostCommitCommandStringFromSetting(): string | undefined {
@@ -168,12 +194,8 @@ export class CommitCommandsCenter {
return postCommitCommandSetting === 'push' || postCommitCommandSetting === 'sync' ? `git.${postCommitCommandSetting}` : undefined;
}
private getPostCommitCommandStringFromStorage(): string | undefined {
if (!this.isRememberPostCommitCommandEnabled()) {
return undefined;
}
return this.globalState.get<string>(this.repository.root);
private getPostCommitCommandStringFromStorage(): string | null | undefined {
return this.globalState.get<string | null>(this.repository.root);
}
private isRememberPostCommitCommandEnabled(): boolean {
@@ -181,16 +203,6 @@ export class CommitCommandsCenter {
return config.get<boolean>('rememberPostCommitCommand') === true;
}
private async savePostCommitCommand(command: string | undefined): Promise<void> {
if (!this.isRememberPostCommitCommandEnabled()) {
return;
}
command = command !== '' ? command : undefined;
await this.globalState.update(this.repository.root, command);
this._onDidChange.fire();
}
dispose(): void {
this.disposables = dispose(this.disposables);
}