@@ -808,35 +808,55 @@ def _easyconfigs_pr_common(paths, ecs, start_branch=None, pr_branch=None, start_
808808 # commit
809809 git_repo .index .commit (commit_msg )
810810
811- # push to GitHub
812- github_url = '[email protected] :%s/%s.git' % (
target_account ,
pr_target_repo )
811+ push_branch_to_github (git_repo , target_account , pr_target_repo , pr_branch )
812+
813+ return file_info , deleted_paths , git_repo , pr_branch , diff_stat
814+
815+
816+ def create_remote (git_repo , account , repo ):
817+ """Create remote in specified git working directory for specified account & repository."""
818+
819+ github_url = '[email protected] :%s/%s.git' % (
account ,
repo )
813820 salt = '' .join (random .choice (ascii_letters ) for _ in range (5 ))
814- remote_name = 'github_%s_%s' % (target_account , salt )
821+ remote_name = 'github_%s_%s' % (account , salt )
822+
823+ try :
824+ remote = git_repo .create_remote (remote_name , github_url )
825+ except GitCommandError as err :
826+ raise EasyBuildError ("Failed to create remote %s for %s: %s" , remote_name , github_url , err )
827+
828+ return remote
829+
830+
831+ def push_branch_to_github (git_repo , target_account , target_repo , branch ):
832+ """Push specified branch to GitHub from specified git repository."""
833+
834+ # push to GitHub
835+ remote = create_remote (git_repo , target_account , target_repo )
815836
816837 dry_run = build_option ('dry_run' ) or build_option ('extended_dry_run' )
817838
818- push_branch_msg = "pushing branch '%s' to remote '%s' (%s)" % (pr_branch , remote_name , github_url )
839+ github_url = '[email protected] :%s/%s.git' % (
target_account ,
target_repo )
840+
841+ push_branch_msg = "pushing branch '%s' to remote '%s' (%s)" % (branch , remote .name , github_url )
819842 if dry_run :
820843 print_msg (push_branch_msg + ' [DRY RUN]' , log = _log )
821844 else :
822845 print_msg (push_branch_msg , log = _log )
823846 try :
824- my_remote = git_repo .create_remote (remote_name , github_url )
825- res = my_remote .push (pr_branch )
847+ res = remote .push (branch )
826848 except GitCommandError as err :
827- raise EasyBuildError ("Failed to push branch '%s' to GitHub (%s): %s" , pr_branch , github_url , err )
849+ raise EasyBuildError ("Failed to push branch '%s' to GitHub (%s): %s" , branch , github_url , err )
828850
829851 if res :
830852 if res [0 ].ERROR & res [0 ].flags :
831853 raise EasyBuildError ("Pushing branch '%s' to remote %s (%s) failed: %s" ,
832- pr_branch , my_remote , github_url , res [0 ].summary )
854+ branch , remote , github_url , res [0 ].summary )
833855 else :
834- _log .debug ("Pushed branch %s to remote %s (%s): %s" , pr_branch , my_remote , github_url , res [0 ].summary )
856+ _log .debug ("Pushed branch %s to remote %s (%s): %s" , branch , remote , github_url , res [0 ].summary )
835857 else :
836858 raise EasyBuildError ("Pushing branch '%s' to remote %s (%s) failed: empty result" ,
837- pr_branch , my_remote , github_url )
838-
839- return file_info , deleted_paths , git_repo , pr_branch , diff_stat
859+ branch , remote , github_url )
840860
841861
842862def is_patch_for (patch_name , ec ):
0 commit comments