Rev 3247: * ``bzr switch`` will attempt to find branches to switch to relative to the in http://people.ubuntu.com/~robertc/baz2.0/switch-relative
Robert Collins
robertc at robertcollins.net
Mon Mar 3 11:36:32 GMT 2008
At http://people.ubuntu.com/~robertc/baz2.0/switch-relative
------------------------------------------------------------
revno: 3247
revision-id:robertc at robertcollins.net-20080303113547-h2gg8asygpg60uun
parent: pqm at pqm.ubuntu.com-20080229011300-p50it0si2y8mbv0d
committer: Robert Collins <robertc at robertcollins.net>
branch nick: switch-relative
timestamp: Mon 2008-03-03 22:35:47 +1100
message:
* ``bzr switch`` will attempt to find branches to switch to relative to the
current branch. E.g. ``bzr switch branchname`` will look for
``current_branch/../branchname``. (Robert Collins, Jelmer Vernooij,
Wouter van Heyst)
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 2008-02-28 21:27:44 +0000
+++ b/NEWS 2008-03-03 11:35:47 +0000
@@ -33,11 +33,16 @@
FEATURES:
- * ``branch`` and ``checkout`` can hard-link working tree files, which is
- faster and saves space. (Aaron Bentley)
+ * ``branch`` and ``checkout`` can hard-link working tree files, which is
+ faster and saves space. (Aaron Bentley)
IMPROVEMENTS:
+ * ``bzr switch`` will attempt to find branches to switch to relative to the
+ current branch. E.g. ``bzr switch branchname`` will look for
+ ``current_branch/../branchname``. (Robert Collins, Jelmer Vernooij,
+ Wouter van Heyst)
+
BUGFIXES:
* Disable plink's interactive prompt for password.
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2008-02-25 07:28:29 +0000
+++ b/bzrlib/builtins.py 2008-03-03 11:35:47 +0000
@@ -4411,6 +4411,11 @@
are merged. The user can commit or revert these as they desire.
Pending merges need to be committed or reverted before using switch.
+
+ The path to the branch to switch to can be specified relative to the parent
+ directory of the current branch. For example, if you are currently in a
+ checkout of /path/to/branch, specifying 'newbranch' will find a branch at
+ /path/to/newbranch.
"""
takes_args = ['to_location']
@@ -4420,9 +4425,13 @@
def run(self, to_location, force=False):
from bzrlib import switch
- to_branch = Branch.open(to_location)
tree_location = '.'
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
+ try:
+ to_branch = Branch.open(to_location)
+ except errors.NotBranchError:
+ to_branch = Branch.open(
+ control_dir.open_branch().base + '../' + to_location)
switch.switch(control_dir, to_branch, force)
note('Switched to branch: %s',
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
=== modified file 'bzrlib/tests/blackbox/test_switch.py'
--- a/bzrlib/tests/blackbox/test_switch.py 2007-11-22 11:21:00 +0000
+++ b/bzrlib/tests/blackbox/test_switch.py 2008-03-03 11:35:47 +0000
@@ -48,3 +48,18 @@
self.assertContainsRe(err, 'Updated to revision 1.\n')
self.assertContainsRe(err, 'Switched to branch: .*/branch2.\n')
self.assertEqual('', out)
+
+ def test_switch_finds_relative_branch(self):
+ """Switch will find 'foo' relative to the branch that the checkout is of."""
+ self.build_tree(['repo/'])
+ tree1 = self.make_branch_and_tree('repo/brancha')
+ tree1.commit('foo')
+ tree2 = self.make_branch_and_tree('repo/branchb')
+ tree2.pull(tree1.branch)
+ branchb_id = tree2.commit('bar')
+ checkout = tree1.branch.create_checkout('checkout', lightweight=True)
+ self.run_bzr(['switch', 'branchb'], working_dir='checkout')
+ self.assertEqual(branchb_id, checkout.last_revision())
+ checkout = checkout.bzrdir.open_workingtree()
+ self.assertEqual(tree2.branch.base, checkout.branch.base)
+
More information about the bazaar-commits
mailing list