Rev 4634: (luks) Support for `bzr branch --switch` in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Thu Aug 20 14:57:30 BST 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4634 [merge]
revision-id: pqm at pqm.ubuntu.com-20090820135727-pz56lf0l0tj6rbrn
parent: pqm at pqm.ubuntu.com-20090820112629-yggugenrypihucji
parent: v.ladeuil+lp at free.fr-20090820123049-81r01t98gu2dlug5
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2009-08-20 14:57:27 +0100
message:
(luks) Support for `bzr branch --switch`
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/tests/blackbox/test_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
=== modified file 'NEWS'
--- a/NEWS 2009-08-20 05:32:57 +0000
+++ b/NEWS 2009-08-20 12:30:49 +0000
@@ -21,6 +21,9 @@
New Features
************
+* ``bzr branch --switch`` can now switch the checkout in the current directory
+ to the newly created branch. (Lukáš Lalinský)
+
Bug Fixes
*********
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2009-08-10 08:25:53 +0000
+++ b/bzrlib/builtins.py 2009-08-11 18:00:37 +0000
@@ -1167,6 +1167,9 @@
help='Hard-link working tree files where possible.'),
Option('no-tree',
help="Create a branch without a working-tree."),
+ Option('switch',
+ help="Switch the checkout in the current directory "
+ "to the new branch."),
Option('stacked',
help='Create a stacked branch referring to the source branch. '
'The new branch will depend on the availability of the source '
@@ -1183,9 +1186,9 @@
def run(self, from_location, to_location=None, revision=None,
hardlink=False, stacked=False, standalone=False, no_tree=False,
- use_existing_dir=False):
+ use_existing_dir=False, switch=False):
+ from bzrlib import switch as _mod_switch
from bzrlib.tag import _merge_tags_if_possible
-
accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
from_location)
if (accelerator_tree is not None and
@@ -1245,6 +1248,12 @@
except (errors.NotStacked, errors.UnstackableBranchFormat,
errors.UnstackableRepositoryFormat), e:
note('Branched %d revision(s).' % branch.revno())
+ if switch:
+ # Switch to the new branch
+ wt, _ = WorkingTree.open_containing('.')
+ _mod_switch.switch(wt.bzrdir, branch)
+ note('Switched to branch: %s',
+ urlutils.unescape_for_display(branch.base, 'utf-8'))
finally:
br_from.unlock()
=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- a/bzrlib/tests/blackbox/test_branch.py 2009-08-11 05:26:57 +0000
+++ b/bzrlib/tests/blackbox/test_branch.py 2009-08-20 12:30:49 +0000
@@ -19,7 +19,13 @@
import os
-from bzrlib import (branch, bzrdir, errors, repository)
+from bzrlib import (
+ branch,
+ bzrdir,
+ errors,
+ repository,
+ revision as _mod_revision,
+ )
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
from bzrlib.tests.blackbox import ExternalBase
from bzrlib.tests import (
@@ -52,6 +58,72 @@
self.assertFalse(b._transport.has('branch-name'))
b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
+ def test_branch_switch_no_branch(self):
+ # No branch in the current directory:
+ # => new branch will be created, but switch fails
+ self.example_branch('a')
+ self.make_repository('current')
+ self.run_bzr_error(['No WorkingTree exists for'],
+ 'branch --switch ../a ../b', working_dir='current')
+ a = branch.Branch.open('a')
+ b = branch.Branch.open('b')
+ self.assertEqual(a.last_revision(), b.last_revision())
+
+ def test_branch_switch_no_wt(self):
+ # No working tree in the current directory:
+ # => new branch will be created, but switch fails and the current
+ # branch is unmodified
+ self.example_branch('a')
+ self.make_branch('current')
+ self.run_bzr_error(['No WorkingTree exists for'],
+ 'branch --switch ../a ../b', working_dir='current')
+ a = branch.Branch.open('a')
+ b = branch.Branch.open('b')
+ self.assertEqual(a.last_revision(), b.last_revision())
+ work = branch.Branch.open('current')
+ self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
+
+ def test_branch_switch_no_checkout(self):
+ # Standalone branch in the current directory:
+ # => new branch will be created, but switch fails and the current
+ # branch is unmodified
+ self.example_branch('a')
+ self.make_branch_and_tree('current')
+ self.run_bzr_error(['Cannot switch a branch, only a checkout'],
+ 'branch --switch ../a ../b', working_dir='current')
+ a = branch.Branch.open('a')
+ b = branch.Branch.open('b')
+ self.assertEqual(a.last_revision(), b.last_revision())
+ work = branch.Branch.open('current')
+ self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
+
+ def test_branch_switch_checkout(self):
+ # Checkout in the current directory:
+ # => new branch will be created and checkout bound to the new branch
+ self.example_branch('a')
+ self.run_bzr('checkout a current')
+ out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
+ a = branch.Branch.open('a')
+ b = branch.Branch.open('b')
+ self.assertEqual(a.last_revision(), b.last_revision())
+ work = WorkingTree.open('current')
+ self.assertEndsWith(work.branch.get_bound_location(), '/b/')
+ self.assertContainsRe(err, "Switched to branch: .*/b/")
+
+ def test_branch_switch_lightweight_checkout(self):
+ # Lightweight checkout in the current directory:
+ # => new branch will be created and lightweight checkout pointed to
+ # the new branch
+ self.example_branch('a')
+ self.run_bzr('checkout --lightweight a current')
+ out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
+ a = branch.Branch.open('a')
+ b = branch.Branch.open('b')
+ self.assertEqual(a.last_revision(), b.last_revision())
+ work = WorkingTree.open('current')
+ self.assertEndsWith(work.branch.base, '/b/')
+ self.assertContainsRe(err, "Switched to branch: .*/b/")
+
def test_branch_only_copies_history(self):
# Knit branches should only push the history for the current revision.
format = bzrdir.BzrDirMetaFormat1()
More information about the bazaar-commits
mailing list