Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix auto publish before Continue On #172324

Merged
merged 3 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2699,25 +2699,6 @@
"default": "prompt",
"markdownDescription": "%config.openRepositoryInParentFolders%",
"scope": "resource"
},
"git.publishBeforeContinueOn": {
"type": "string",
"enum": [
"prompt",
"always",
"never"
],
"markdownEnumDescriptions": [
"%config.publishBeforeContinueOn.prompt%",
"%config.publishBeforeContinueOn.always%",
"%config.publishBeforeContinueOn.never%"
],
"default": "prompt",
"markdownDescription": "%config.publishBeforeContinueOn%",
"scope": "resource",
"tags": [
"experimental"
]
}
}
},
Expand Down
55 changes: 13 additions & 42 deletions extensions/git/src/editSessionIdentityProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ export class GitEditSessionIdentityProvider implements vscode.EditSessionIdentit
this.providerRegistration = vscode.workspace.registerEditSessionIdentityProvider('file', this);

vscode.workspace.onWillCreateEditSessionIdentity((e) => {
const publishBeforeContinueOn = vscode.workspace.getConfiguration('git').get<'never' | 'always' | 'prompt'>('publishBeforeContinueOn', 'prompt');
if (publishBeforeContinueOn !== 'never') {
e.waitUntil(this._onWillCreateEditSessionIdentity(e.workspaceFolder, e.token, publishBeforeContinueOn));
}
e.waitUntil(this._onWillCreateEditSessionIdentity(e.workspaceFolder));
});
}

Expand Down Expand Up @@ -67,12 +64,11 @@ export class GitEditSessionIdentityProvider implements vscode.EditSessionIdentit
}
}

private async _onWillCreateEditSessionIdentity(workspaceFolder: vscode.WorkspaceFolder, cancellationToken: vscode.CancellationToken, publishBeforeContinueOn: 'always' | 'prompt'): Promise<void> {
const cancellationPromise = createCancellationPromise(cancellationToken);
await Promise.race([this._doPublish(workspaceFolder, publishBeforeContinueOn), cancellationPromise]);
private async _onWillCreateEditSessionIdentity(workspaceFolder: vscode.WorkspaceFolder): Promise<void> {
await this._doPublish(workspaceFolder);
}

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

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

if (publishBeforeContinueOn === 'prompt') {
const always = vscode.l10n.t('Always');
const never = vscode.l10n.t('Never');
const selection = await vscode.window.showInformationMessage(
vscode.l10n.t('The current branch is not published to the remote. Would you like to publish it to access your changes elsewhere?'),
{ modal: true },
...[always, never]
);
switch (selection) {
case always:
vscode.workspace.getConfiguration('git').update('publishBeforeContinueOn', 'always');
break;
case never:
vscode.workspace.getConfiguration('git').update('publishBeforeContinueOn', 'never');
default:
return;
}
const publishBranch = vscode.l10n.t('Publish Branch');
const selection = await vscode.window.showInformationMessage(
vscode.l10n.t('The current branch is not published to the remote. Would you like to publish it to access your changes elsewhere?'),
{ modal: true },
publishBranch
);
if (selection !== publishBranch) {
throw new vscode.CancellationError();
}

await vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
title: vscode.l10n.t('Publishing branch...')
}, async () => {
await vscode.commands.executeCommand('git.publish');
});
await vscode.commands.executeCommand('git.publish');
}
}
}
Expand All @@ -128,14 +110,3 @@ function normalizeEditSessionIdentity(identity: string) {
sha
};
}

function createCancellationPromise(cancellationToken: vscode.CancellationToken) {
return new Promise((resolve, _) => {
if (cancellationToken.isCancellationRequested) {
resolve(undefined);
}
cancellationToken.onCancellationRequested(() => {
resolve(undefined);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ export class EditSessionIdentityService implements IEditSessionIdentityService {
}

async onWillCreateEditSessionIdentity(workspaceFolder: IWorkspaceFolder, cancellationToken: CancellationToken): Promise<void> {
this._logService.debug('Running onWillCreateEditSessionIdentity participants...');

// TODO@joyceerhl show progress notification?
for (const participant of this._participants) {
await participant.participate(workspaceFolder, cancellationToken);
}

this._logService.debug(`Done running ${this._participants.length} onWillCreateEditSessionIdentity participants.`);
}

private _participants: IEditSessionIdentityCreateParticipant[] = [];
Expand Down