summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-08-06 12:03:02 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-08-06 16:28:19 +0100
commit16f17f5d713960ab3ed9981b0b554e3657fb82f9 (patch)
treeb155a53d5d80b18981bb90730a5ab027d54afd35
parent437ce27de0fec13d3efa939c04d17164049ccbfc (diff)
downloaddefinitions-16f17f5d713960ab3ed9981b0b554e3657fb82f9.tar.gz
Re-implement "morph branch" using new infrastructure
-rw-r--r--morphlib/plugins/branch_and_merge_new_plugin.py73
-rw-r--r--morphlib/plugins/branch_and_merge_plugin.py42
2 files changed, 73 insertions, 42 deletions
diff --git a/morphlib/plugins/branch_and_merge_new_plugin.py b/morphlib/plugins/branch_and_merge_new_plugin.py
index 479bd2f9..f52dba6f 100644
--- a/morphlib/plugins/branch_and_merge_new_plugin.py
+++ b/morphlib/plugins/branch_and_merge_new_plugin.py
@@ -32,6 +32,8 @@ class SimpleBranchAndMergePlugin(cliapp.Plugin):
self.app.add_subcommand(
'checkout', self.checkout, arg_synopsis='REPO BRANCH')
self.app.add_subcommand(
+ 'branch', self.branch, arg_synopsis='REPO NEW [OLD]')
+ self.app.add_subcommand(
'show-system-branch', self.show_system_branch, arg_synopsis='')
self.app.add_subcommand(
'show-branch-root', self.show_branch_root, arg_synopsis='')
@@ -138,6 +140,77 @@ class SimpleBranchAndMergePlugin(cliapp.Plugin):
self._remove_branch_dir_safe(ws.root, root_dir)
raise
+ def branch(self, args):
+ '''Create a new system branch.
+
+ Command line arguments:
+
+ * `REPO` is a repository URL.
+ * `NEW` is the name of the new system branch.
+ * `OLD` is the point from which to branch, and defaults to `master`.
+
+ This creates a new system branch. It needs to be run in an
+ existing workspace (see `morph workspace`). It creates a new
+ git branch in the clone of the repository in the workspace. The
+ system branch will not be visible on the git server until you
+ push your changes to the repository.
+
+ Example:
+
+ cd /src/workspace
+ morph branch baserock:baserock:morphs jrandom/new-feature
+
+ '''
+
+ if len(args) not in [2, 3]:
+ raise cliapp.AppException(
+ 'morph branch needs name of branch as parameter')
+
+ root_url = args[0]
+ system_branch = args[1]
+ base_ref = 'master' if len(args) == 2 else args[2]
+ origin_base_ref = 'origin/%s' % base_ref
+
+ self._require_git_user_config()
+
+ # Open the workspace first thing, so user gets a quick error if
+ # we're not inside a workspace.
+ ws = morphlib.workspace.open('.')
+
+ # Make sure the root repository is in the local git repository
+ # cache, and is up to date.
+ lrc, rrc = morphlib.util.new_repo_caches(self.app)
+ cached_repo = lrc.get_updated_repo(root_url)
+
+ # Make sure the system branch doesn't exist yet.
+ if cached_repo.ref_exists(system_branch):
+ raise cliapp.AppException(
+ 'branch %s already exists in repository %s' %
+ (system_branch, root_url))
+
+ # Make sure the base_ref exists.
+ cached_repo.resolve_ref(base_ref)
+
+ root_dir = ws.get_default_system_branch_directory_name(system_branch)
+
+ try:
+ # Create the system branch directory. This doesn't yet clone
+ # the root repository there.
+ sb = morphlib.sysbranchdir.create(
+ root_dir, root_url, system_branch)
+
+ gd = sb.clone_cached_repo(cached_repo, system_branch, base_ref)
+ gd.branch(system_branch, base_ref)
+ gd.checkout(system_branch)
+ gd.update_submodules(self.app)
+ gd.update_remotes()
+ except BaseException as e:
+ # Oops. Clean up.
+ logging.error('Caught exception: %s' % str(e))
+ logging.info('Removing half-finished branch %s' % system_branch)
+ self._remove_branch_dir_safe(ws.root, root_dir)
+ raise
+
def show_system_branch(self, args):
'''Show the name of the current system branch.'''
diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py
index 6f3a8c87..62a9f925 100644
--- a/morphlib/plugins/branch_and_merge_plugin.py
+++ b/morphlib/plugins/branch_and_merge_plugin.py
@@ -57,8 +57,6 @@ class BranchAndMergePlugin(cliapp.Plugin):
def enable(self):
# User-facing commands
- self.app.add_subcommand('branch', self.branch,
- arg_synopsis='REPO NEW [OLD]')
self.app.add_subcommand('merge', self.merge,
arg_synopsis='BRANCH')
self.app.add_subcommand('edit', self.edit,
@@ -575,46 +573,6 @@ class BranchAndMergePlugin(cliapp.Plugin):
self.remove_branch_dir_safe(workspace, branch_name)
raise
- @warns_git_identity
- def branch(self, args):
- '''Create a new system branch.
-
- Command line arguments:
-
- * `REPO` is a repository URL.
- * `NEW` is the name of the new system branch.
- * `OLD` is the point from which to branch, and defaults to `master`.
-
- This creates a new system branch. It needs to be run in an
- existing workspace (see `morph workspace`). It creates a new
- git branch in the clone of the repository in the workspace. The
- system branch will not be visible on the git server until you
- push your changes to the repository.
-
- Example:
-
- cd /src/workspace
- morph branch baserock:baserock:morphs jrandom/new-feature
-
- '''
-
- if len(args) not in [2, 3]:
- raise cliapp.AppException('morph branch needs name of branch '
- 'as parameter')
-
- repo = args[0]
- new_branch = args[1]
- commit = 'master' if len(args) == 2 else args[2]
-
- self.lrc, self.rrc = morphlib.util.new_repo_caches(self.app)
- if self.get_cached_repo(repo).ref_exists(new_branch):
- raise cliapp.AppException('branch %s already exists in '
- 'repository %s' % (new_branch, repo))
-
- # Create the system branch directory.
- workspace = self.deduce_workspace()
- self._create_branch(workspace, new_branch, repo, commit)
-
def checkout_repository(self, branch_dir, repo, ref, parent_ref=None):
'''Make a chunk or stratum repository available for a system branch