@@ -570,7 +570,7 @@ export class VsCodeMessenger {
570570 ) ;
571571
572572 if ( currentBranch !== branch ) {
573- // Try to switch to the branch
573+ // Try to switch to the branch using VS Code Git API
574574 await vscode . window . withProgress (
575575 {
576576 location : vscode . ProgressLocation . Notification ,
@@ -579,39 +579,16 @@ export class VsCodeMessenger {
579579 } ,
580580 async ( ) => {
581581 try {
582- // First try a simple checkout
583- await this . ide . subprocess (
584- `git checkout ${ branch } ` ,
585- matchingWorkspace ,
586- ) ;
582+ // Use VS Code Git API for checkout
583+ await repo . checkout ( branch ) ;
587584 } catch ( checkoutError : any ) {
588585 console . log (
589- "Simple checkout failed, trying to fetch and checkout ..." ,
586+ "Checkout failed, trying to fetch first ..." ,
590587 checkoutError ,
591588 ) ;
592-
593- // If that fails, try fetching and then checking out
594- try {
595- await this . ide . subprocess (
596- `git fetch origin ${ branch } :${ branch } ` ,
597- matchingWorkspace ,
598- ) ;
599- await this . ide . subprocess (
600- `git checkout ${ branch } ` ,
601- matchingWorkspace ,
602- ) ;
603- } catch ( fetchError : any ) {
604- console . log (
605- "Fetch and checkout failed, trying checkout with tracking..." ,
606- fetchError ,
607- ) ;
608-
609- // Last attempt: checkout with tracking
610- await this . ide . subprocess (
611- `git checkout -b ${ branch } origin/${ branch } ` ,
612- matchingWorkspace ,
613- ) ;
614- }
589+ // If checkout fails, fetch and try again
590+ await repo . fetch ( ) ;
591+ await repo . checkout ( branch ) ;
615592 }
616593 } ,
617594 ) ;
@@ -624,7 +601,7 @@ export class VsCodeMessenger {
624601 } catch ( e : any ) {
625602 console . error ( "Failed to switch branch:" , e ) ;
626603 vscode . window . showErrorMessage (
627- `Failed to switch to branch ${ branch } : ${ e . message || "Unknown error" } ` ,
604+ `Failed to switch to branch ${ branch } : ${ e . message || String ( e ) } ` ,
628605 ) ;
629606 return ;
630607 }
0 commit comments