From 339c05186f49d0203618b5979cf4e76d6d1fc3e6 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 31 Jul 2013 11:55:57 +0000 Subject: Re-implement "morph init" using the new Workspace class Move "morph init" into a plugin, and remove it from the previously existing plugin. This keeps all the old, tricky code in the old plugin, and moves new, clean code into a new plugin. Eventually the old plugin can be removed, since it'll be empty. --- morphlib/plugins/branch_and_merge_new_plugin.py | 63 +++++++++++++++++++++++++ morphlib/plugins/branch_and_merge_plugin.py | 45 ------------------ without-test-modules | 1 + 3 files changed, 64 insertions(+), 45 deletions(-) create mode 100644 morphlib/plugins/branch_and_merge_new_plugin.py diff --git a/morphlib/plugins/branch_and_merge_new_plugin.py b/morphlib/plugins/branch_and_merge_new_plugin.py new file mode 100644 index 00000000..2c92156f --- /dev/null +++ b/morphlib/plugins/branch_and_merge_new_plugin.py @@ -0,0 +1,63 @@ +# Copyright (C) 2012,2013 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +import cliapp + +import morphlib + + +class SimpleBranchAndMergePlugin(cliapp.Plugin): + + '''Add subcommands for handling workspaces and system branches.''' + + def enable(self): + self.app.add_subcommand('init', self.init, arg_synopsis='[DIR]') + + def disable(self): + pass + + def init(self, args): + '''Initialize a workspace directory. + + Command line argument: + + * `DIR` is the directory to use as a workspace, and defaults to + the current directory. + + This creates a workspace, either in the current working directory, + or if `DIR` is given, in that directory. If the directory doesn't + exist, it is created. If it does exist, it must be empty. + + You need to run `morph init` to initialise a workspace, or none + of the other system branching tools will work: they all assume + an existing workspace. Note that a workspace only exists on your + machine, not on the git server. + + Example: + + morph init /src/workspace + cd /src/workspace + + ''' + + if not args: + args = ['.'] + elif len(args) > 1: + raise morphlib.Error('init must get at most one argument') + + ws = morphlib.workspace.create(args[0]) + self.app.status(msg='Initialized morph workspace', chatty=True) + diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py index 737ac463..2121885f 100644 --- a/morphlib/plugins/branch_and_merge_plugin.py +++ b/morphlib/plugins/branch_and_merge_plugin.py @@ -57,7 +57,6 @@ class BranchAndMergePlugin(cliapp.Plugin): def enable(self): # User-facing commands - self.app.add_subcommand('init', self.init, arg_synopsis='[DIR]') self.app.add_subcommand('branch', self.branch, arg_synopsis='REPO NEW [OLD]') self.app.add_subcommand('checkout', self.checkout, @@ -547,50 +546,6 @@ class BranchAndMergePlugin(cliapp.Plugin): return system_key, metadata_cache_id_lookup - def init(self, args): - '''Initialize a workspace directory. - - Command line argument: - - * `DIR` is the directory to use as a workspace, and defaults to - the current directory. - - This creates a workspace, either in the current working directory, - or if `DIR` is given, in that directory. If the directory doesn't - exist, it is created. If it does exist, it must be empty. - - You need to run `morph init` to initialise a workspace, or none - of the other system branching tools will work: they all assume - an existing workspace. Note that a workspace only exists on your - machine, not on the git server. - - Example: - - morph init /src/workspace - cd /src/workspace - - ''' - - if not args: - args = ['.'] - elif len(args) > 1: - raise cliapp.AppException('init must get at most one argument') - - dirname = args[0] - - # verify the workspace is empty (and thus, can be used) or - # create it if it doesn't exist yet - if os.path.exists(dirname): - if os.listdir(dirname) != []: - raise cliapp.AppException('can only initialize empty ' - 'directory as a workspace: %s' % - dirname) - else: - os.makedirs(dirname) - - os.mkdir(os.path.join(dirname, '.morph')) - self.app.status(msg='Initialized morph workspace', chatty=True) - def _create_branch(self, workspace, branch_name, repo, original_ref): '''Create a branch called branch_name based off original_ref. diff --git a/without-test-modules b/without-test-modules index c5d59442..9e2f39aa 100644 --- a/without-test-modules +++ b/without-test-modules @@ -27,3 +27,4 @@ morphlib/writeexts.py morphlib/plugins/copy-artifacts_plugin.py morphlib/plugins/trovectl_plugin.py morphlib/plugins/gc_plugin.py +morphlib/plugins/branch_and_merge_new_plugin.py -- cgit v1.2.1