diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2013-08-07 15:56:08 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2013-08-08 13:37:45 +0000 |
commit | 27a0d807da50f4db27e87728e1599333a314b619 (patch) | |
tree | 78717617c412d606e6fd7489ed64f56b39fdc1b2 | |
parent | 3a87d9f94b8d30f6e988c790d23789a3e0bb56c0 (diff) | |
download | definitions-27a0d807da50f4db27e87728e1599333a314b619.tar.gz |
workflow-tools: check branch roots have systems
It's rather easy to accidentally try to create a system branch of
the `morph` repository rather than the `morphs` repository.
This commit verifies that a checked out branch contains system
morphologies, otherwise it aborts and cleans up.
-rw-r--r-- | morphlib/plugins/branch_and_merge_new_plugin.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/morphlib/plugins/branch_and_merge_new_plugin.py b/morphlib/plugins/branch_and_merge_new_plugin.py index 5a33d47b..e09417d2 100644 --- a/morphlib/plugins/branch_and_merge_new_plugin.py +++ b/morphlib/plugins/branch_and_merge_new_plugin.py @@ -15,6 +15,7 @@ import cliapp +import glob import logging import os import shutil @@ -22,6 +23,13 @@ import shutil import morphlib +class BranchRootHasNoSystemsError(cliapp.AppException): + def __init__(self, repo, ref): + cliapp.AppException.__init__( + self, 'System branch root repository %s ' + 'has no system morphologies at ref %s' % (repo, ref)) + + class SimpleBranchAndMergePlugin(cliapp.Plugin): '''Add subcommands for handling workspaces and system branches.''' @@ -131,6 +139,10 @@ class SimpleBranchAndMergePlugin(cliapp.Plugin): gd = sb.clone_cached_repo( cached_repo, system_branch, system_branch) + + if not self._checkout_has_systems(gd): + raise BranchRootHasNoSystemsError(root_url, system_branch) + gd.update_submodules(self.app) gd.update_remotes() except BaseException as e: @@ -202,6 +214,10 @@ class SimpleBranchAndMergePlugin(cliapp.Plugin): gd = sb.clone_cached_repo(cached_repo, system_branch, base_ref) gd.branch(system_branch, base_ref) gd.checkout(system_branch) + + if not self._checkout_has_systems(gd): + raise BranchRootHasNoSystemsError(root_url, base_ref) + gd.update_submodules(self.app) gd.update_remotes() except BaseException as e: @@ -267,3 +283,12 @@ class SimpleBranchAndMergePlugin(cliapp.Plugin): msg="WARNING: %(message)s", message=str(e), error=True) + @staticmethod + def _checkout_has_systems(gd): + for filename in glob.iglob(os.path.join(gd.dirname, '*.morph')): + with open(filename) as mf: + morphology = morphlib.morph2.Morphology(mf.read()) + if morphology['kind'] == 'system': + return True + return False + |