Skip to content

Commit 0231351

Browse files
joyceerhlhediet
authored andcommitted
Fix auto publish before Continue On (#172324)
* Fix auto publish before Continue On * Fix provider implementation
1 parent 52db823 commit 0231351

File tree

3 files changed

+18
-61
lines changed

3 files changed

+18
-61
lines changed

extensions/git/package.json

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2699,25 +2699,6 @@
26992699
"default": "prompt",
27002700
"markdownDescription": "%config.openRepositoryInParentFolders%",
27012701
"scope": "resource"
2702-
},
2703-
"git.publishBeforeContinueOn": {
2704-
"type": "string",
2705-
"enum": [
2706-
"prompt",
2707-
"always",
2708-
"never"
2709-
],
2710-
"markdownEnumDescriptions": [
2711-
"%config.publishBeforeContinueOn.prompt%",
2712-
"%config.publishBeforeContinueOn.always%",
2713-
"%config.publishBeforeContinueOn.never%"
2714-
],
2715-
"default": "prompt",
2716-
"markdownDescription": "%config.publishBeforeContinueOn%",
2717-
"scope": "resource",
2718-
"tags": [
2719-
"experimental"
2720-
]
27212702
}
27222703
}
27232704
},

extensions/git/src/editSessionIdentityProvider.ts

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ export class GitEditSessionIdentityProvider implements vscode.EditSessionIdentit
1616
this.providerRegistration = vscode.workspace.registerEditSessionIdentityProvider('file', this);
1717

1818
vscode.workspace.onWillCreateEditSessionIdentity((e) => {
19-
const publishBeforeContinueOn = vscode.workspace.getConfiguration('git').get<'never' | 'always' | 'prompt'>('publishBeforeContinueOn', 'prompt');
20-
if (publishBeforeContinueOn !== 'never') {
21-
e.waitUntil(this._onWillCreateEditSessionIdentity(e.workspaceFolder, e.token, publishBeforeContinueOn));
22-
}
19+
e.waitUntil(this._onWillCreateEditSessionIdentity(e.workspaceFolder));
2320
});
2421
}
2522

@@ -67,12 +64,11 @@ export class GitEditSessionIdentityProvider implements vscode.EditSessionIdentit
6764
}
6865
}
6966

70-
private async _onWillCreateEditSessionIdentity(workspaceFolder: vscode.WorkspaceFolder, cancellationToken: vscode.CancellationToken, publishBeforeContinueOn: 'always' | 'prompt'): Promise<void> {
71-
const cancellationPromise = createCancellationPromise(cancellationToken);
72-
await Promise.race([this._doPublish(workspaceFolder, publishBeforeContinueOn), cancellationPromise]);
67+
private async _onWillCreateEditSessionIdentity(workspaceFolder: vscode.WorkspaceFolder): Promise<void> {
68+
await this._doPublish(workspaceFolder);
7369
}
7470

75-
private async _doPublish(workspaceFolder: vscode.WorkspaceFolder, publishBeforeContinueOn: 'always' | 'prompt') {
71+
private async _doPublish(workspaceFolder: vscode.WorkspaceFolder) {
7672
await this.model.openRepository(path.dirname(workspaceFolder.uri.fsPath));
7773

7874
const repository = this.model.getRepository(workspaceFolder.uri);
@@ -86,31 +82,17 @@ export class GitEditSessionIdentityProvider implements vscode.EditSessionIdentit
8682
// ensure that it is published before Continue On is invoked
8783
if (!repository.HEAD?.upstream && repository.HEAD?.type === RefType.Head) {
8884

89-
if (publishBeforeContinueOn === 'prompt') {
90-
const always = vscode.l10n.t('Always');
91-
const never = vscode.l10n.t('Never');
92-
const selection = await vscode.window.showInformationMessage(
93-
vscode.l10n.t('The current branch is not published to the remote. Would you like to publish it to access your changes elsewhere?'),
94-
{ modal: true },
95-
...[always, never]
96-
);
97-
switch (selection) {
98-
case always:
99-
vscode.workspace.getConfiguration('git').update('publishBeforeContinueOn', 'always');
100-
break;
101-
case never:
102-
vscode.workspace.getConfiguration('git').update('publishBeforeContinueOn', 'never');
103-
default:
104-
return;
105-
}
85+
const publishBranch = vscode.l10n.t('Publish Branch');
86+
const selection = await vscode.window.showInformationMessage(
87+
vscode.l10n.t('The current branch is not published to the remote. Would you like to publish it to access your changes elsewhere?'),
88+
{ modal: true },
89+
publishBranch
90+
);
91+
if (selection !== publishBranch) {
92+
throw new vscode.CancellationError();
10693
}
10794

108-
await vscode.window.withProgress({
109-
location: vscode.ProgressLocation.Notification,
110-
title: vscode.l10n.t('Publishing branch...')
111-
}, async () => {
112-
await vscode.commands.executeCommand('git.publish');
113-
});
95+
await vscode.commands.executeCommand('git.publish');
11496
}
11597
}
11698
}
@@ -128,14 +110,3 @@ function normalizeEditSessionIdentity(identity: string) {
128110
sha
129111
};
130112
}
131-
132-
function createCancellationPromise(cancellationToken: vscode.CancellationToken) {
133-
return new Promise((resolve, _) => {
134-
if (cancellationToken.isCancellationRequested) {
135-
resolve(undefined);
136-
}
137-
cancellationToken.onCancellationRequested(() => {
138-
resolve(undefined);
139-
});
140-
});
141-
}

src/vs/workbench/services/workspaces/common/editSessionIdentityService.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,14 @@ export class EditSessionIdentityService implements IEditSessionIdentityService {
5252
}
5353

5454
async onWillCreateEditSessionIdentity(workspaceFolder: IWorkspaceFolder, cancellationToken: CancellationToken): Promise<void> {
55+
this._logService.debug('Running onWillCreateEditSessionIdentity participants...');
56+
57+
// TODO@joyceerhl show progress notification?
5558
for (const participant of this._participants) {
5659
await participant.participate(workspaceFolder, cancellationToken);
5760
}
61+
62+
this._logService.debug(`Done running ${this._participants.length} onWillCreateEditSessionIdentity participants.`);
5863
}
5964

6065
private _participants: IEditSessionIdentityCreateParticipant[] = [];

0 commit comments

Comments
 (0)