Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,15 @@ export class CopilotCloudSessionsProvider extends Disposable implements vscode.C
private readonly PUSH_BRANCH = vscode.l10n.t('Push Branch');
private readonly DELEGATE = vscode.l10n.t('Delegate');
private readonly CANCEL = vscode.l10n.t('Cancel');
private readonly USE_CURRENT_BRANCH = vscode.l10n.t('Use Current Branch');
private readonly USE_DEFAULT_BRANCH = vscode.l10n.t('Use Default Branch');

// Messages
private readonly BASE_MESSAGE = vscode.l10n.t('Cloud agent works asynchronously to create a pull request with your requested changes. This chat\'s history will be summarized and appended to the pull request as context.');
private readonly AUTHORIZE_MESSAGE = vscode.l10n.t('Cloud agent requires elevated GitHub access to proceed.');
private readonly COMMIT_MESSAGE = vscode.l10n.t('This workspace has uncommitted changes. Should these changes be pushed and included in cloud agent\'s work?');
private readonly PUSH_BRANCH_MESSAGE = (baseRef: string, defaultBranch: string) => vscode.l10n.t('Push your currently checked out branch `{0}`, or start from the default branch `{1}`?', baseRef, defaultBranch);
private readonly CHOOSE_BRANCH_MESSAGE = (baseRef: string, defaultBranch: string) => vscode.l10n.t('Continue on your currently checked out branch `{0}`, or start from the default branch `{1}`?', baseRef, defaultBranch);

// Workspace storage keys
private readonly WORKSPACE_CONTEXT_PREFIX = 'copilot.cloudAgent';
Expand Down Expand Up @@ -892,12 +895,19 @@ export class CopilotCloudSessionsProvider extends Disposable implements vscode.C
}
}

// Determine if user explicitly chose to use the default branch
const useDefaultBranch = selection.includes(this.USE_DEFAULT_BRANCH.toUpperCase());

const base_ref: string = await (async () => {
const res = await this.checkBaseBranchPresentOnRemote();
if (!res) {
// Unexpected
throw new Error(vscode.l10n.t('Repo base branch is not detected on remote. Push your branch and try again.'));
}
// If user explicitly chose default branch, use it
if (useDefaultBranch) {
return res.repoDefaultBranch;
}
return (res?.missingOnRemote || !res?.baseRef) ? res.repoDefaultBranch : res?.baseRef;
})();
stream.progress(vscode.l10n.t('Validating branch `{0}` exists on remote', base_ref));
Expand Down Expand Up @@ -978,6 +988,7 @@ export class CopilotCloudSessionsProvider extends Disposable implements vscode.C
const needsPermissiveAuth = !this._authenticationService.permissiveGitHubSession;
const hasUncommittedChanges = await this.detectedUncommittedChanges();
const baseBranchInfo = await this.checkBaseBranchPresentOnRemote();
const isOnNonDefaultBranch = baseBranchInfo && !baseBranchInfo.missingOnRemote && baseBranchInfo.baseRef !== baseBranchInfo.repoDefaultBranch;

if (needsPermissiveAuth && hasUncommittedChanges) {
message += '\n\n' + this.AUTHORIZE_MESSAGE;
Expand All @@ -994,6 +1005,14 @@ export class CopilotCloudSessionsProvider extends Disposable implements vscode.C
vscode.l10n.t('{0} and {1}', this.AUTHORIZE, this.PUSH_BRANCH),
this.AUTHORIZE,
);
} else if (needsPermissiveAuth && isOnNonDefaultBranch) {
const { baseRef, repoDefaultBranch } = baseBranchInfo!;
message += '\n\n' + this.AUTHORIZE_MESSAGE;
message += '\n\n' + this.CHOOSE_BRANCH_MESSAGE(baseRef, repoDefaultBranch);
buttons.unshift(
vscode.l10n.t('{0} and {1}', this.AUTHORIZE, this.USE_CURRENT_BRANCH),
vscode.l10n.t('{0} and {1}', this.AUTHORIZE, this.USE_DEFAULT_BRANCH),
);
} else if (needsPermissiveAuth) {
message += '\n\n' + this.AUTHORIZE_MESSAGE;
buttons.unshift(
Expand All @@ -1012,6 +1031,14 @@ export class CopilotCloudSessionsProvider extends Disposable implements vscode.C
vscode.l10n.t('{0} and {1}', this.PUSH_BRANCH, this.DELEGATE),
this.DELEGATE,
);
} else if (isOnNonDefaultBranch) {
// User is on a non-default branch that exists on remote
const { baseRef, repoDefaultBranch } = baseBranchInfo!;
message += '\n\n' + this.CHOOSE_BRANCH_MESSAGE(baseRef, repoDefaultBranch);
buttons.unshift(
this.USE_CURRENT_BRANCH,
this.USE_DEFAULT_BRANCH,
);
}

// Check if the message has been modified from the default
Expand Down