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
1=== modified file 'NEWS'
2--- NEWS 2009-08-20 05:32:57 +0000
3+++ NEWS 2009-08-20 08:35:58 +0000
4@@ -12,6 +12,7 @@
5 Compatibility Breaks
6 ********************
7
8+<<<<<<< TREE
9 * The default format for bzr is now ``2a``. This format brings many
10 significant performance and size improvements. bzr can pull from
11 any existing repository into a ``2a`` one, but can only transfer
12@@ -83,6 +84,16 @@
13
14 * Fixed "Pack ... already exists" error when running ``bzr pack`` on a
15 fully packed 2a repository. (Andrew Bennetts, #382463)
16+=======
17+New Features
18+************
19+
20+* ``bzr branch --switch`` can now switch the checkout in the current directory
21+ to the newly created branch. (Lukáš Lalinský)
22+
23+Bug Fixes
24+*********
25+>>>>>>> MERGE-SOURCE
26
27 * Further tweaks to handling of ``bzr add`` messages about ignored files.
28 (Jason Spashett, #76616)
29
30=== modified file 'bzrlib/builtins.py'
31--- bzrlib/builtins.py 2009-08-10 08:25:53 +0000
32+++ bzrlib/builtins.py 2009-08-20 08:35:58 +0000
33@@ -1167,6 +1167,9 @@
34 help='Hard-link working tree files where possible.'),
35 Option('no-tree',
36 help="Create a branch without a working-tree."),
37+ Option('switch',
38+ help="Switch the checkout in the current directory "
39+ "to the new branch."),
40 Option('stacked',
41 help='Create a stacked branch referring to the source branch. '
42 'The new branch will depend on the availability of the source '
43@@ -1183,9 +1186,9 @@
44
45 def run(self, from_location, to_location=None, revision=None,
46 hardlink=False, stacked=False, standalone=False, no_tree=False,
47- use_existing_dir=False):
48+ use_existing_dir=False, switch=False):
49+ from bzrlib import switch as _mod_switch
50 from bzrlib.tag import _merge_tags_if_possible
51-
52 accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
53 from_location)
54 if (accelerator_tree is not None and
55@@ -1245,6 +1248,12 @@
56 except (errors.NotStacked, errors.UnstackableBranchFormat,
57 errors.UnstackableRepositoryFormat), e:
58 note('Branched %d revision(s).' % branch.revno())
59+ if switch:
60+ # Switch to the new branch
61+ wt, _ = WorkingTree.open_containing('.')
62+ _mod_switch.switch(wt.bzrdir, branch)
63+ note('Switched to branch: %s',
64+ urlutils.unescape_for_display(branch.base, 'utf-8'))
65 finally:
66 br_from.unlock()
67
68
69=== modified file 'bzrlib/tests/blackbox/test_branch.py'
70--- bzrlib/tests/blackbox/test_branch.py 2009-08-11 05:26:57 +0000
71+++ bzrlib/tests/blackbox/test_branch.py 2009-08-20 08:35:58 +0000
72@@ -19,7 +19,13 @@
73
74 import os
75
76-from bzrlib import (branch, bzrdir, errors, repository)
77+from bzrlib import (
78+ branch,
79+ bzrdir,
80+ errors,
81+ repository,
82+ revision as _mod_revision,
83+ )
84 from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
85 from bzrlib.tests.blackbox import ExternalBase
86 from bzrlib.tests import (
87@@ -52,6 +58,72 @@
88 self.assertFalse(b._transport.has('branch-name'))
89 b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
90
91+ def test_branch_switch_no_branch(self):
92+ # No branch in the current directory:
93+ # => new branch will be created, but switch fails
94+ self.example_branch('a')
95+ self.make_repository('current')
96+ self.run_bzr_error(['No WorkingTree exists for'],
97+ 'branch --switch ../a ../b', working_dir='current')
98+ a = branch.Branch.open('a')
99+ b = branch.Branch.open('b')
100+ self.assertEqual(a.last_revision(), b.last_revision())
101+
102+ def test_branch_switch_no_wt(self):
103+ # No working tree in the current directory:
104+ # => new branch will be created, but switch fails and the current
105+ # branch is unmodified
106+ self.example_branch('a')
107+ self.make_branch('current')
108+ self.run_bzr_error(['No WorkingTree exists for'],
109+ 'branch --switch ../a ../b', working_dir='current')
110+ a = branch.Branch.open('a')
111+ b = branch.Branch.open('b')
112+ self.assertEqual(a.last_revision(), b.last_revision())
113+ work = branch.Branch.open('current')
114+ self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
115+
116+ def test_branch_switch_no_checkout(self):
117+ # Standalone branch in the current directory:
118+ # => new branch will be created, but switch fails and the current
119+ # branch is unmodified
120+ self.example_branch('a')
121+ self.make_branch_and_tree('current')
122+ self.run_bzr_error(['Cannot switch a branch, only a checkout'],
123+ 'branch --switch ../a ../b', working_dir='current')
124+ a = branch.Branch.open('a')
125+ b = branch.Branch.open('b')
126+ self.assertEqual(a.last_revision(), b.last_revision())
127+ work = branch.Branch.open('current')
128+ self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
129+
130+ def test_branch_switch_checkout(self):
131+ # Checkout in the current directory:
132+ # => new branch will be created and checkout bound to the new branch
133+ self.example_branch('a')
134+ self.run_bzr('checkout a current')
135+ out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
136+ a = branch.Branch.open('a')
137+ b = branch.Branch.open('b')
138+ self.assertEqual(a.last_revision(), b.last_revision())
139+ work = WorkingTree.open('current')
140+ self.assertEndsWith(work.branch.get_bound_location(), '/b/')
141+ self.assertContainsRe(err, "Switched to branch: .*/b/")
142+
143+ def test_branch_switch_lightweight_checkout(self):
144+ # Lightweight checkout in the current directory:
145+ # => new branch will be created and lightweight checkout pointed to
146+ # the new branch
147+ self.example_branch('a')
148+ self.run_bzr('checkout --lightweight a current')
149+ out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
150+ a = branch.Branch.open('a')
151+ b = branch.Branch.open('b')
152+ self.assertEqual(a.last_revision(), b.last_revision())
153+ work = WorkingTree.open('current')
154+ self.assertEndsWith(work.branch.base, '/b/')
155+ self.assertContainsRe(err, "Switched to branch: .*/b/")
156+
157 def test_branch_only_copies_history(self):
158 # Knit branches should only push the history for the current revision.
159 format = bzrdir.BzrDirMetaFormat1()