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

Proposed by Lukáš Lalinský
Status: Superseded
Proposed branch: lp:~luks/bzr/branch-switch
Merge into: lp:~bzr/bzr/trunk-old
Diff against target: 96 lines (has conflicts)
Text conflict in NEWS
To merge this branch: bzr merge lp:~luks/bzr/branch-switch
Reviewer Review Type Date Requested Status
John A Meinel Needs Fixing
Review via email: mp+9969@code.launchpad.net

This proposal has been superseded by 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 :

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 :

-----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
Robert Collins (lifeless) wrote :

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 :

-----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-----

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-11 02:58:23 +0000
3+++ NEWS 2009-08-11 10:35:10 +0000
4@@ -21,6 +21,7 @@
5 * Further tweaks to handling of ``bzr add`` messages about ignored files.
6 (Jason Spashett, #76616)
7
8+<<<<<<< TREE
9 Improvements
10 ************
11
12@@ -54,6 +55,19 @@
13 with bugfix-only releases based on it continuing for at least six months
14 or until the following stable release.
15
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+In Development
24+##############
25+
26+Compatibility Breaks
27+********************
28+>>>>>>> MERGE-SOURCE
29
30 New Features
31 ************
32
33=== modified file 'bzrlib/builtins.py'
34--- bzrlib/builtins.py 2009-08-10 08:25:53 +0000
35+++ bzrlib/builtins.py 2009-08-11 10:35:10 +0000
36@@ -1167,6 +1167,9 @@
37 help='Hard-link working tree files where possible.'),
38 Option('no-tree',
39 help="Create a branch without a working-tree."),
40+ Option('switch',
41+ help="Switch the checkout in the current directory "
42+ "to the new branch."),
43 Option('stacked',
44 help='Create a stacked branch referring to the source branch. '
45 'The new branch will depend on the availability of the source '
46@@ -1183,9 +1186,12 @@
47
48 def run(self, from_location, to_location=None, revision=None,
49 hardlink=False, stacked=False, standalone=False, no_tree=False,
50- use_existing_dir=False):
51+ use_existing_dir=False, switch=False):
52+ from bzrlib import switch as _mod_switch
53 from bzrlib.tag import _merge_tags_if_possible
54-
55+ if switch:
56+ # Check if we have a WT in the current directory
57+ wt, _ = WorkingTree.open_containing('.')
58 accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
59 from_location)
60 if (accelerator_tree is not None and
61@@ -1245,6 +1251,11 @@
62 except (errors.NotStacked, errors.UnstackableBranchFormat,
63 errors.UnstackableRepositoryFormat), e:
64 note('Branched %d revision(s).' % branch.revno())
65+ if switch:
66+ # Switch to the new branch
67+ _mod_switch.switch(wt.bzrdir, branch)
68+ note('Switched to branch: %s',
69+ urlutils.unescape_for_display(branch.base, 'utf-8'))
70 finally:
71 br_from.unlock()
72
73
74=== modified file 'bzrlib/tests/blackbox/test_branch.py'
75--- bzrlib/tests/blackbox/test_branch.py 2009-08-03 04:19:03 +0000
76+++ bzrlib/tests/blackbox/test_branch.py 2009-08-11 10:35:10 +0000
77@@ -52,6 +52,19 @@
78 self.assertFalse(b._transport.has('branch-name'))
79 b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
80
81+ def test_branch_switch_no_checkout(self):
82+ self.example_branch('a')
83+ self.run_bzr_error(['Cannot switch a branch, only a checkout'],
84+ 'branch --switch a b', working_dir='.')
85+
86+ def test_branch_switch(self):
87+ self.example_branch('a')
88+ self.run_bzr('checkout --lightweight a tree')
89+ out, err = self.run_bzr('branch --switch ../a ../b', working_dir='tree')
90+ tree = WorkingTree.open('tree')
91+ self.assertEndsWith(tree.branch.base, '/b/')
92+ self.assertContainsRe(err, "Switched to branch: .*/b/")
93+
94 def test_branch_only_copies_history(self):
95 # Knit branches should only push the history for the current revision.
96 format = bzrdir.BzrDirMetaFormat1()