Rev 4535: (jam) Add 'bzr switch -b' to create the branch and switch to it. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Tue Jul 14 17:27:48 BST 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4535 [merge]
revision-id: pqm at pqm.ubuntu.com-20090714162740-3nro58lxslrcfyh4
parent: pqm at pqm.ubuntu.com-20090714150506-zspaa7037mm7x9hi
parent: john at arbash-meinel.com-20090709151857-0halwp51u1on5p1n
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2009-07-14 17:27:40 +0100
message:
(jam) Add 'bzr switch -b' to create the branch and switch to it.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/tests/blackbox/test_switch.py test_switch.py-20071122111948-0c5en6uz92bwl76h-1
=== modified file 'NEWS'
--- a/NEWS 2009-07-14 13:19:52 +0000
+++ b/NEWS 2009-07-14 16:27:40 +0000
@@ -80,6 +80,11 @@
behavior.
(Vincent Ladeuil, #206577)
+* ``bzr switch --create-branch/-b`` can now be used to create and switch
+ to a new branch. Supplying a name without a ``/`` will create the branch
+ relative to the existing branch. (similar to how ``bzr switch name``
+ works when the branch already exists.) (John Arbash Meinel)
+
Bug Fixes
*********
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2009-07-14 13:56:21 +0000
+++ b/bzrlib/builtins.py 2009-07-14 16:27:40 +0000
@@ -5324,10 +5324,13 @@
takes_args = ['to_location']
takes_options = [Option('force',
- help='Switch even if local commits will be lost.')
+ help='Switch even if local commits will be lost.'),
+ Option('create-branch', short_name='b',
+ help='Create the target branch from this one before'
+ ' switching to it.'),
]
- def run(self, to_location, force=False):
+ def run(self, to_location, force=False, create_branch=False):
from bzrlib import switch
tree_location = '.'
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
@@ -5335,13 +5338,33 @@
branch = control_dir.open_branch()
had_explicit_nick = branch.get_config().has_explicit_nickname()
except errors.NotBranchError:
+ branch = None
had_explicit_nick = False
- try:
- to_branch = Branch.open(to_location)
- except errors.NotBranchError:
- this_url = self._get_branch_location(control_dir)
- to_branch = Branch.open(
- urlutils.join(this_url, '..', to_location))
+ if create_branch:
+ if branch is None:
+ raise errors.BzrCommandError('cannot create branch without'
+ ' source branch')
+ if '/' not in to_location and '\\' not in to_location:
+ # This path is meant to be relative to the existing branch
+ this_url = self._get_branch_location(control_dir)
+ to_location = urlutils.join(this_url, '..', to_location)
+ to_branch = branch.bzrdir.sprout(to_location,
+ possible_transports=[branch.bzrdir.root_transport],
+ source_branch=branch).open_branch()
+ # try:
+ # from_branch = control_dir.open_branch()
+ # except errors.NotBranchError:
+ # raise BzrCommandError('Cannot create a branch from this'
+ # ' location when we cannot open this branch')
+ # from_branch.bzrdir.sprout(
+ pass
+ else:
+ try:
+ to_branch = Branch.open(to_location)
+ except errors.NotBranchError:
+ this_url = self._get_branch_location(control_dir)
+ to_branch = Branch.open(
+ urlutils.join(this_url, '..', to_location))
switch.switch(control_dir, to_branch, force)
if had_explicit_nick:
branch = control_dir.open_branch() #get the new branch!
=== modified file 'bzrlib/tests/blackbox/test_switch.py'
--- a/bzrlib/tests/blackbox/test_switch.py 2009-06-10 03:56:49 +0000
+++ b/bzrlib/tests/blackbox/test_switch.py 2009-07-09 15:18:57 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2007 Canonical Ltd
+# Copyright (C) 2007, 2008, 2009 Canonical Ltd
# -*- coding: utf-8 -*-
#
# This program is free software; you can redistribute it and/or modify
@@ -150,3 +150,36 @@
self.run_bzr('switch --force branch1', working_dir='tree')
branch_location = WorkingTree.open('tree').branch.base
self.assertEndsWith(branch_location, 'branch1/')
+
+ def test_create_branch_no_branch(self):
+ self.prepare_lightweight_switch()
+ self.run_bzr_error(['cannot create branch without source branch'],
+ 'switch --create-branch ../branch2', working_dir='tree')
+
+ def test_create_branch(self):
+ branch = self.make_branch('branch')
+ tree = branch.create_checkout('tree', lightweight=True)
+ tree.commit('one', rev_id='rev-1')
+ self.run_bzr('switch --create-branch ../branch2', working_dir='tree')
+ tree = WorkingTree.open('tree')
+ self.assertEndsWith(tree.branch.base, '/branch2/')
+
+ def test_create_branch_local(self):
+ branch = self.make_branch('branch')
+ tree = branch.create_checkout('tree', lightweight=True)
+ tree.commit('one', rev_id='rev-1')
+ self.run_bzr('switch --create-branch branch2', working_dir='tree')
+ tree = WorkingTree.open('tree')
+ # The new branch should have been created at the same level as
+ # 'branch', because we did not have a '/' segment
+ self.assertEqual(branch.base[:-1] + '2/', tree.branch.base)
+
+ def test_create_branch_short_name(self):
+ branch = self.make_branch('branch')
+ tree = branch.create_checkout('tree', lightweight=True)
+ tree.commit('one', rev_id='rev-1')
+ self.run_bzr('switch -b branch2', working_dir='tree')
+ tree = WorkingTree.open('tree')
+ # The new branch should have been created at the same level as
+ # 'branch', because we did not have a '/' segment
+ self.assertEqual(branch.base[:-1] + '2/', tree.branch.base)
More information about the bazaar-commits
mailing list