diff options
author | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-08-28 16:43:51 +0000 |
---|---|---|
committer | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-08-29 18:44:52 +0100 |
commit | b78ac0f72aa2fc4815131bb2bbd883a373c62e48 (patch) | |
tree | 457b02ccb81f3d15df8e66edeefa1f93d948aed9 | |
parent | 384689e00d8bed6b1e5373dda6fc407ae9d197b6 (diff) | |
download | morph-b78ac0f72aa2fc4815131bb2bbd883a373c62e48.tar.gz |
Use .morph-system-branch directories to identify branch directories
The commands "morph branch" and "morph checkout" now create a
.morph-system-branch directory for each system branch. This is the
per-branch analogue to the .morph directory for a workspace.
The .morph-system-branch directories make it possible to store
state and other information for system branches. They also make
deducing the current system branch more robust and clear.
4 files changed, 22 insertions, 25 deletions
diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py index 2304fc0f..3145b774 100644 --- a/morphlib/plugins/branch_and_merge_plugin.py +++ b/morphlib/plugins/branch_and_merge_plugin.py @@ -56,22 +56,20 @@ class BranchAndMergePlugin(cliapp.Plugin): if os.path.isdir(dot_morph): return dirname dirname = os.path.dirname(dirname) - return None + raise cliapp.AppException("Can't find the workspace directory") @classmethod def deduce_system_branch(cls): workspace = cls.deduce_workspace() - if workspace is None: - return None - - if not workspace.endswith('/'): - workspace += '/' - cwd = os.getcwd() - if not cwd.startswith(workspace): - return None + dirname = os.getcwd() + while dirname != workspace and dirname != '/': + system_branch_dir = os.path.join(dirname, '.morph-system-branch') + if os.path.isdir(system_branch_dir): + return os.path.dirname(system_branch_dir[len(workspace)+1:]) + dirname = os.path.dirname(dirname) - return os.path.dirname(cwd[len(workspace):]) + raise cliapp.AppException("Can't find the system branch directory") @staticmethod def clone_to_directory(app, dirname, reponame, ref): @@ -211,10 +209,7 @@ class BranchAndMergePlugin(cliapp.Plugin): def workspace(self, args): '''Find morph workspace directory from current working directory.''' - dirname = self.deduce_workspace() - if dirname is None: - raise cliapp.AppException("Can't find the workspace directory") - self.app.output.write('%s\n' % dirname) + self.app.output.write('%s\n' % self.deduce_workspace()) def branch(self, args): '''Branch the whole system.''' @@ -229,6 +224,10 @@ class BranchAndMergePlugin(cliapp.Plugin): # Create the system branch directory. os.makedirs(new_branch) + # Create a .morph-system-branch directory to clearly identify + # this directory as a morph system branch. + os.mkdir(os.path.join(new_branch, '.morph-system-branch')) + # Clone into system branch directory. new_repo = os.path.join(new_branch, self.system_repo_base) self.clone_to_directory(self.app, new_repo, self.system_repo_name, @@ -250,22 +249,19 @@ class BranchAndMergePlugin(cliapp.Plugin): # Create the system branch directory. os.makedirs(system_branch) + # Create a .morph-system-branch directory to clearly identify + # this directory as a morph system branch. + os.mkdir(os.path.join(system_branch, '.morph-system-branch')) + # Clone into system branch directory. new_repo = os.path.join(system_branch, self.system_repo_base) self.clone_to_directory(self.app, new_repo, self.system_repo_name, system_branch) def show_system_branch(self, args): - '''Print name of current system branch. - - This must be run in the system branch's ``morphs`` repository. + '''Print name of current system branch.''' - ''' - - system_branch = self.deduce_system_branch() - if system_branch is None: - raise cliapp.AppException("Can't determine system branch") - self.app.output.write('%s\n' % system_branch) + self.app.output.write('%s\n' % self.deduce_system_branch()) def merge(self, args): '''Merge specified repositories from another system branch.''' @@ -296,8 +292,6 @@ class BranchAndMergePlugin(cliapp.Plugin): app = self.app workspace = self.deduce_workspace() system_branch = self.deduce_system_branch() - if system_branch is None: - raise morphlib.Error('Cannot deduce system branch') morphs_dirname = os.path.join(workspace, system_branch, 'morphs') if morphs_dirname is None: diff --git a/tests.branching/branch-creates-new-system-branch-not-from-master.stdout b/tests.branching/branch-creates-new-system-branch-not-from-master.stdout index 7dfffab1..af1ad6cd 100644 --- a/tests.branching/branch-creates-new-system-branch-not-from-master.stdout +++ b/tests.branching/branch-creates-new-system-branch-not-from-master.stdout @@ -6,6 +6,7 @@ d ./.morph/cache/gits d ./.morph/cache/gits/file_morphs d ./.morph/cache/gits/file_morphs/.git d ./newbranch +d ./newbranch/.morph-system-branch d ./newbranch/morphs d ./newbranch/morphs/.git f ./newbranch/morphs/hello-stratum.morph diff --git a/tests.branching/branch-creates-new-system-branch.stdout b/tests.branching/branch-creates-new-system-branch.stdout index d2884b8c..e22ef30b 100644 --- a/tests.branching/branch-creates-new-system-branch.stdout +++ b/tests.branching/branch-creates-new-system-branch.stdout @@ -6,6 +6,7 @@ d ./.morph/cache/gits d ./.morph/cache/gits/file_morphs d ./.morph/cache/gits/file_morphs/.git d ./newbranch +d ./newbranch/.morph-system-branch d ./newbranch/morphs d ./newbranch/morphs/.git f ./newbranch/morphs/hello-stratum.morph diff --git a/tests.branching/checkout-existing-branch.stdout b/tests.branching/checkout-existing-branch.stdout index 7f405fdb..47043bbe 100644 --- a/tests.branching/checkout-existing-branch.stdout +++ b/tests.branching/checkout-existing-branch.stdout @@ -6,6 +6,7 @@ d ./.morph/cache/gits d ./.morph/cache/gits/file_morphs d ./.morph/cache/gits/file_morphs/.git d ./master +d ./master/.morph-system-branch d ./master/morphs d ./master/morphs/.git f ./master/morphs/hello-stratum.morph |