Skip to content

Commit 1c671c1

Browse files
Copilotjoshspicer
andcommitted
Add confirmation prompt for non-default branch selection
When user is on a non-default branch that exists on the remote with no uncommitted changes, they now get a confirmation prompt to choose between continuing on their current branch or starting from the default branch. This covers the missing case in the buildConfirmation method. Co-authored-by: joshspicer <[email protected]>
1 parent 8f4a714 commit 1c671c1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/extension/chatSessions/vscode-node/copilotCloudSessionsProvider.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,15 @@ export class CopilotCloudSessionsProvider extends Disposable implements vscode.C
151151
private readonly PUSH_BRANCH = vscode.l10n.t('Push Branch');
152152
private readonly DELEGATE = vscode.l10n.t('Delegate');
153153
private readonly CANCEL = vscode.l10n.t('Cancel');
154+
private readonly USE_CURRENT_BRANCH = vscode.l10n.t('Use Current Branch');
155+
private readonly USE_DEFAULT_BRANCH = vscode.l10n.t('Use Default Branch');
154156

155157
// Messages
156158
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.');
157159
private readonly AUTHORIZE_MESSAGE = vscode.l10n.t('Cloud agent requires elevated GitHub access to proceed.');
158160
private readonly COMMIT_MESSAGE = vscode.l10n.t('This workspace has uncommitted changes. Should these changes be pushed and included in cloud agent\'s work?');
159161
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);
162+
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);
160163

161164
// Workspace storage keys
162165
private readonly WORKSPACE_CONTEXT_PREFIX = 'copilot.cloudAgent';
@@ -892,12 +895,19 @@ export class CopilotCloudSessionsProvider extends Disposable implements vscode.C
892895
}
893896
}
894897

898+
// Determine if user explicitly chose to use the default branch
899+
const useDefaultBranch = selection.includes(this.USE_DEFAULT_BRANCH.toUpperCase());
900+
895901
const base_ref: string = await (async () => {
896902
const res = await this.checkBaseBranchPresentOnRemote();
897903
if (!res) {
898904
// Unexpected
899905
throw new Error(vscode.l10n.t('Repo base branch is not detected on remote. Push your branch and try again.'));
900906
}
907+
// If user explicitly chose default branch, use it
908+
if (useDefaultBranch) {
909+
return res.repoDefaultBranch;
910+
}
901911
return (res?.missingOnRemote || !res?.baseRef) ? res.repoDefaultBranch : res?.baseRef;
902912
})();
903913
stream.progress(vscode.l10n.t('Validating branch `{0}` exists on remote', base_ref));
@@ -978,6 +988,7 @@ export class CopilotCloudSessionsProvider extends Disposable implements vscode.C
978988
const needsPermissiveAuth = !this._authenticationService.permissiveGitHubSession;
979989
const hasUncommittedChanges = await this.detectedUncommittedChanges();
980990
const baseBranchInfo = await this.checkBaseBranchPresentOnRemote();
991+
const isOnNonDefaultBranch = baseBranchInfo && !baseBranchInfo.missingOnRemote && baseBranchInfo.baseRef !== baseBranchInfo.repoDefaultBranch;
981992

982993
if (needsPermissiveAuth && hasUncommittedChanges) {
983994
message += '\n\n' + this.AUTHORIZE_MESSAGE;
@@ -994,6 +1005,14 @@ export class CopilotCloudSessionsProvider extends Disposable implements vscode.C
9941005
vscode.l10n.t('{0} and {1}', this.AUTHORIZE, this.PUSH_BRANCH),
9951006
this.AUTHORIZE,
9961007
);
1008+
} else if (needsPermissiveAuth && isOnNonDefaultBranch) {
1009+
const { baseRef, repoDefaultBranch } = baseBranchInfo;
1010+
message += '\n\n' + this.AUTHORIZE_MESSAGE;
1011+
message += '\n\n' + this.CHOOSE_BRANCH_MESSAGE(baseRef, repoDefaultBranch);
1012+
buttons.unshift(
1013+
vscode.l10n.t('{0} and {1}', this.AUTHORIZE, this.USE_CURRENT_BRANCH),
1014+
vscode.l10n.t('{0} and {1}', this.AUTHORIZE, this.USE_DEFAULT_BRANCH),
1015+
);
9971016
} else if (needsPermissiveAuth) {
9981017
message += '\n\n' + this.AUTHORIZE_MESSAGE;
9991018
buttons.unshift(
@@ -1012,6 +1031,14 @@ export class CopilotCloudSessionsProvider extends Disposable implements vscode.C
10121031
vscode.l10n.t('{0} and {1}', this.PUSH_BRANCH, this.DELEGATE),
10131032
this.DELEGATE,
10141033
);
1034+
} else if (isOnNonDefaultBranch) {
1035+
// User is on a non-default branch that exists on remote
1036+
const { baseRef, repoDefaultBranch } = baseBranchInfo;
1037+
message += '\n\n' + this.CHOOSE_BRANCH_MESSAGE(baseRef, repoDefaultBranch);
1038+
buttons.unshift(
1039+
this.USE_CURRENT_BRANCH,
1040+
this.USE_DEFAULT_BRANCH,
1041+
);
10151042
}
10161043

10171044
// Check if the message has been modified from the default

0 commit comments

Comments
 (0)