def gentoo_build(script_name, logger, release_repo_uri, options):
"""Main function that creates a versioned ebuild file and releases it."""
ebuilds = find_ebuilds(logger, options.category)
+ repo = git.Repo()
if options.tag_from_debian:
- git_tag = tag_from_debian_changelog(logger)
+ git_tag = tag_from_debian_changelog(logger, repo)
else:
- git_tag = get_latest_tag(logger)
+ git_tag = get_latest_tag(logger, repo)
for ebuild in ebuilds:
ebuild.set_version(git_tag)
ebuild.set_git_commit(git_tag)
# Checkout release repository
branch = options.release_branch
if branch is None:
- branch = git.Repo().active_branch.name
+ branch = repo.active_branch.name
logger.info("Check out {branch} branch of {repo} to "
"{dir}...".format(repo=release_repo_uri, branch=branch,
dir=tmpdir))
release_repo.git.push("origin", branch)
if options.tag_from_debian:
- push_tag(logger, git_tag, options.dry_run)
+ push_tag(logger, repo, git_tag, options.dry_run)
finally:
if options.keep:
logger.warning("Keeping temporary git clone in {dir} as "
ebuild=" ".join(ebuild_files)))
return [Ebuild(logger, e, category) for e in ebuild_files]
-def tag_from_debian_changelog(logger):
+def tag_from_debian_changelog(logger, repo):
"""Create a tag from the version specified in debian/changelog.
Returns the name of the created tag.
"""
new_tag = version.replace('~', '_').replace(':', ',')
resolve_existing_msg = (" Have you forgotten to create a new Debian "
"changelog entry?")
- tag_head_commit(logger, new_tag, resolve_existing_msg)
+ tag_head_commit(logger, repo, new_tag, resolve_existing_msg)
return new_tag
-def tag_head_commit(logger, new_tag, resolve_existing_msg=""):
+def tag_head_commit(logger, repo, new_tag, resolve_existing_msg=""):
"""Tags the head commit with the given tag name."""
- repo = git.Repo('.')
current_commit = repo.commit(repo.active_branch)
tags = [t.name for t in repo.tags if t.commit == current_commit]
if len(tags) > 0:
weburl += "/commit/" + commit.hexsha[0:7]
return commit.hexsha[0:7] + ' (' + weburl + ')'
-def get_latest_tag(logger):
+def get_latest_tag(logger, repo):
"""Get the tag name for the branch head commit.
The function will fail if the branch head commit is not tagged or has
multiple tags.
"""
- repo = git.Repo('.')
current_commit = repo.commit(repo.active_branch)
tags = [t.name for t in repo.tags if t.commit == current_commit]
if len(tags) == 0:
logger.info('Use tag "{tag}" as release version.'.format(tag=tag))
return tag
-def push_tag(logger, tag, dry_run):
+def push_tag(logger, repo, tag, dry_run):
"""Pushed the given git tag unless it is a dry run."""
if dry_run:
logger.info("Not pushing tag {tag} as dry run was "
"requested.".format(tag=tag))
else:
logger.info("Pushing tag {tag}...".format(tag=tag))
- repo = git.Repo()
repo.git.push("origin", tag)
if __name__ == '__main__':
- main()
\ No newline at end of file
+ main()