Rev 1: A new plugin which simplifies my workflow for creating a new feature branch. in http://bzr.arbash-meinel.com/plugins/start

John Arbash Meinel john at arbash-meinel.com
Wed Jan 21 17:44:09 GMT 2009


At http://bzr.arbash-meinel.com/plugins/start

------------------------------------------------------------
revno: 1
revision-id: john at arbash-meinel.com-20090121174359-jwfe45i4hol31ny6
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: start
timestamp: Wed 2009-01-21 11:43:59 -0600
message:
  A new plugin which simplifies my workflow for creating a new feature branch.
-------------- next part --------------
=== added file '__init__.py'
--- a/__init__.py	1970-01-01 00:00:00 +0000
+++ b/__init__.py	2009-01-21 17:43:59 +0000
@@ -0,0 +1,63 @@
+# Copyright (C) 2009 Canonical Ltd
+#
+# 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; either version 2 of the License, or
+# (at your option) any later version.
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Provide the 'start' command.
+
+This command creates a new local branch from a 'trunk' branch, then switches
+the current working tree over to it. Basically, it is equivalent to:
+
+  bzr branch $TRUNK $NEW_BRANCH
+  bzr switch $NEW_BRANCH
+"""
+
+from bzrlib import (
+    commands,
+    errors,
+    )
+
+
+class cmd_start(commands.Command):
+    """Create a new branch, and start working on it.
+    """
+
+    takes_args = ['location']
+    takes_options = []
+
+    def run(self, location=None):
+        from bzrlib import (
+            branch,
+            config,
+            osutils,
+            switch,
+            workingtree,
+            )
+        wt, _ = workingtree.WorkingTree.open_containing('.')
+        c = config.LocationConfig(wt.basedir)
+        trunk_branch = c.get_user_option('trunk_branch')
+        if trunk_branch is None:
+            raise errors.BzrCommandError('No "trunk_branch" configured')
+        b = branch.Branch.open(trunk_branch)
+        new_b = b.bzrdir.sprout(location).open_branch()
+        switch.switch(wt.bzrdir, new_b)
+commands.register_command(cmd_start)
+
+
+def load_tests(standard_tests, module, loader):
+    standard_tests.addTests(loader.loadTestsFromModuleNames(
+        [__name__ + '.' + x for x in [
+        'test_start',
+    ]]))
+    return standard_tests

=== added file 'test_start.py'
--- a/test_start.py	1970-01-01 00:00:00 +0000
+++ b/test_start.py	2009-01-21 17:43:59 +0000
@@ -0,0 +1,53 @@
+# Copyright (C) 2009 Canonical Ltd
+#
+# 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; either version 2 of the License, or
+# (at your option) any later version.
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Tests for the 'start' plugin"""
+
+from bzrlib import (
+    branch,
+    config,
+    errors,
+    osutils,
+    tests,
+    workingtree,
+    )
+
+
+class TestStart(tests.TestCaseWithTransport):
+
+    def create_trunk_and_config(self):
+        builder = self.make_branch_builder('trunk')
+        builder.build_snapshot('rev1', None,
+            [('add', ('', 'root-id', 'directory', None))])
+        b = builder.get_branch()
+        c = config.LocationConfig(osutils.getcwd())
+        c.set_user_option('trunk_branch', b.base)
+        b.create_checkout('tree', lightweight=True)
+
+    def test_no_trunk_branch(self):
+        self.run_bzr_error(['No "trunk_branch" configured'],
+            'start foobar')
+
+    def test_create_new_branch(self):
+        self.create_trunk_and_config()
+        self.run_bzr('start ../foobar', working_dir='tree')
+        # Make sure the 'foobar' branch was created, and is at the right
+        # revision
+        b = branch.Branch.open('foobar')
+        self.assertEqual((1, 'rev1'), b.last_revision_info())
+        # And that the local tree is pointing at it
+        tree = workingtree.WorkingTree.open('tree')
+        self.assertEqual(b.base, tree.branch.base)



More information about the bazaar-commits mailing list