@@ -896,27 +896,51 @@ export function registerCommands(
896896
897897 const worktreePath = worktreeUri . fsPath ;
898898
899- // Create the worktree using git command
899+ // Create the worktree using a VS Code task
900900 progress . report ( { message : vscode . l10n . t ( 'Creating worktree at {0}...' , worktreePath ) } ) ;
901901
902902 const trackedBranchName = `${ remoteName } /${ branchName } ` ;
903903 const localBranchName = `pr-${ pullRequestModel . number } /${ branchName } ` ;
904904
905905 try {
906- // Execute git worktree add command
907- const terminal = vscode . window . createTerminal ( {
908- name : vscode . l10n . t ( 'Git Worktree' ) ,
909- cwd : repoRootPath ,
910- hideFromUser : true ,
906+ // Create a VS Code task to execute the git worktree command
907+ const taskDefinition : vscode . TaskDefinition = {
908+ type : 'shell'
909+ } ;
910+
911+ const shellExecution = new vscode . ShellExecution ( 'git' , [
912+ 'worktree' , 'add' ,
913+ '-b' , { value : localBranchName , quoting : vscode . ShellQuoting . Strong } ,
914+ { value : worktreePath , quoting : vscode . ShellQuoting . Strong } ,
915+ { value : trackedBranchName , quoting : vscode . ShellQuoting . Strong }
916+ ] , {
917+ cwd : repoRootPath
911918 } ) ;
912919
913- // Create worktree with a new local branch tracking the remote
914- terminal . sendText ( `git worktree add -b "${ localBranchName } " "${ worktreePath } " "${ trackedBranchName } " && exit` ) ;
915-
916- // Wait a bit for the command to complete
917- await new Promise ( resolve => setTimeout ( resolve , 2000 ) ) ;
920+ const task = new vscode . Task (
921+ taskDefinition ,
922+ vscode . TaskScope . Workspace ,
923+ vscode . l10n . t ( 'Create Worktree for Pull Request #{0}' , pullRequestModel . number ) ,
924+ 'git' ,
925+ shellExecution
926+ ) ;
918927
919- terminal . dispose ( ) ;
928+ // Execute the task and wait for completion
929+ const taskExecution = await vscode . tasks . executeTask ( task ) ;
930+
931+ // Wait for task to complete
932+ await new Promise < void > ( ( resolve , reject ) => {
933+ const disposable = vscode . tasks . onDidEndTaskProcess ( e => {
934+ if ( e . execution === taskExecution ) {
935+ disposable . dispose ( ) ;
936+ if ( e . exitCode === 0 ) {
937+ resolve ( ) ;
938+ } else {
939+ reject ( new Error ( vscode . l10n . t ( 'Git worktree command failed with exit code {0}' , e . exitCode ?. toString ( ) ?? 'unknown' ) ) ) ;
940+ }
941+ }
942+ } ) ;
943+ } ) ;
920944
921945 // Ask user if they want to open the worktree
922946 const openAction = vscode . l10n . t ( 'Open in New Window' ) ;
0 commit comments