Skip to content
This repository was archived by the owner on May 20, 2026. It is now read-only.

Commit 4e872ea

Browse files
authored
Session - add confirmation dialog for discarding changes (#4787)
* Pull request feedback * Fix dialog
1 parent 34fda39 commit 4e872ea

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5639,6 +5639,7 @@
56395639
"chat/input/editing/sessionChangeToolbar": [
56405640
{
56415641
"command": "github.copilot.sessions.discardChanges",
5642+
"when": "chatSessionType == copilotcli && isSessionsWindow",
56425643
"group": "navigation@1"
56435644
}
56445645
]

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2303,7 +2303,7 @@ export function registerCLIChatCommands(
23032303
}));
23042304

23052305
disposableStore.add(vscode.commands.registerCommand('github.copilot.sessions.discardChanges', async (sessionResource: vscode.Uri, ref: string, ...resources: vscode.Uri[]) => {
2306-
if (!isUri(sessionResource) || resources.some(r => !isUri(r))) {
2306+
if (!isUri(sessionResource) || !ref || resources.length === 0 || resources.some(r => !isUri(r))) {
23072307
return;
23082308
}
23092309

@@ -2317,6 +2317,16 @@ export function registerCLIChatCommands(
23172317
return;
23182318
}
23192319

2320+
const confirmAction = l10n.t('Discard Changes');
2321+
const message = resources.length === 1
2322+
? l10n.t('Are you sure you want to discard the changes in \'{0}\'? This action cannot be undone.', basename(resources[0]))
2323+
: l10n.t('Are you sure you want to discard the changes in these {0} files? This action cannot be undone.', resources.length);
2324+
2325+
const choice = await vscode.window.showWarningMessage(message, { modal: true }, confirmAction);
2326+
if (choice !== confirmAction) {
2327+
return;
2328+
}
2329+
23202330
await gitService.restore(repository.rootUri, resources.map(r => r.fsPath), { ref });
23212331
}));
23222332

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2374,7 +2374,7 @@ export function registerCLIChatCommands(
23742374
}));
23752375

23762376
disposableStore.add(vscode.commands.registerCommand('github.copilot.sessions.discardChanges', async (sessionResource: vscode.Uri, ref: string, ...resources: vscode.Uri[]) => {
2377-
if (!isUri(sessionResource) || resources.some(r => !isUri(r))) {
2377+
if (!isUri(sessionResource) || !ref || resources.length === 0 || resources.some(r => !isUri(r))) {
23782378
return;
23792379
}
23802380

@@ -2388,6 +2388,16 @@ export function registerCLIChatCommands(
23882388
return;
23892389
}
23902390

2391+
const confirmAction = l10n.t('Discard Changes');
2392+
const message = resources.length === 1
2393+
? l10n.t('Are you sure you want to discard the changes in \'{0}\'? This action cannot be undone.', basename(resources[0]))
2394+
: l10n.t('Are you sure you want to discard the changes in these {0} files? This action cannot be undone.', resources.length);
2395+
2396+
const choice = await vscode.window.showWarningMessage(message, { modal: true }, confirmAction);
2397+
if (choice !== confirmAction) {
2398+
return;
2399+
}
2400+
23912401
await gitService.restore(repository.rootUri, resources.map(r => r.fsPath), { ref });
23922402
}));
23932403

0 commit comments

Comments
 (0)