~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_switch.py

  • Committer: Patch Queue Manager
  • Date: 2011-11-17 19:50:38 UTC
  • mfrom: (5268.8.23 switch-colocated)
  • Revision ID: pqm@pqm.ubuntu.com-20111117195038-1e3ypqmovs2bjhtp
(jelmer) Support switching to colocated branches in "bzr switch". (Jelmer
 Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
import os
22
22
 
 
23
from bzrlib.bzrdir import BzrDir
23
24
from bzrlib import (
24
25
        osutils,
25
26
        urlutils,
30
31
        TestCaseWithTransport,
31
32
        script,
32
33
        )
 
34
from bzrlib.tests.features import UnicodeFilenameFeature
33
35
from bzrlib.directory_service import directories
34
36
 
35
37
 
152
154
        self.assertEqual(branchb_id, checkout.last_revision())
153
155
        self.assertEqual(tree2.branch.base, checkout.branch.get_bound_location())
154
156
 
 
157
    def test_switch_finds_relative_unicode_branch(self):
 
158
        """Switch will find 'foo' relative to the branch the checkout is of."""
 
159
        self.requireFeature(UnicodeFilenameFeature)
 
160
        self.build_tree(['repo/'])
 
161
        tree1 = self.make_branch_and_tree('repo/brancha')
 
162
        tree1.commit('foo')
 
163
        tree2 = self.make_branch_and_tree(u'repo/branch\xe9')
 
164
        tree2.pull(tree1.branch)
 
165
        branchb_id = tree2.commit('bar')
 
166
        checkout =  tree1.branch.create_checkout('checkout', lightweight=True)
 
167
        self.run_bzr(['switch', u'branch\xe9'], working_dir='checkout')
 
168
        self.assertEqual(branchb_id, checkout.last_revision())
 
169
        checkout = checkout.bzrdir.open_workingtree()
 
170
        self.assertEqual(tree2.branch.base, checkout.branch.base)
 
171
 
155
172
    def test_switch_revision(self):
156
173
        tree = self._create_sample_tree()
157
174
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
159
176
        self.assertPathExists('checkout/file-1')
160
177
        self.assertPathDoesNotExist('checkout/file-2')
161
178
 
 
179
    def test_switch_existing_colocated(self):
 
180
        # Create a branch branch-1 that initially is a checkout of 'foo'
 
181
        # Use switch to change it to 'anotherbranch'
 
182
        repo = self.make_repository('branch-1', format='development-colo')
 
183
        target_branch = repo.bzrdir.create_branch(name='foo')
 
184
        branch.BranchReferenceFormat().initialize(
 
185
            repo.bzrdir, target_branch=target_branch)
 
186
        tree = repo.bzrdir.create_workingtree()
 
187
        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
 
188
        tree.add('file-1')
 
189
        revid1 = tree.commit('rev1')
 
190
        tree.add('file-2')
 
191
        revid2 = tree.commit('rev2')
 
192
        otherbranch = tree.bzrdir.create_branch(name='anotherbranch')
 
193
        otherbranch.generate_revision_history(revid1)
 
194
        self.run_bzr(['switch', 'anotherbranch'], working_dir='branch-1')
 
195
        tree = WorkingTree.open("branch-1")
 
196
        self.assertEquals(tree.last_revision(), revid1)
 
197
        self.assertEquals(tree.branch.control_url, otherbranch.control_url)
 
198
 
 
199
    def test_switch_new_colocated(self):
 
200
        # Create a branch branch-1 that initially is a checkout of 'foo'
 
201
        # Use switch to create 'anotherbranch' which derives from that
 
202
        repo = self.make_repository('branch-1', format='development-colo')
 
203
        target_branch = repo.bzrdir.create_branch(name='foo')
 
204
        branch.BranchReferenceFormat().initialize(
 
205
            repo.bzrdir, target_branch=target_branch)
 
206
        tree = repo.bzrdir.create_workingtree()
 
207
        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
 
208
        tree.add('file-1')
 
209
        revid1 = tree.commit('rev1')
 
210
        self.run_bzr(['switch', '-b', 'anotherbranch'], working_dir='branch-1')
 
211
        bzrdir = BzrDir.open("branch-1")
 
212
        self.assertEquals(
 
213
            set([b.name for b in bzrdir.list_branches()]),
 
214
            set(["foo", "anotherbranch"]))
 
215
        self.assertEquals(bzrdir.open_branch().name, "anotherbranch")
 
216
        self.assertEquals(bzrdir.open_branch().last_revision(), revid1)
 
217
 
 
218
    def test_switch_new_colocated_unicode(self):
 
219
        # Create a branch branch-1 that initially is a checkout of 'foo'
 
220
        # Use switch to create 'branch\xe9' which derives from that
 
221
        self.requireFeature(UnicodeFilenameFeature)
 
222
        repo = self.make_repository('branch-1', format='development-colo')
 
223
        target_branch = repo.bzrdir.create_branch(name='foo')
 
224
        branch.BranchReferenceFormat().initialize(
 
225
            repo.bzrdir, target_branch=target_branch)
 
226
        tree = repo.bzrdir.create_workingtree()
 
227
        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
 
228
        tree.add('file-1')
 
229
        revid1 = tree.commit('rev1')
 
230
        self.run_bzr(['switch', '-b', u'branch\xe9'], working_dir='branch-1')
 
231
        bzrdir = BzrDir.open("branch-1")
 
232
        self.assertEquals(
 
233
            set([b.name for b in bzrdir.list_branches()]),
 
234
            set(["foo", u"branch\xe9"]))
 
235
        self.assertEquals(bzrdir.open_branch().name, u"branch\xe9")
 
236
        self.assertEquals(bzrdir.open_branch().last_revision(), revid1)
 
237
 
162
238
    def test_switch_only_revision(self):
163
239
        tree = self._create_sample_tree()
164
240
        checkout = tree.branch.create_checkout('checkout', lightweight=True)