@@ -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
0 commit comments