@@ -243,7 +243,8 @@ def git_get_title_and_message(begin, end):
243
243
return (len (titles ), title , message )
244
244
245
245
246
- def git_pull_request (target_remote = None , target_branch = None ,
246
+ def git_pull_request (* ,
247
+ target_remote = None , target_branch = None ,
247
248
title = None , message = None ,
248
249
comment = None ,
249
250
rebase = True ,
@@ -254,7 +255,9 @@ def git_pull_request(target_remote=None, target_branch=None,
254
255
fork = True ,
255
256
setup_only = False ,
256
257
branch_prefix = None ,
257
- dry_run = False ):
258
+ dry_run = False ,
259
+ allow_noop = False ,
260
+ ):
258
261
branch = git_get_branch_name ()
259
262
if not branch :
260
263
LOG .critical ("Unable to find current branch" )
@@ -326,7 +329,7 @@ def git_pull_request(target_remote=None, target_branch=None,
326
329
retcode = fork_and_push_pull_request (
327
330
g , hosttype , repo , rebase , target_remote , target_branch , branch ,
328
331
user , title , message , comment , force_editor , tag_previous_revision ,
329
- fork , setup_only , branch_prefix , dry_run ,
332
+ fork , setup_only , branch_prefix , dry_run , allow_noop = allow_noop ,
330
333
)
331
334
332
335
approve_login_password (host = hostname , user = user , password = password )
@@ -435,7 +438,7 @@ def fork_and_push_pull_request(g, hosttype, repo_to_fork, rebase,
435
438
title , message , comment ,
436
439
force_editor , tag_previous_revision , fork ,
437
440
setup_only , branch_prefix ,
438
- dry_run = False ):
441
+ dry_run = False , * , allow_noop ):
439
442
440
443
g_user = g .get_user ()
441
444
@@ -582,10 +585,16 @@ def fork_and_push_pull_request(g, hosttype, repo_to_fork, rebase,
582
585
title = title ,
583
586
body = message )
584
587
except github .GithubException as e :
585
- LOG .critical (
586
- _format_github_exception ("create pull request" , e )
587
- )
588
- return 50
588
+ if allow_noop and any ((
589
+ error .get ("message" , "" ).startswith ("No commits between" )
590
+ for error in e .data .get ("errors" , [])
591
+ )):
592
+ LOG .info ("Did not create pull-request, no new commits." )
593
+ else :
594
+ LOG .critical (
595
+ _format_github_exception ("create pull request" , e )
596
+ )
597
+ return 50
589
598
else :
590
599
LOG .info ("Pull-request created: %s" , pull .html_url )
591
600
@@ -693,6 +702,13 @@ def build_parser():
693
702
default = False ,
694
703
help = "Just setup the fork repo"
695
704
)
705
+ git_config_add_argument (
706
+ parser ,
707
+ "--allow-noop" ,
708
+ action = "store_true" ,
709
+ default = False ,
710
+ help = "If the target branch is up-to-date, do nothing."
711
+ )
696
712
return parser
697
713
698
714
@@ -724,6 +740,7 @@ def main():
724
740
setup_only = args .setup_only ,
725
741
branch_prefix = args .branch_prefix ,
726
742
dry_run = args .dry_run ,
743
+ allow_noop = args .allow_noop ,
727
744
)
728
745
except Exception :
729
746
LOG .error ("Unable to send pull request" , exc_info = True )
0 commit comments