Merge lp:~jameinel/bzr/1.18-switch-branch into lp:~bzr/bzr/trunk-old
- 1.18-switch-branch
- Merge into trunk-old
Status: | Merged |
---|---|
Approved by: | Ian Clatworthy |
Approved revision: | no longer in the source branch. |
Merged at revision: | not available |
Proposed branch: | lp:~jameinel/bzr/1.18-switch-branch |
Merge into: | lp:~bzr/bzr/trunk-old |
Diff against target: | 122 lines |
To merge this branch: | bzr merge lp:~jameinel/bzr/1.18-switch-branch |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ian Clatworthy | Approve | ||
Review via email: mp+8469@code.launchpad.net |
Commit message
Description of the change
John A Meinel (jameinel) wrote : | # |
Robert Collins (lifeless) wrote : | # |
On Thu, 2009-07-09 at 15:25 +0000, John A Meinel wrote:
> John A Meinel has proposed merging lp:~jameinel/bzr/1.18-switch-branch into lp:bzr.
>
> Requested reviews:
> bzr-core (bzr-core)
>
> from the commit comment:
> 'bzr switch -b' can now be used to create the branch while you switch to it.
>
> This is just a convenience thing, but it shortens:
> bzr branch . ../new-branch
> bzr switch ../new-branch
> into a single:
> bzr switch -b ../new-branch
We have a search path for branches. I'd like to suggest we use that here
so that you can do
bzr switch -b new-branch
and have that turn up in wt.branch.base + ../ + $arg if arg is neither
absolute, or relative to cwd (doesn't start with ..).
Robert Collins (lifeless) wrote : | # |
I should add, my suggestion will make this _much_ better for folk with
lightweight checkouts away from the branch. Rather
than ../../.
-Rob
John A Meinel (jameinel) wrote : | # |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Robert Collins wrote:
> I should add, my suggestion will make this _much_ better for folk with
> lightweight checkouts away from the branch. Rather
> than ../../.
>
> -Rob
>
I'm not sure if you noticed that I already check: "if '/' in to_location".
I'm not sure what more than that you need. (I even added tests for this
case....)
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://
iEYEARECAAYFAkp
5xIAnjReCxMvAkI
=ugdy
-----END PGP SIGNATURE-----
Robert Collins (lifeless) wrote : | # |
On Fri, 2009-07-10 at 13:45 +0000, John A Meinel wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Robert Collins wrote:
> > I should add, my suggestion will make this _much_ better for folk with
> > lightweight checkouts away from the branch. Rather
> > than ../../.
> >
> > -Rob
> >
>
> I'm not sure if you noticed that I already check: "if '/' in to_location".
>
> I'm not sure what more than that you need. (I even added tests for this
> case....)
Oh oops :P. However I think thats more prohibitive than needed - in
particular I use subdirs not a flat branch space. What do you thank of
the slightly more sophisticated heuristic I proposed?
-Rob
John A Meinel (jameinel) wrote : | # |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Robert Collins wrote:
> On Fri, 2009-07-10 at 13:45 +0000, John A Meinel wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Robert Collins wrote:
>>> I should add, my suggestion will make this _much_ better for folk with
>>> lightweight checkouts away from the branch. Rather
>>> than ../../.
>>>
>>> -Rob
>>>
>> I'm not sure if you noticed that I already check: "if '/' in to_location".
>>
>> I'm not sure what more than that you need. (I even added tests for this
>> case....)
>
> Oh oops :P. However I think thats more prohibitive than needed - in
> particular I use subdirs not a flat branch space. What do you thank of
> the slightly more sophisticated heuristic I proposed?
>
> -Rob
>
You're welcome to write it?
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://
iEYEARECAAYFAkp
i7AAnAhmzjS1FGO
=ZyoD
-----END PGP SIGNATURE-----
John A Meinel (jameinel) wrote : | # |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
John A Meinel wrote:
...
>>>>
>>> I'm not sure if you noticed that I already check: "if '/' in to_location".
>>>
>>> I'm not sure what more than that you need. (I even added tests for this
>>> case....)
>> Oh oops :P. However I think thats more prohibitive than needed - in
>> particular I use subdirs not a flat branch space. What do you thank of
>> the slightly more sophisticated heuristic I proposed?
>
>> -Rob
>
>
> You're welcome to write it?
>
> John
> =:->
>
More seriously, I think it would be reasonable to do so, but if you
really do use nested values, then when you want to do "../another/dir"
it will look like you are doing something relative to the current dir.
I've proposed in the past that if you did:
bzr switch bar/baz
That it would treat it as
bzr switch $ORIG/../../bar/baz
However, we don't do that *today* so what I wrote is consistent with
what we have.
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://
iEYEARECAAYFAkp
wLYAoJ/
=JxmI
-----END PGP SIGNATURE-----
Ian Clatworthy (ian-clatworthy) wrote : | # |
There's a comment and a pass command in builtins.py that can be deleted. Otherwise, this looks good to land.
FWIW, I like the idea of the branch name implicitly being relative to the right origin (unless the name is absolute or starts with '.') but that can come later.
Preview Diff
1 | === modified file 'NEWS' | |||
2 | --- NEWS 2009-07-09 01:44:00 +0000 | |||
3 | +++ NEWS 2009-07-09 15:35:15 +0000 | |||
4 | @@ -36,6 +36,11 @@ | |||
5 | 36 | behavior. | 36 | behavior. |
6 | 37 | (Vincent Ladeuil, #206577) | 37 | (Vincent Ladeuil, #206577) |
7 | 38 | 38 | ||
8 | 39 | * ``bzr switch --create-branch/-b`` can now be used to create and switch | ||
9 | 40 | to a new branch. Supplying a name without a ``/`` will create the branch | ||
10 | 41 | relative to the existing branch. (similar to how ``bzr switch name`` | ||
11 | 42 | works when the branch already exists.) (John Arbash Meinel) | ||
12 | 43 | |||
13 | 39 | 44 | ||
14 | 40 | Bug Fixes | 45 | Bug Fixes |
15 | 41 | ********* | 46 | ********* |
16 | 42 | 47 | ||
17 | === modified file 'bzrlib/builtins.py' | |||
18 | --- bzrlib/builtins.py 2009-07-02 21:17:35 +0000 | |||
19 | +++ bzrlib/builtins.py 2009-07-09 15:35:16 +0000 | |||
20 | @@ -5299,10 +5299,13 @@ | |||
21 | 5299 | 5299 | ||
22 | 5300 | takes_args = ['to_location'] | 5300 | takes_args = ['to_location'] |
23 | 5301 | takes_options = [Option('force', | 5301 | takes_options = [Option('force', |
25 | 5302 | help='Switch even if local commits will be lost.') | 5302 | help='Switch even if local commits will be lost.'), |
26 | 5303 | Option('create-branch', short_name='b', | ||
27 | 5304 | help='Create the target branch from this one before' | ||
28 | 5305 | ' switching to it.'), | ||
29 | 5303 | ] | 5306 | ] |
30 | 5304 | 5307 | ||
32 | 5305 | def run(self, to_location, force=False): | 5308 | def run(self, to_location, force=False, create_branch=False): |
33 | 5306 | from bzrlib import switch | 5309 | from bzrlib import switch |
34 | 5307 | tree_location = '.' | 5310 | tree_location = '.' |
35 | 5308 | control_dir = bzrdir.BzrDir.open_containing(tree_location)[0] | 5311 | control_dir = bzrdir.BzrDir.open_containing(tree_location)[0] |
36 | @@ -5310,13 +5313,33 @@ | |||
37 | 5310 | branch = control_dir.open_branch() | 5313 | branch = control_dir.open_branch() |
38 | 5311 | had_explicit_nick = branch.get_config().has_explicit_nickname() | 5314 | had_explicit_nick = branch.get_config().has_explicit_nickname() |
39 | 5312 | except errors.NotBranchError: | 5315 | except errors.NotBranchError: |
40 | 5316 | branch = None | ||
41 | 5313 | had_explicit_nick = False | 5317 | had_explicit_nick = False |
48 | 5314 | try: | 5318 | if create_branch: |
49 | 5315 | to_branch = Branch.open(to_location) | 5319 | if branch is None: |
50 | 5316 | except errors.NotBranchError: | 5320 | raise errors.BzrCommandError('cannot create branch without' |
51 | 5317 | this_url = self._get_branch_location(control_dir) | 5321 | ' source branch') |
52 | 5318 | to_branch = Branch.open( | 5322 | if '/' not in to_location and '\\' not in to_location: |
53 | 5319 | urlutils.join(this_url, '..', to_location)) | 5323 | # This path is meant to be relative to the existing branch |
54 | 5324 | this_url = self._get_branch_location(control_dir) | ||
55 | 5325 | to_location = urlutils.join(this_url, '..', to_location) | ||
56 | 5326 | to_branch = branch.bzrdir.sprout(to_location, | ||
57 | 5327 | possible_transports=[branch.bzrdir.root_transport], | ||
58 | 5328 | source_branch=branch).open_branch() | ||
59 | 5329 | # try: | ||
60 | 5330 | # from_branch = control_dir.open_branch() | ||
61 | 5331 | # except errors.NotBranchError: | ||
62 | 5332 | # raise BzrCommandError('Cannot create a branch from this' | ||
63 | 5333 | # ' location when we cannot open this branch') | ||
64 | 5334 | # from_branch.bzrdir.sprout( | ||
65 | 5335 | pass | ||
66 | 5336 | else: | ||
67 | 5337 | try: | ||
68 | 5338 | to_branch = Branch.open(to_location) | ||
69 | 5339 | except errors.NotBranchError: | ||
70 | 5340 | this_url = self._get_branch_location(control_dir) | ||
71 | 5341 | to_branch = Branch.open( | ||
72 | 5342 | urlutils.join(this_url, '..', to_location)) | ||
73 | 5320 | switch.switch(control_dir, to_branch, force) | 5343 | switch.switch(control_dir, to_branch, force) |
74 | 5321 | if had_explicit_nick: | 5344 | if had_explicit_nick: |
75 | 5322 | branch = control_dir.open_branch() #get the new branch! | 5345 | branch = control_dir.open_branch() #get the new branch! |
76 | 5323 | 5346 | ||
77 | === modified file 'bzrlib/tests/blackbox/test_switch.py' | |||
78 | --- bzrlib/tests/blackbox/test_switch.py 2009-06-10 03:56:49 +0000 | |||
79 | +++ bzrlib/tests/blackbox/test_switch.py 2009-07-09 15:35:16 +0000 | |||
80 | @@ -1,4 +1,4 @@ | |||
82 | 1 | # Copyright (C) 2007 Canonical Ltd | 1 | # Copyright (C) 2007, 2008, 2009 Canonical Ltd |
83 | 2 | # -*- coding: utf-8 -*- | 2 | # -*- coding: utf-8 -*- |
84 | 3 | # | 3 | # |
85 | 4 | # This program is free software; you can redistribute it and/or modify | 4 | # This program is free software; you can redistribute it and/or modify |
86 | @@ -150,3 +150,36 @@ | |||
87 | 150 | self.run_bzr('switch --force branch1', working_dir='tree') | 150 | self.run_bzr('switch --force branch1', working_dir='tree') |
88 | 151 | branch_location = WorkingTree.open('tree').branch.base | 151 | branch_location = WorkingTree.open('tree').branch.base |
89 | 152 | self.assertEndsWith(branch_location, 'branch1/') | 152 | self.assertEndsWith(branch_location, 'branch1/') |
90 | 153 | |||
91 | 154 | def test_create_branch_no_branch(self): | ||
92 | 155 | self.prepare_lightweight_switch() | ||
93 | 156 | self.run_bzr_error(['cannot create branch without source branch'], | ||
94 | 157 | 'switch --create-branch ../branch2', working_dir='tree') | ||
95 | 158 | |||
96 | 159 | def test_create_branch(self): | ||
97 | 160 | branch = self.make_branch('branch') | ||
98 | 161 | tree = branch.create_checkout('tree', lightweight=True) | ||
99 | 162 | tree.commit('one', rev_id='rev-1') | ||
100 | 163 | self.run_bzr('switch --create-branch ../branch2', working_dir='tree') | ||
101 | 164 | tree = WorkingTree.open('tree') | ||
102 | 165 | self.assertEndsWith(tree.branch.base, '/branch2/') | ||
103 | 166 | |||
104 | 167 | def test_create_branch_local(self): | ||
105 | 168 | branch = self.make_branch('branch') | ||
106 | 169 | tree = branch.create_checkout('tree', lightweight=True) | ||
107 | 170 | tree.commit('one', rev_id='rev-1') | ||
108 | 171 | self.run_bzr('switch --create-branch branch2', working_dir='tree') | ||
109 | 172 | tree = WorkingTree.open('tree') | ||
110 | 173 | # The new branch should have been created at the same level as | ||
111 | 174 | # 'branch', because we did not have a '/' segment | ||
112 | 175 | self.assertEqual(branch.base[:-1] + '2/', tree.branch.base) | ||
113 | 176 | |||
114 | 177 | def test_create_branch_short_name(self): | ||
115 | 178 | branch = self.make_branch('branch') | ||
116 | 179 | tree = branch.create_checkout('tree', lightweight=True) | ||
117 | 180 | tree.commit('one', rev_id='rev-1') | ||
118 | 181 | self.run_bzr('switch -b branch2', working_dir='tree') | ||
119 | 182 | tree = WorkingTree.open('tree') | ||
120 | 183 | # The new branch should have been created at the same level as | ||
121 | 184 | # 'branch', because we did not have a '/' segment | ||
122 | 185 | self.assertEqual(branch.base[:-1] + '2/', tree.branch.base) |
from the commit comment:
'bzr switch -b' can now be used to create the branch while you switch to it.
This is just a convenience thing, but it shortens:
bzr branch . ../new-branch
bzr switch ../new-branch
into a single:
bzr switch -b ../new-branch