@@ -859,78 +859,80 @@ export function registerCommands(
859859 */
860860 telemetry . sendTelemetryEvent ( 'pr.checkoutInWorktree' ) ;
861861
862- return vscode . window . withProgress (
863- {
864- location : vscode . ProgressLocation . Notification ,
865- title : vscode . l10n . t ( 'Checking out Pull Request #{0} in worktree' , pullRequestModel . number ) ,
866- } ,
867- async ( progress ) => {
868- // Generate a branch name for the worktree
869- const branchName = prHead . ref ;
870- const remoteName = pullRequestModel . remote . remoteName ;
871-
872- // Fetch the PR branch first
873- progress . report ( { message : vscode . l10n . t ( 'Fetching branch {0}...' , branchName ) } ) ;
862+ // Prepare for parallel operations
863+ const repoRootPath = repositoryToUse . rootUri . fsPath ;
864+ const parentDir = pathLib . dirname ( repoRootPath ) ;
865+ const defaultWorktreePath = pathLib . join ( parentDir , `pr-${ pullRequestModel . number } ` ) ;
866+ const branchName = prHead . ref ;
867+ const remoteName = pullRequestModel . remote . remoteName ;
868+
869+ // Run fetch and worktree location selection in parallel
870+ const [ , worktreeUri ] = await Promise . all ( [
871+ // Fetch the PR branch
872+ ( async ( ) => {
874873 try {
875874 await repositoryToUse . fetch ( { remote : remoteName , ref : branchName } ) ;
876875 } catch ( e ) {
877876 const errorMessage = e instanceof Error ? e . message : String ( e ) ;
878877 Logger . appendLine ( `Failed to fetch branch ${ branchName } : ${ errorMessage } ` , logId ) ;
879878 // Continue even if fetch fails - the branch might already be available locally
880879 }
880+ } ) ( ) ,
881+ // Ask user for worktree location
882+ vscode . window . showSaveDialog ( {
883+ defaultUri : vscode . Uri . file ( defaultWorktreePath ) ,
884+ title : vscode . l10n . t ( 'Select Worktree Location' ) ,
885+ saveLabel : vscode . l10n . t ( 'Create Worktree' ) ,
886+ } )
887+ ] ) ;
881888
882- // Ask user for worktree location
883- const repoRootPath = repositoryToUse . rootUri . fsPath ;
884- const parentDir = pathLib . dirname ( repoRootPath ) ;
885- const defaultWorktreePath = pathLib . join ( parentDir , `pr-${ pullRequestModel . number } ` ) ;
886-
887- const worktreeUri = await vscode . window . showSaveDialog ( {
888- defaultUri : vscode . Uri . file ( defaultWorktreePath ) ,
889- title : vscode . l10n . t ( 'Select Worktree Location' ) ,
890- saveLabel : vscode . l10n . t ( 'Create Worktree' ) ,
891- } ) ;
892-
893- if ( ! worktreeUri ) {
894- return ; // User cancelled
895- }
889+ if ( ! worktreeUri ) {
890+ return ; // User cancelled
891+ }
896892
897- const worktreePath = worktreeUri . fsPath ;
893+ const worktreePath = worktreeUri . fsPath ;
894+ const trackedBranchName = `${ remoteName } /${ branchName } ` ;
898895
899- // Create the worktree using the git extension API
900- progress . report ( { message : vscode . l10n . t ( 'Creating worktree at {0}...' , worktreePath ) } ) ;
896+ try {
897+ // Check if the createWorktree API is available
898+ if ( ! repositoryToUse . createWorktree ) {
899+ throw new Error ( vscode . l10n . t ( 'Git worktree API is not available. Please update VS Code to the latest version.' ) ) ;
900+ }
901901
902- const trackedBranchName = `${ remoteName } /${ branchName } ` ;
903-
904- try {
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- }
902+ // Store reference to ensure type narrowing
903+ const createWorktree = repositoryToUse . createWorktree ;
909904
905+ // Create the worktree with progress
906+ await vscode . window . withProgress (
907+ {
908+ location : vscode . ProgressLocation . Notification ,
909+ title : vscode . l10n . t ( 'Creating worktree for Pull Request #{0}...' , pullRequestModel . number ) ,
910+ } ,
911+ async ( ) => {
910912 // Use the git extension's createWorktree API
911- await repositoryToUse . createWorktree ( {
913+ await createWorktree ( {
912914 path : worktreePath ,
913915 commitish : trackedBranchName ,
914916 branch : branchName
915917 } ) ;
918+ }
919+ ) ;
916920
917- // Ask user if they want to open the worktree
918- const openAction = vscode . l10n . t ( 'Open in New Window' ) ;
919- const result = await vscode . window . showInformationMessage (
920- vscode . l10n . t ( 'Worktree created for Pull Request #{0}' , pullRequestModel . number ) ,
921- openAction
922- ) ;
921+ // Ask user if they want to open the worktree (after progress is finished)
922+ const openAction = vscode . l10n . t ( 'Open in New Window' ) ;
923+ const result = await vscode . window . showInformationMessage (
924+ vscode . l10n . t ( 'Worktree created for Pull Request #{0}' , pullRequestModel . number ) ,
925+ openAction
926+ ) ;
923927
924- if ( result === openAction ) {
925- await commands . openFolder ( worktreeUri , { forceNewWindow : true } ) ;
926- }
927- } catch ( e ) {
928- const errorMessage = e instanceof Error ? e . message : String ( e ) ;
929- Logger . error ( `Failed to create worktree: ${ errorMessage } ` , logId ) ;
930- return vscode . window . showErrorMessage ( vscode . l10n . t ( 'Failed to create worktree: {0}' , errorMessage ) ) ;
931- }
928+ if ( result === openAction ) {
929+ await commands . openFolder ( worktreeUri , { forceNewWindow : true } ) ;
932930 }
933- ) ;
931+ } catch ( e ) {
932+ const errorMessage = e instanceof Error ? e . message : String ( e ) ;
933+ Logger . error ( `Failed to create worktree: ${ errorMessage } ` , logId ) ;
934+ return vscode . window . showErrorMessage ( vscode . l10n . t ( 'Failed to create worktree: {0}' , errorMessage ) ) ;
935+ }
934936 } ) ,
935937 ) ;
936938
0 commit comments