@@ -104,10 +104,12 @@ def git_remote_url(remote="origin"):
104
104
105
105
106
106
def git_get_config (option , default ):
107
- out = _run_shell_command (
108
- ["git" , "config" , "--get" , "git-pull-request." + option ],
109
- output = True , raise_on_error = False )
110
- return out or default
107
+ try :
108
+ return _run_shell_command (
109
+ ["git" , "config" , "--get" , "git-pull-request." + option ],
110
+ output = True )
111
+ except RuntimeError :
112
+ return default
111
113
112
114
113
115
def git_config_add_argument (parser , option , * args , ** kwargs ):
@@ -116,10 +118,9 @@ def git_config_add_argument(parser, option, *args, **kwargs):
116
118
if isboolean and default is None :
117
119
default = False
118
120
default = git_get_config (option [2 :], default )
119
- if default :
120
- if isboolean :
121
- default = distutils .util .strtobool (default )
122
- kwargs ["default" ] = default
121
+ if isboolean and isinstance (default , str ):
122
+ default = distutils .util .strtobool (default )
123
+ kwargs ["default" ] = default
123
124
return parser .add_argument (option , * args , ** kwargs )
124
125
125
126
@@ -250,7 +251,8 @@ def git_pull_request(target_remote=None, target_branch=None,
250
251
download = None ,
251
252
tag_previous_revision = False ,
252
253
fork = True ,
253
- setup_only = False ):
254
+ setup_only = False ,
255
+ branch_prefix = None ):
254
256
branch = git_get_branch_name ()
255
257
if not branch :
256
258
LOG .critical ("Unable to find current branch" )
@@ -321,7 +323,7 @@ def git_pull_request(target_remote=None, target_branch=None,
321
323
target_branch , branch , user , title , message ,
322
324
comment ,
323
325
force_editor , tag_previous_revision ,
324
- fork , setup_only )
326
+ fork , setup_only , branch_prefix )
325
327
approve_login_password (host = hostname , user = user , password = password )
326
328
327
329
@@ -408,7 +410,7 @@ def fork_and_push_pull_request(g, hosttype, repo_to_fork, rebase,
408
410
target_remote , target_branch , branch , user ,
409
411
title , message , comment ,
410
412
force_editor , tag_previous_revision , fork ,
411
- setup_only ):
413
+ setup_only , branch_prefix ):
412
414
413
415
g_user = g .get_user ()
414
416
@@ -430,6 +432,14 @@ def fork_and_push_pull_request(g, hosttype, repo_to_fork, rebase,
430
432
forked = True
431
433
LOG .info ("Forked repository: %s" , repo_forked .html_url )
432
434
435
+ if branch_prefix is None and not forked :
436
+ branch_prefix = g_user .login
437
+
438
+ if branch_prefix :
439
+ remote_branch = "{}/{}" .format (branch_prefix , branch )
440
+ else :
441
+ remote_branch = branch
442
+
433
443
if forked :
434
444
remote_to_push = git_remote_matching_url (repo_forked .clone_url )
435
445
@@ -443,9 +453,7 @@ def fork_and_push_pull_request(g, hosttype, repo_to_fork, rebase,
443
453
remote_to_push , repo_forked .clone_url ])
444
454
LOG .info ("Added forked repository as remote `%s'" , remote_to_push )
445
455
head = "{}:{}" .format (user , branch )
446
- remote_branch = branch
447
456
else :
448
- remote_branch = "{}/{}" .format (g_user .login , branch )
449
457
remote_to_push = target_remote
450
458
head = "{}:{}" .format (repo_to_fork .owner .login , remote_branch )
451
459
@@ -579,6 +587,9 @@ def build_parser():
579
587
help = "Title of the pull request." )
580
588
parser .add_argument ("--message" , "-m" ,
581
589
help = "Message of the pull request." )
590
+ git_config_add_argument (parser ,
591
+ "--branch-prefix" ,
592
+ help = "Prefix remote branch" )
582
593
git_config_add_argument (parser , "--no-rebase" , "-R" ,
583
594
action = "store_true" ,
584
595
help = "Don't rebase branch before pushing." )
@@ -618,7 +629,6 @@ def build_parser():
618
629
const = "never" ,
619
630
help = "Don't fork to create the pull-request"
620
631
)
621
-
622
632
git_config_add_argument (
623
633
parser ,
624
634
"--setup-only" ,
@@ -653,7 +663,8 @@ def main():
653
663
download = args .download ,
654
664
tag_previous_revision = args .tag_previous_revision ,
655
665
fork = args .fork ,
656
- setup_only = args .setup_only
666
+ setup_only = args .setup_only ,
667
+ branch_prefix = args .branch_prefix
657
668
)
658
669
except Exception :
659
670
LOG .error ("Unable to send pull request" , exc_info = True )
0 commit comments