summaryrefslogtreecommitdiff
path: root/morphlib
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2012-07-31 16:16:20 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2012-08-01 13:27:53 +0000
commit9370ccddabbbe89120710732d9029e61f3c97cb8 (patch)
tree49e9ae68d7cf38a8d6de055fbe8381b015ec1072 /morphlib
parent5406a395ae8940bc7fd58fe6f3b7647fa4f4dceb (diff)
downloadmorph-9370ccddabbbe89120710732d9029e61f3c97cb8.tar.gz
move command show-system-branch to plugin
deduce_system_branch is now duplicated because other commands not yet moved require it.
Diffstat (limited to 'morphlib')
-rwxr-xr-xmorphlib/app.py12
-rw-r--r--morphlib/plugins/branch_and_merge_plugin.py30
2 files changed, 29 insertions, 13 deletions
diff --git a/morphlib/app.py b/morphlib/app.py
index 50fdbca5..dbcf2c2b 100755
--- a/morphlib/app.py
+++ b/morphlib/app.py
@@ -643,18 +643,6 @@ class Morph(cliapp.Application):
return os.path.dirname(cwd[len(minedir):])
- def cmd_show_system_branch(self, args):
- '''Print name of current system branch.
-
- This must be run in the system branch's ``morphs`` repository.
-
- '''
-
- system_branch = self._deduce_system_branch()
- if system_branch is None:
- raise cliapp.AppException("Can't determine system branch")
- self.output.write('%s\n' % system_branch)
-
def cmd_edit(self, args):
'''Edit a component in a system branch.'''
diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py
index ff738b2d..1f20191b 100644
--- a/morphlib/plugins/branch_and_merge_plugin.py
+++ b/morphlib/plugins/branch_and_merge_plugin.py
@@ -32,6 +32,8 @@ class BranchAndMergePlugin(cliapp.Plugin):
arg_synopsis='NEW [OLD]')
self.app.add_subcommand('checkout', self.checkout,
arg_synopsis='BRANCH')
+ self.app.add_subcommand('show-system-branch', self.show_system_branch,
+ arg_synopsis='')
def disable(self):
pass
@@ -46,6 +48,21 @@ class BranchAndMergePlugin(cliapp.Plugin):
dirname = os.path.dirname(dirname)
return None
+ @classmethod
+ def deduce_system_branch(cls):
+ minedir = cls.deduce_mine_directory()
+ if minedir is None:
+ return None
+
+ if not minedir.endswith('/'):
+ minedir += '/'
+
+ cwd = os.getcwd()
+ if not cwd.startswith(minedir):
+ return None
+
+ return os.path.dirname(cwd[len(minedir):])
+
@staticmethod
def clone_to_directory(app, dirname, reponame, ref):
'''Clone a repository below a directory.
@@ -76,7 +93,6 @@ class BranchAndMergePlugin(cliapp.Plugin):
resolver.push_url(reponame)),
resolver.pull_url(reponame)], cwd=dirname)
- # Update remotes.
app.runcmd(['git', 'remote', 'update'], cwd=dirname)
def init(self, args):
@@ -146,3 +162,15 @@ class BranchAndMergePlugin(cliapp.Plugin):
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.
+
+ '''
+
+ 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)