Skip to content

Commit c2c693d

Browse files
authored
Copilot CLI updates to worktree creation/storage (#1890)
* Copilot CLI updates to worktree creation/storage * Fix tests
1 parent 70622f9 commit c2c693d

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@ export class CopilotCLIWorktreeManager {
4040
@IVSCodeExtensionContext private readonly extensionContext: IVSCodeExtensionContext,
4141
@IRunCommandExecutionService private readonly commandExecutionService: IRunCommandExecutionService) { }
4242

43-
async createWorktreeIfNeeded(sessionId: string, stream: vscode.ChatResponseStream): Promise<string | undefined> {
44-
const isolationEnabled = this._sessionIsolation.get(sessionId) ?? false;
45-
if (!isolationEnabled) {
46-
return undefined;
47-
}
48-
43+
async createWorktree(stream: vscode.ChatResponseStream): Promise<string | undefined> {
4944
try {
5045
const worktreePath = await this.commandExecutionService.executeCommand('git.createWorktreeWithDefaults') as string | undefined;
5146
if (worktreePath) {
@@ -382,7 +377,7 @@ export class CopilotCLIChatSessionParticipant {
382377
const id = SessionIdForCLI.parse(resource);
383378

384379
const workingDirectory = chatSessionContext.isUntitled ?
385-
await this.worktreeManager.createWorktreeIfNeeded(id, stream) :
380+
(this.worktreeManager.getIsolationPreference(id) ? await this.worktreeManager.createWorktree(stream) : undefined) :
386381
this.worktreeManager.getWorktreePath(id);
387382

388383
const session = chatSessionContext.isUntitled ?
@@ -393,6 +388,10 @@ export class CopilotCLIChatSessionParticipant {
393388
stream.warning(vscode.l10n.t('Chat session not found.'));
394389
return undefined;
395390
}
391+
392+
if (chatSessionContext.isUntitled && workingDirectory) {
393+
await this.worktreeManager.storeWorktreePath(session.sessionId, workingDirectory);
394+
}
396395
disposables.add(session.attachStream(stream));
397396
disposables.add(session.attachPermissionHandler(async (permissionRequest: PermissionRequest) => requestPermission(permissionRequest, this.toolsService, request.toolInvocationToken, token)));
398397

src/extension/chatSessions/vscode-node/test/copilotCLIChatSessionParticipant.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ class FakeSummarizerProvider extends mock<ChatSummarizerProvider>() {
5757
}
5858

5959
class FakeWorktreeManager extends mock<CopilotCLIWorktreeManager>() {
60-
override createWorktreeIfNeeded = vi.fn(async () => undefined);
60+
override createWorktree = vi.fn(async () => undefined);
6161
override storeWorktreePath = vi.fn(async () => { });
6262
override getWorktreePath = vi.fn((_id: string) => undefined);
63+
override getIsolationPreference = vi.fn(() => true);
6364
}
6465

6566
interface CreateSessionArgs { prompt: string | undefined; modelId: string | undefined; workingDirectory: string | undefined }

0 commit comments

Comments
 (0)