]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
gentoo_build: Support running in a detached head.
authorBenjamin Drung <benjamin.drung@profitbricks.com>
Wed, 22 Jan 2014 11:37:07 +0000 (12:37 +0100)
committerBenjamin Drung <benjamin.drung@profitbricks.com>
Wed, 22 Jan 2014 11:37:07 +0000 (12:37 +0100)
gentoo_build

index dbef0aa9e302e0840c73a44de124ad0accce4b14..48098830977d6bd39ef8a10476a6dd39ea6b27a9 100755 (executable)
@@ -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 '