@@ -896,50 +896,22 @@ export function registerCommands(
896896
897897 const worktreePath = worktreeUri . fsPath ;
898898
899- // Create the worktree using a VS Code task
899+ // Create the worktree using the git extension API
900900 progress . report ( { message : vscode . l10n . t ( 'Creating worktree at {0}...' , worktreePath ) } ) ;
901901
902902 const trackedBranchName = `${ remoteName } /${ branchName } ` ;
903- const localBranchName = branchName ;
904903
905904 try {
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
918- } ) ;
919-
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- ) ;
905+ // Check if the createWorktree API is available
906+ if ( ! repositoryToUse . createWorktree ) {
907+ throw new Error ( vscode . l10n . t ( 'Git worktree API is not available. Please update VS Code to the latest version.' ) ) ;
908+ }
927909
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- } ) ;
910+ // Use the git extension's createWorktree API
911+ await repositoryToUse . createWorktree ( {
912+ path : worktreePath ,
913+ commitish : trackedBranchName ,
914+ branch : branchName
943915 } ) ;
944916
945917 // Ask user if they want to open the worktree
0 commit comments