@@ -15,7 +15,6 @@ import { Disposable, DisposableStore } from '../../../util/vs/base/common/lifecy
1515import { ResourceSet } from '../../../util/vs/base/common/map' ;
1616import { isEqual } from '../../../util/vs/base/common/resources' ;
1717import { createTimeout } from '../../inlineEdits/common/common' ;
18- import { ToolName } from '../../tools/common/toolNames' ;
1918import { IToolsService } from '../../tools/common/toolsService' ;
2019import { IChatSessionWorkspaceFolderService } from '../common/chatSessionWorkspaceFolderService' ;
2120import { ChatSessionWorktreeFile , ChatSessionWorktreeProperties , IChatSessionWorktreeService } from '../common/chatSessionWorktreeService' ;
@@ -254,7 +253,7 @@ export abstract class FolderRepositoryManager extends Disposable implements IFol
254253 // Check for uncommitted changes and prompt user before creating worktree
255254 let uncommittedChangesAction : 'move' | 'copy' | 'skip' | 'cancel' | undefined = undefined ;
256255 if ( ( ! sessionId || isUntitledSessionId ( sessionId ) ) && ! worktreeProperties ) {
257- uncommittedChangesAction = await this . promptForUncommittedChangesAction ( sessionId , toolInvocationToken , token ) ;
256+ uncommittedChangesAction = await this . promptForUncommittedChangesAction ( sessionId , repository , branch , toolInvocationToken , token ) ;
258257 if ( uncommittedChangesAction === 'cancel' ) {
259258 return { folder, repository, worktree, worktreeProperties, trusted : true , cancelled : true } ;
260259 }
@@ -374,18 +373,16 @@ export abstract class FolderRepositoryManager extends Disposable implements IFol
374373 */
375374 private async promptForUncommittedChangesAction (
376375 sessionId : string | undefined ,
376+ repositoryUri : vscode . Uri ,
377+ branch : string | undefined ,
377378 toolInvocationToken : vscode . ChatParticipantToolToken ,
378379 token : vscode . CancellationToken
379380 ) : Promise < 'move' | 'copy' | 'skip' | 'cancel' | undefined > {
380- const uncommittedChanges = await this . getUncommittedChangesPromptData ( sessionId , token ) ;
381+ const uncommittedChanges = await this . getUncommittedChanges ( repositoryUri , branch , token ) ;
381382 if ( ! uncommittedChanges ) {
382383 return undefined ;
383384 }
384385
385- if ( ! this . toolsService . getTool ( 'vscode_get_modified_files_confirmation' ) ) {
386- return this . promptForUncommittedChangesActionOld ( sessionId , toolInvocationToken , token ) ;
387- }
388-
389386 const isDelegation = ! sessionId ;
390387 const title = isDelegation
391388 ? l10n . t ( 'Delegate to Copilot CLI' )
@@ -422,48 +419,6 @@ export abstract class FolderRepositoryManager extends Disposable implements IFol
422419 }
423420 }
424421
425- private async promptForUncommittedChangesActionOld (
426- sessionId : string | undefined ,
427- toolInvocationToken : vscode . ChatParticipantToolToken ,
428- token : vscode . CancellationToken
429- ) : Promise < 'move' | 'copy' | 'skip' | 'cancel' | undefined > {
430- const isDelegation = ! sessionId ;
431- const title = isDelegation
432- ? l10n . t ( 'Delegate to Copilot CLI' )
433- : l10n . t ( 'Uncommitted Changes' ) ;
434- const message = isDelegation
435- ? l10n . t ( 'Copilot CLI will work in an isolated worktree to implement your requested changes.' )
436- + '\n\n'
437- + l10n . t ( 'The selected repository has uncommitted changes. Should these changes be included in the new worktree?' )
438- : l10n . t ( 'The selected repository has uncommitted changes. Should these changes be included in the new worktree?' ) ;
439-
440- const copyChanges = l10n . t ( 'Copy Changes' ) ;
441- const moveChanges = l10n . t ( 'Move Changes' ) ;
442- const skipChanges = l10n . t ( 'Skip Changes' ) ;
443- const cancel = l10n . t ( 'Cancel' ) ;
444- const buttons = [ copyChanges , moveChanges , skipChanges , cancel ] ;
445- const input = {
446- title,
447- message,
448- buttons
449- } ;
450- const result = await this . toolsService . invokeTool ( ToolName . CoreConfirmationToolWithOptions , { input, toolInvocationToken } , token ) ;
451-
452- const firstResultPart = result . content . at ( 0 ) ;
453- const selection = firstResultPart instanceof LanguageModelTextPart ? firstResultPart . value : undefined ;
454-
455- switch ( selection ?. toUpperCase ( ) ) {
456- case moveChanges . toUpperCase ( ) :
457- return 'move' ;
458- case copyChanges . toUpperCase ( ) :
459- return 'copy' ;
460- case skipChanges . toUpperCase ( ) :
461- return 'skip' ;
462- default :
463- return 'cancel' ;
464- }
465- }
466-
467422 private getSelectedUncommittedChangesAction (
468423 result : vscode . LanguageModelToolResult ,
469424 options : readonly string [ ]
@@ -482,15 +437,21 @@ export abstract class FolderRepositoryManager extends Disposable implements IFol
482437 return undefined ;
483438 }
484439
485- private async getUncommittedChangesPromptData (
486- sessionId : string | undefined ,
440+ private async getUncommittedChanges (
441+ folderPath : vscode . Uri ,
442+ branch : string | undefined ,
487443 token : vscode . CancellationToken
488444 ) : Promise < { repository : vscode . Uri ; modifiedFiles : Array < { uri : vscode . Uri ; originalUri ?: vscode . Uri ; insertions ?: number ; deletions ?: number } > } | undefined > {
489- const repository = await this . getRepositoryForUncommittedChanges ( sessionId ) ;
445+ const repository = await this . gitService . getRepository ( folderPath ) ;
490446 if ( ! repository ) {
491447 return undefined ;
492448 }
493449
450+ // If the current branch is not the same as the requested branch, we cannot reliably determine the uncommitted changes, so skip the confirmation.
451+ if ( branch && repository . headBranchName !== branch ) {
452+ return undefined ;
453+ }
454+
494455 const modifiedFiles = await this . getModifiedFilesForConfirmation ( repository . rootUri , repository , token ) ;
495456 if ( modifiedFiles . length === 0 ) {
496457 return undefined ;
@@ -502,27 +463,6 @@ export abstract class FolderRepositoryManager extends Disposable implements IFol
502463 } ;
503464 }
504465
505- private async getRepositoryForUncommittedChanges ( sessionId : string | undefined ) : Promise < ReturnType < IGitService [ 'activeRepository' ] [ 'get' ] > | undefined > {
506- if ( sessionId && isUntitledSessionId ( sessionId ) ) {
507- const folder = this . _newSessionFolders . get ( sessionId ) ?. uri
508- ?? await this . workspaceFolderService . getSessionWorkspaceFolder ( sessionId ) ;
509- if ( folder ) {
510- return await this . gitService . getRepository ( folder , false ) ;
511- }
512- // No folder selected, fall through to the active repository check.
513- }
514-
515- if ( sessionId && ! isUntitledSessionId ( sessionId ) ) {
516- return undefined ;
517- }
518-
519- if ( ! isWelcomeView ( this . workspaceService ) && this . workspaceService . getWorkspaceFolders ( ) . length === 1 ) {
520- return this . gitService . activeRepository . get ( ) ;
521- }
522-
523- return undefined ;
524- }
525-
526466 private async getModifiedFilesForConfirmation (
527467 repositoryUri : vscode . Uri ,
528468 repository : NonNullable < ReturnType < IGitService [ 'activeRepository' ] [ 'get' ] > > ,
0 commit comments