Merge lp:~luks/bzr/branch-switch into lp:~bzr/bzr/trunk-old

Proposed by Lukáš Lalinský
Status: Merged
Merged at revision: not available
Proposed branch: lp:~luks/bzr/branch-switch
Merge into: lp:~bzr/bzr/trunk-old
Diff against target: 159 lines (has conflicts)
Text conflict in NEWS
To merge this branch: bzr merge lp:~luks/bzr/branch-switch
Reviewer Review Type Date Requested Status
Alexander Belchenko Approve
John A Meinel Approve
Review via email: mp+9987@code.launchpad.net

This proposal supersedes a proposal from 2009-08-11.

Commit message

Support for `bzr branch --switch`

To post a comment you must log in.
Revision history for this message
Lukáš Lalinský (luks) wrote : Posted in a previous version of this proposal

This patch adds a new option to bzr branch that allows to switch the checkout in the current directory to the new branch. This is based on yesterday's discussion in #bzr -- http://irclogs.ubuntu.com/2009/08/10/%23bzr.html from 19:48. Another option was to add a "source" argument to bzr switch -b (http://paste.pocoo.org/show/133506/), but the only way seems to be to add it to the end of the command line and "bzr <command> <target> <source>" is not used in any other bzr command except for bzr export.

Revision history for this message
John A Meinel (jameinel) wrote : Posted in a previous version of this proposal

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Lukáš Lalinský wrote:
> Lukáš Lalinský has proposed merging lp:~luks/bzr/branch-switch into lp:bzr.
>
> Requested reviews:
> bzr-core (bzr-core)
>
> This patch adds a new option to bzr branch that allows to switch the checkout in the current directory to the new branch. This is based on yesterday's discussion in #bzr -- http://irclogs.ubuntu.com/2009/08/10/%23bzr.html from 19:48. Another option was to add a "source" argument to bzr switch -b (http://paste.pocoo.org/show/133506/), but the only way seems to be to add it to the end of the command line and "bzr <command> <target> <source>" is not used in any other bzr command except for bzr export.
>

I would like to see a test for what happens when you are only in a
branch, and not a working tree at all.

I'd also like to see "test_branch_switch_no_checkout" assert what
happens as a side effect. Does it:
1) Create/not create the branch 'b'?
2) Do anything to the local branch or working tree?

Also, I think we should have a test with a heavyweight checkout, to
assert what it does there.

Note that I'm not particularly strong on what the answers to the
questions should be. I just want the behavior identified, so we don't
accidentally change it in the future.

 review needs_fixing

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkqBnGQACgkQJdeBCYSNAAOicwCfdIjxHxP0i5y68vllU8YyArZS
EEQAn2PL4ykfHtQWUfwxkFUH3zXVGr7K
=Et4B
-----END PGP SIGNATURE-----

review: Needs Fixing
Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Lukáš Lalinský wrote:
> Lukáš Lalinský has proposed merging lp:~luks/bzr/branch-switch into lp:bzr.
>
> Requested reviews:
> bzr-core (bzr-core)
>

 review approve

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkqBtG4ACgkQJdeBCYSNAAOGFwCcCUgzwlsN3jypt4XMwwcVdG7e
Ll8AoJOhoFbtxH6LcEraHFy/dD8hCIG5
=3FMl
-----END PGP SIGNATURE-----

review: Approve
Revision history for this message
Robert Collins (lifeless) wrote : Posted in a previous version of this proposal

I thought we had 'switch -b' for this case? Is there really a need to
have both switch --branch and branch --switch?

Revision history for this message
John A Meinel (jameinel) wrote : Posted in a previous version of this proposal

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Robert Collins wrote:
> I thought we had 'switch -b' for this case? Is there really a need to
> have both switch --branch and branch --switch?
>
>
>

branch --switch allows for a custom source that isn't "."

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkqB5WoACgkQJdeBCYSNAAMYjgCfVedumO+/Xo/jgl0kYg0bkPyn
t9IAn1tIjmrIboawgHcw5E17jKAg4NAy
=KqUk
-----END PGP SIGNATURE-----

Revision history for this message
Alexander Belchenko (bialix) wrote :

I like the idea and implementation.

John, can you merge this, please?

review: Approve
Revision history for this message
Vincent Ladeuil (vila) wrote :

Sent to pqm

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2009-08-20 05:32:57 +0000
+++ NEWS 2009-08-20 08:35:58 +0000
@@ -12,6 +12,7 @@
12Compatibility Breaks12Compatibility Breaks
13********************13********************
1414
15<<<<<<< TREE
15* The default format for bzr is now ``2a``. This format brings many16* The default format for bzr is now ``2a``. This format brings many
16 significant performance and size improvements. bzr can pull from17 significant performance and size improvements. bzr can pull from
17 any existing repository into a ``2a`` one, but can only transfer18 any existing repository into a ``2a`` one, but can only transfer
@@ -83,6 +84,16 @@
8384
84* Fixed "Pack ... already exists" error when running ``bzr pack`` on a85* Fixed "Pack ... already exists" error when running ``bzr pack`` on a
85 fully packed 2a repository. (Andrew Bennetts, #382463)86 fully packed 2a repository. (Andrew Bennetts, #382463)
87=======
88New Features
89************
90
91* ``bzr branch --switch`` can now switch the checkout in the current directory
92 to the newly created branch. (Lukáš Lalinský)
93
94Bug Fixes
95*********
96>>>>>>> MERGE-SOURCE
8697
87* Further tweaks to handling of ``bzr add`` messages about ignored files.98* Further tweaks to handling of ``bzr add`` messages about ignored files.
88 (Jason Spashett, #76616)99 (Jason Spashett, #76616)
89100
=== modified file 'bzrlib/builtins.py'
--- bzrlib/builtins.py 2009-08-10 08:25:53 +0000
+++ bzrlib/builtins.py 2009-08-20 08:35:58 +0000
@@ -1167,6 +1167,9 @@
1167 help='Hard-link working tree files where possible.'),1167 help='Hard-link working tree files where possible.'),
1168 Option('no-tree',1168 Option('no-tree',
1169 help="Create a branch without a working-tree."),1169 help="Create a branch without a working-tree."),
1170 Option('switch',
1171 help="Switch the checkout in the current directory "
1172 "to the new branch."),
1170 Option('stacked',1173 Option('stacked',
1171 help='Create a stacked branch referring to the source branch. '1174 help='Create a stacked branch referring to the source branch. '
1172 'The new branch will depend on the availability of the source '1175 'The new branch will depend on the availability of the source '
@@ -1183,9 +1186,9 @@
11831186
1184 def run(self, from_location, to_location=None, revision=None,1187 def run(self, from_location, to_location=None, revision=None,
1185 hardlink=False, stacked=False, standalone=False, no_tree=False,1188 hardlink=False, stacked=False, standalone=False, no_tree=False,
1186 use_existing_dir=False):1189 use_existing_dir=False, switch=False):
1190 from bzrlib import switch as _mod_switch
1187 from bzrlib.tag import _merge_tags_if_possible1191 from bzrlib.tag import _merge_tags_if_possible
1188
1189 accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(1192 accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1190 from_location)1193 from_location)
1191 if (accelerator_tree is not None and1194 if (accelerator_tree is not None and
@@ -1245,6 +1248,12 @@
1245 except (errors.NotStacked, errors.UnstackableBranchFormat,1248 except (errors.NotStacked, errors.UnstackableBranchFormat,
1246 errors.UnstackableRepositoryFormat), e:1249 errors.UnstackableRepositoryFormat), e:
1247 note('Branched %d revision(s).' % branch.revno())1250 note('Branched %d revision(s).' % branch.revno())
1251 if switch:
1252 # Switch to the new branch
1253 wt, _ = WorkingTree.open_containing('.')
1254 _mod_switch.switch(wt.bzrdir, branch)
1255 note('Switched to branch: %s',
1256 urlutils.unescape_for_display(branch.base, 'utf-8'))
1248 finally:1257 finally:
1249 br_from.unlock()1258 br_from.unlock()
12501259
12511260
=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- bzrlib/tests/blackbox/test_branch.py 2009-08-11 05:26:57 +0000
+++ bzrlib/tests/blackbox/test_branch.py 2009-08-20 08:35:58 +0000
@@ -19,7 +19,13 @@
1919
20import os20import os
2121
22from bzrlib import (branch, bzrdir, errors, repository)22from bzrlib import (
23 branch,
24 bzrdir,
25 errors,
26 repository,
27 revision as _mod_revision,
28 )
23from bzrlib.repofmt.knitrepo import RepositoryFormatKnit129from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
24from bzrlib.tests.blackbox import ExternalBase30from bzrlib.tests.blackbox import ExternalBase
25from bzrlib.tests import (31from bzrlib.tests import (
@@ -52,6 +58,72 @@
52 self.assertFalse(b._transport.has('branch-name'))58 self.assertFalse(b._transport.has('branch-name'))
53 b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)59 b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
5460
61 def test_branch_switch_no_branch(self):
62 # No branch in the current directory:
63 # => new branch will be created, but switch fails
64 self.example_branch('a')
65 self.make_repository('current')
66 self.run_bzr_error(['No WorkingTree exists for'],
67 'branch --switch ../a ../b', working_dir='current')
68 a = branch.Branch.open('a')
69 b = branch.Branch.open('b')
70 self.assertEqual(a.last_revision(), b.last_revision())
71
72 def test_branch_switch_no_wt(self):
73 # No working tree in the current directory:
74 # => new branch will be created, but switch fails and the current
75 # branch is unmodified
76 self.example_branch('a')
77 self.make_branch('current')
78 self.run_bzr_error(['No WorkingTree exists for'],
79 'branch --switch ../a ../b', working_dir='current')
80 a = branch.Branch.open('a')
81 b = branch.Branch.open('b')
82 self.assertEqual(a.last_revision(), b.last_revision())
83 work = branch.Branch.open('current')
84 self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
85
86 def test_branch_switch_no_checkout(self):
87 # Standalone branch in the current directory:
88 # => new branch will be created, but switch fails and the current
89 # branch is unmodified
90 self.example_branch('a')
91 self.make_branch_and_tree('current')
92 self.run_bzr_error(['Cannot switch a branch, only a checkout'],
93 'branch --switch ../a ../b', working_dir='current')
94 a = branch.Branch.open('a')
95 b = branch.Branch.open('b')
96 self.assertEqual(a.last_revision(), b.last_revision())
97 work = branch.Branch.open('current')
98 self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
99
100 def test_branch_switch_checkout(self):
101 # Checkout in the current directory:
102 # => new branch will be created and checkout bound to the new branch
103 self.example_branch('a')
104 self.run_bzr('checkout a current')
105 out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
106 a = branch.Branch.open('a')
107 b = branch.Branch.open('b')
108 self.assertEqual(a.last_revision(), b.last_revision())
109 work = WorkingTree.open('current')
110 self.assertEndsWith(work.branch.get_bound_location(), '/b/')
111 self.assertContainsRe(err, "Switched to branch: .*/b/")
112
113 def test_branch_switch_lightweight_checkout(self):
114 # Lightweight checkout in the current directory:
115 # => new branch will be created and lightweight checkout pointed to
116 # the new branch
117 self.example_branch('a')
118 self.run_bzr('checkout --lightweight a current')
119 out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
120 a = branch.Branch.open('a')
121 b = branch.Branch.open('b')
122 self.assertEqual(a.last_revision(), b.last_revision())
123 work = WorkingTree.open('current')
124 self.assertEndsWith(work.branch.base, '/b/')
125 self.assertContainsRe(err, "Switched to branch: .*/b/")
126
55 def test_branch_only_copies_history(self):127 def test_branch_only_copies_history(self):
56 # Knit branches should only push the history for the current revision.128 # Knit branches should only push the history for the current revision.
57 format = bzrdir.BzrDirMetaFormat1()129 format = bzrdir.BzrDirMetaFormat1()