diff --git a/openstack_releases/cmds/list_changes.py b/openstack_releases/cmds/list_changes.py index 5be2fb16c8..489e5cc25d 100644 --- a/openstack_releases/cmds/list_changes.py +++ b/openstack_releases/cmds/list_changes.py @@ -258,11 +258,6 @@ def main(): else: print('no team name given, cannot report on governance status') - if series == defaults.RELEASE: - branch = 'master' - else: - branch = 'stable/' + series - # If there are no releases listed, this is probably a new # deliverable file for initializing a new series. We don't # need to list its changes. @@ -290,17 +285,49 @@ def main(): print('%s %s exists on git server already' % (project['repo'], new_release['version'])) + # Decide which branch we're going to try to clone. We need + # the repo checked out before we can tell if the stable + # branch really exists, but zuul-cloner will fall back to + # master if it doesn't. + if series in (defaults.RELEASE, '_independent'): + clone_branch = 'master' + else: + clone_branch = 'stable/' + series + # Check out the code. - print('\nChecking out repository {}'.format(project['repo'])) + print('\nChecking out repository {} to {}'.format( + project['repo'], clone_branch)) subprocess.check_call( ['zuul-cloner', - '--branch', branch, + '--branch', clone_branch, '--workspace', workdir, 'git://git.openstack.org', project['repo'], ] ) + # Determine which branch we should actually be looking + # at. Assume any series for which there is no stable + # branch will be on 'master'. + if gitutils.stable_branch_exists(workdir, project['repo'], series): + branch = 'stable/' + series + else: + branch = 'master' + + if branch != clone_branch: + # Check out the repo again to the right branch if we + # didn't get it the first time. + print('\nUpdating repository {} to {}'.format( + project['repo'], branch)) + subprocess.check_call( + ['zuul-cloner', + '--branch', branch, + '--workspace', workdir, + 'git://git.openstack.org', + project['repo'], + ] + ) + # look at the previous tag for the parent of the commit # getting the new release previous_tag = gitutils.get_latest_tag( diff --git a/openstack_releases/gitutils.py b/openstack_releases/gitutils.py index 0551042714..365deda63d 100644 --- a/openstack_releases/gitutils.py +++ b/openstack_releases/gitutils.py @@ -120,6 +120,22 @@ def _filter_branches(output): ] +def stable_branch_exists(workdir, repo, series): + "Does the stable/series branch exist?" + remote_match = 'remotes/origin/stable/%s' % series + try: + containing_branches = _filter_branches( + subprocess.check_output( + ['git', 'branch', '-a'], + cwd=os.path.join(workdir, repo), + ).decode('utf-8') + ) + return (remote_match in containing_branches) + except subprocess.CalledProcessError as e: + print('ERROR checking for branch: %s [%s]' % (e, e.output.strip())) + return False + + def check_branch_sha(workdir, repo, series, master, sha): """Check if the SHA is in the targeted branch.