From 15423d837376cd580f54ef15e2bbc8eddaecf2b7 Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Wed, 22 Jan 2014 12:37:07 +0100 Subject: [PATCH] gentoo_build: Support running in a detached head. --- gentoo_build | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/gentoo_build b/gentoo_build index dbef0aa..4809883 100755 --- a/gentoo_build +++ b/gentoo_build @@ -238,9 +238,7 @@ def gentoo_build(script_name, logger, release_repo_uri, options): tmpdir = tempfile.mkdtemp(prefix=script_name+".") try: # Checkout release repository - branch = options.release_branch - if branch is None: - branch = repo.active_branch.name + branch = get_release_repo_branch(logger, options, repo) logger.info("Check out {branch} branch of {repo} to " "{dir}...".format(repo=release_repo_uri, branch=branch, dir=tmpdir)) @@ -273,6 +271,22 @@ def gentoo_build(script_name, logger, release_repo_uri, options): else: shutil.rmtree(tmpdir) +def get_release_repo_branch(logger, options, repo): + """Return the branch to use for the release repo.""" + branch = options.release_branch + if branch is None: + try: + branch = repo.active_branch.name + except TypeError as error: + msg = ("Getting the active branch name failed: {msg}\nPlease " + "specify the branch for the release repository one on the " + "command line or in the {env} environment variable if you " + "are in a detached head.".format(msg=error.message, + env=ENV_RELEASE_BRANCH)) + logger.error(msg) + sys.exit(1) + return branch + def update_manifest(logger, chroot_name, chroot_user, workdir, ebuild_path): """Update manifest file in a Gentoo chroot.""" cmd = ["schroot", "-c", chroot_name, "-u", chroot_user, @@ -332,7 +346,7 @@ def tag_from_debian_changelog(logger, repo): def tag_head_commit(logger, repo, new_tag, resolve_existing_msg=""): """Tags the head commit with the given tag name.""" - current_commit = repo.commit(repo.active_branch) + current_commit = repo.head.commit tags = [t.name for t in repo.tags if t.commit == current_commit] if len(tags) > 0: if len(tags) == 1 and tags[0] == new_tag: @@ -371,7 +385,7 @@ def get_latest_tag(logger, repo): The function will fail if the branch head commit is not tagged or has multiple tags. """ - current_commit = repo.commit(repo.active_branch) + current_commit = repo.head.commit tags = [t.name for t in repo.tags if t.commit == current_commit] if len(tags) == 0: logger.error('No tag found for commit {commit}.\nHave you tagged your ' -- 2.39.5