File tree Expand file tree Collapse file tree
commands/checkoutToCommand Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -331,6 +331,9 @@ export class CheckoutToCommand extends BaseCommand {
331331 default :
332332 try {
333333 await git . checkout ( newBranchName ) ;
334+ if ( await git . hasUpstreamBranch ( newBranchName ) ) {
335+ await git . pullCurrentBranch ( ) ;
336+ }
334337 } catch ( e ) {
335338 throw new Error ( 'Failed to checkout the selected branch.' ) ;
336339 }
@@ -363,6 +366,9 @@ export class CheckoutToCommand extends BaseCommand {
363366
364367 try {
365368 await git . checkout ( newBranch ) ;
369+ if ( await git . hasUpstreamBranch ( newBranch ) ) {
370+ await git . pullCurrentBranch ( ) ;
371+ }
366372 } catch ( e ) {
367373 throw new Error ( 'Failed to checkout the selected branch.' ) ;
368374 }
@@ -417,6 +423,9 @@ export class CheckoutToCommand extends BaseCommand {
417423 // Checkout the selected branch
418424 try {
419425 await git . checkout ( newBranch ) ;
426+ if ( await git . hasUpstreamBranch ( newBranch ) ) {
427+ await git . pullCurrentBranch ( ) ;
428+ }
420429 } catch ( e ) {
421430 throw new Error ( 'Failed to checkout the selected branch.' ) ;
422431 }
Original file line number Diff line number Diff line change @@ -464,6 +464,17 @@ export class GitExecutor {
464464 return await this . #checkRemoteBranchExists( branchName ) ;
465465 }
466466
467+ async hasUpstreamBranch ( branchName : string ) : Promise < boolean > {
468+ const command = `git rev-parse --abbrev-ref ${ branchName } @{upstream}` ;
469+
470+ try {
471+ await this . #execGitCommand( command ) ;
472+ return true ;
473+ } catch {
474+ return false ;
475+ }
476+ }
477+
467478 async pushBranchToGitHub ( branchName : string ) : Promise < void > {
468479 const command = `git push -u origin ${ branchName } ` ;
469480
You can’t perform that action at this time.
0 commit comments