@@ -662,9 +662,20 @@ def find_reviewers(b) -> Optional[List[str]]:
662
662
return
663
663
664
664
665
- def create_gh_pr (b ):
665
+ def create_gh_pr (b , prefix ):
666
666
cout ("Creating PR for {}\n " , b .name , fg = "green" )
667
- cmd = ["gh" , "pr" , "create" , "--head" , b .name , "--base" , b .parent .name ]
667
+ parent_prefix = ""
668
+ if b .parent .name not in STACK_BOTTOMS :
669
+ parent_prefix = prefix
670
+ cmd = [
671
+ "gh" ,
672
+ "pr" ,
673
+ "create" ,
674
+ "--head" ,
675
+ f"{ prefix } { b .name } " ,
676
+ "--base" ,
677
+ f"{ parent_prefix } { b .parent .name } " ,
678
+ ]
668
679
match = re .match (r"([A-Z]{3,}-\d{1,})($|-.*)" , b .name )
669
680
reviewers = find_reviewers (b )
670
681
if match :
@@ -714,7 +725,7 @@ def create_gh_pr(b):
714
725
)
715
726
716
727
717
- def do_push (forest , * , force = False , pr = False ):
728
+ def do_push (forest , * , force = False , pr = False , remote_name = "origin" ):
718
729
if pr :
719
730
load_pr_info_for_forest (forest )
720
731
print_forest (forest )
@@ -781,6 +792,18 @@ def do_push(forest, *, force=False, pr=False):
781
792
if actions and not force :
782
793
confirm ()
783
794
795
+ # Figure out if we need to add a prefix to the branch
796
+ # ie. user:foo
797
+ # We should call gh repo set-default before doing that
798
+ val = run (["git" , "config" , f"remote.{ remote_name } .gh-resolved" ], check = False )
799
+ if val is not None and "/" in val :
800
+ # If there is a "/" in the gh-resolved it means that the repo where
801
+ # the should be created is not the same as the one where the push will
802
+ # be made, we need to add a prefix to the branch in the gh pr command
803
+ val = run (["git" , "config" , f"remote.{ remote_name } .url" ])
804
+ prefix = f'{ val .split (":" )[1 ].split ("/" )[0 ]} :'
805
+ else :
806
+ prefix = ""
784
807
for b , push , pr_action in actions :
785
808
if push :
786
809
cout ("Pushing {}\n " , b .name , fg = "green" )
@@ -808,7 +831,7 @@ def do_push(forest, *, force=False, pr=False):
808
831
out = True ,
809
832
)
810
833
elif pr_action == PR_CREATE :
811
- create_gh_pr (b )
834
+ create_gh_pr (b , prefix )
812
835
813
836
814
837
def cmd_stack_push (stack , args ):
@@ -1254,6 +1277,12 @@ def main():
1254
1277
choices = ["always" , "auto" , "never" ],
1255
1278
help = "Colorize output and error" ,
1256
1279
)
1280
+ parser .add_argument (
1281
+ "--remote-name" ,
1282
+ "-r" ,
1283
+ default = "origin" ,
1284
+ help = "name of the git remote where branches will be pushed" ,
1285
+ )
1257
1286
1258
1287
subparsers = parser .add_subparsers (required = True , dest = "command" )
1259
1288
0 commit comments