@@ -40,7 +40,8 @@ def do_sync():
4040
4141 origin = providers [repo ['origin' ]['provider' ]].get_project (repo ['origin' ]['name' ])
4242 branches = origin .get_active_branches ()
43- branch_commits = {x : origin .get_last_commit_on_branch (x ) for x in branches }
43+ all_branches = origin .get_all_branches ()
44+ branch_commits = {x : origin .get_last_commit_on_branch (x ) for x in origin .get_all_branches ()}
4445 tags = origin .get_tags ()
4546
4647 mirror_refs = {}
@@ -54,7 +55,7 @@ def do_sync():
5455 mirror_tags [name ] = mirror_ref .get_tags ()
5556
5657 for x in mirror_ref .get_active_branches ():
57- if x not in branches :
58+ if x not in all_branches :
5859 log .info ("Branch {} available on mirror but not on origin" .format (x ))
5960 branches .append (x )
6061 need_sync = True
@@ -79,19 +80,21 @@ def do_sync():
7980 git_repo .add_remote (downstream .get_url_from_project (), name )
8081
8182 for x in branches :
82- upstream_commit = branch_commits [x ]
83- upstream_commit_ref = git_repo .get_commit (upstream_commit )
83+ upstream_commit = branch_commits [x ] if x in branch_commits else ''
84+ upstream_commit_ref = git_repo .get_commit (upstream_commit ) if x in branch_commits else ''
8485 downstream_commit = downstream .get_last_commit_on_branch (x )
8586 downstream_commit_ref = git_repo .get_commit (downstream_commit )
8687
8788 if upstream_commit == downstream_commit :
8889 continue
8990
90- if git_repo .is_ancestor (downstream_commit_ref , upstream_commit_ref ):
91+ if upstream_commit_ref != '' and git_repo .is_ancestor (downstream_commit_ref ,
92+ upstream_commit_ref ):
9193 # Upstream is newer
9294 log .info ("Pushing origin commits to mirror" )
9395 git_repo .push (upstream_commit , x , name )
94- elif git_repo .is_ancestor (upstream_commit_ref , downstream_commit_ref ):
96+ elif upstream_commit_ref == '' or git_repo .is_ancestor (upstream_commit_ref ,
97+ downstream_commit_ref ):
9598 # Downstream is newer
9699 log .info ("Pushing mirror commits to origin" )
97100 git_repo .push (downstream_commit , x , 'origin' )
0 commit comments