1
1
import logging
2
2
3
- from codegen .git .schemas .enums import FetchResult
4
- from codegen .git .utils .branch_sync import BranchSyncResult , fetch_highside_branch , get_highside_origin
3
+ from codegen .git .schemas .github import GithubType
5
4
from codegen .runner .models .codemod import Codemod
5
+ from codegen .runner .utils .branch_sync import get_remote_for_github_type
6
6
from codegen .sdk .codebase .factory .codebase_factory import CodebaseType
7
7
8
8
logger = logging .getLogger (__name__ )
@@ -22,9 +22,12 @@ def set_up_base_branch(self, base_branch: str | None) -> None:
22
22
if self .codebase .op .is_branch_checked_out (base_branch ):
23
23
return
24
24
25
- res = self ._pull_highside_to_lowside (base_branch )
26
- if res is BranchSyncResult .SUCCESS :
27
- self .codebase .checkout (branch = base_branch , remote = True )
25
+ # fetch the base branch from highside (do not checkout yet)
26
+ highside_remote = get_remote_for_github_type (op = self .codebase .op , github_type = GithubType .Github )
27
+ self .codebase .op .fetch_remote (highside_remote .name , refspec = f"{ base_branch } :{ base_branch } " )
28
+
29
+ # checkout the base branch (and possibly sync graph)
30
+ self .codebase .checkout (branch = base_branch )
28
31
29
32
def set_up_head_branch (self , head_branch : str , force_push_head_branch : bool ):
30
33
"""Set-up head branch by pushing latest highside branch to lowside and fetching the branch (so that it can be checked out later)."""
@@ -43,22 +46,9 @@ def set_up_head_branch(self, head_branch: str, force_push_head_branch: bool):
43
46
if force_push_head_branch :
44
47
return
45
48
46
- res = self ._pull_highside_to_lowside (head_branch )
47
- if res is BranchSyncResult .SUCCESS :
48
- self .codebase .op .fetch_remote ("origin" , refspec = f"{ head_branch } :{ head_branch } " )
49
-
50
- def _pull_highside_to_lowside (self , branch_name : str ):
51
- """Grabs the latest highside branch `branch_name` and pushes it to the lowside."""
52
- # Step 1: checkout branch that tracks highside remote
53
- res = fetch_highside_branch (op = self .codebase .op , branch_name = branch_name )
54
- if res == FetchResult .REFSPEC_NOT_FOUND :
55
- return BranchSyncResult .BRANCH_NOT_FOUND
56
-
57
- # Step 2: push branch up to lowside
58
- logger .info (f"Pushing branch: { branch_name } from highside to lowside w/ force=False ..." )
59
- lowside_origin = self .codebase .op .git_cli .remote ("origin" )
60
- self .codebase .op .push_changes (remote = lowside_origin , refspec = f"{ branch_name } :{ branch_name } " , force = False )
61
- return BranchSyncResult .SUCCESS
49
+ # fetch the head branch from highside (do not checkout yet)
50
+ highside_remote = get_remote_for_github_type (op = self .codebase .op , github_type = GithubType .Github )
51
+ self .codebase .op .fetch_remote (highside_remote .name , refspec = f"{ head_branch } :{ head_branch } " )
62
52
63
53
def reset_branch (self , base_branch : str , head_branch : str ) -> None :
64
54
logger .info (f"Checking out base branch { base_branch } ..." )
@@ -76,8 +66,8 @@ def push_changes_to_remote(self, codemod: Codemod, head_branch: str, force_push:
76
66
return False
77
67
78
68
# =====[ Push changes highside ]=====
79
- highside_origin = get_highside_origin ( self .codebase .op )
80
- highside_res = self .codebase .op .push_changes (remote = highside_origin , refspec = f"{ head_branch } :{ head_branch } " , force = force_push )
69
+ highside_remote = get_remote_for_github_type ( op = self .codebase .op , github_type = GithubType . Github )
70
+ highside_res = self .codebase .op .push_changes (remote = highside_remote , refspec = f"{ head_branch } :{ head_branch } " , force = force_push )
81
71
return not any (push_info .flags & push_info .ERROR for push_info in highside_res )
82
72
83
73
# TODO: move bunch of codebase git operations into this class.
0 commit comments