/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2012 Canonical Ltd
 
1
# Copyright (C) 2007-2012, 2016 Canonical Ltd
2
2
# -*- coding: utf-8 -*-
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
20
20
 
21
21
import os
22
22
 
23
 
from bzrlib.controldir import ControlDir
24
 
from bzrlib import (
 
23
from breezy.controldir import ControlDir
 
24
from breezy import (
25
25
    osutils,
26
26
    urlutils,
27
27
    branch,
28
28
    )
29
 
from bzrlib.workingtree import WorkingTree
30
 
from bzrlib.tests import (
 
29
from breezy.workingtree import WorkingTree
 
30
from breezy.tests import (
31
31
    TestCaseWithTransport,
32
32
    script,
33
33
    )
34
 
from bzrlib.tests.features import UnicodeFilenameFeature
35
 
from bzrlib.directory_service import directories
36
 
 
37
 
from bzrlib.tests.matchers import ContainsNoVfsCalls
 
34
from breezy.tests.features import UnicodeFilenameFeature
 
35
from breezy.directory_service import directories
38
36
 
39
37
 
40
38
class TestSwitch(TestCaseWithTransport):
55
53
        os.chdir('checkout')
56
54
        out, err = self.run_bzr('switch ../branch2')
57
55
        self.assertContainsRe(err, 'Tree is up to date at revision 0.\n')
58
 
        self.assertContainsRe(err, 'Switched to branch: .*/branch2.\n')
 
56
        self.assertContainsRe(err, 'Switched to branch at .*/branch2.\n')
59
57
        self.assertEqual('', out)
60
58
 
61
59
    def test_switch_out_of_date_light_checkout(self):
69
67
        out, err = self.run_bzr('switch ../branch2')
70
68
        #self.assertContainsRe(err, '\+N  file')
71
69
        self.assertContainsRe(err, 'Updated to revision 1.\n')
72
 
        self.assertContainsRe(err, 'Switched to branch: .*/branch2.\n')
 
70
        self.assertContainsRe(err, 'Switched to branch at .*/branch2.\n')
73
71
        self.assertEqual('', out)
74
72
 
75
73
    def _test_switch_nick(self, lightweight):
77
75
        tree1 = self.make_branch_and_tree('branch1')
78
76
        tree2 = self.make_branch_and_tree('branch2')
79
77
        tree2.pull(tree1.branch)
80
 
        checkout =  tree1.branch.create_checkout('checkout',
81
 
            lightweight=lightweight)
 
78
        checkout = tree1.branch.create_checkout('checkout',
 
79
                                                lightweight=lightweight)
82
80
        self.assertEqual(checkout.branch.nick, tree1.branch.nick)
83
81
        self.assertEqual(checkout.branch.get_config().has_explicit_nickname(),
84
 
            False)
 
82
                         False)
85
83
        self.run_bzr('switch branch2', working_dir='checkout')
86
84
 
87
85
        # we need to get the tree again, otherwise we don't get the new branch
88
86
        checkout = WorkingTree.open('checkout')
89
87
        self.assertEqual(checkout.branch.nick, tree2.branch.nick)
90
88
        self.assertEqual(checkout.branch.get_config().has_explicit_nickname(),
91
 
            False)
 
89
                         False)
92
90
 
93
91
    def test_switch_nick(self):
94
92
        self._test_switch_nick(lightweight=False)
101
99
        tree1 = self.make_branch_and_tree('branch1')
102
100
        tree2 = self.make_branch_and_tree('branch2')
103
101
        tree2.pull(tree1.branch)
104
 
        checkout =  tree1.branch.create_checkout('checkout',
105
 
            lightweight=lightweight)
 
102
        checkout = tree1.branch.create_checkout('checkout',
 
103
                                                lightweight=lightweight)
106
104
        self.assertEqual(checkout.branch.nick, tree1.branch.nick)
107
105
        checkout.branch.nick = "explicit_nick"
108
106
        self.assertEqual(checkout.branch.nick, "explicit_nick")
109
107
        self.assertEqual(checkout.branch.get_config()._get_explicit_nickname(),
110
 
            "explicit_nick")
 
108
                         "explicit_nick")
111
109
        self.run_bzr('switch branch2', working_dir='checkout')
112
110
 
113
111
        # we need to get the tree again, otherwise we don't get the new branch
114
112
        checkout = WorkingTree.open('checkout')
115
113
        self.assertEqual(checkout.branch.nick, tree2.branch.nick)
116
114
        self.assertEqual(checkout.branch.get_config()._get_explicit_nickname(),
117
 
            tree2.branch.nick)
 
115
                         tree2.branch.nick)
118
116
 
119
117
    def test_switch_explicit_nick(self):
120
118
        self._test_switch_explicit_nick(lightweight=False)
130
128
        tree2 = self.make_branch_and_tree('repo/branchb')
131
129
        tree2.pull(tree1.branch)
132
130
        branchb_id = tree2.commit('bar')
133
 
        checkout =  tree1.branch.create_checkout('checkout', lightweight=True)
 
131
        checkout = tree1.branch.create_checkout('checkout', lightweight=True)
134
132
        self.run_bzr(['switch', 'branchb'], working_dir='checkout')
135
133
        self.assertEqual(branchb_id, checkout.last_revision())
136
 
        checkout = checkout.bzrdir.open_workingtree()
 
134
        checkout = checkout.controldir.open_workingtree()
137
135
        self.assertEqual(tree2.branch.base, checkout.branch.base)
138
136
 
139
137
    def test_switch_finds_relative_bound_branch(self):
154
152
        checkout = tree1.branch.create_checkout('heavyco/a', lightweight=False)
155
153
        self.run_bzr(['switch', 'branchb'], working_dir='heavyco/a')
156
154
        # Refresh checkout as 'switch' modified it
157
 
        checkout = checkout.bzrdir.open_workingtree()
 
155
        checkout = checkout.controldir.open_workingtree()
158
156
        self.assertEqual(branchb_id, checkout.last_revision())
159
157
        self.assertEqual(tree2.branch.base,
160
158
                         checkout.branch.get_bound_location())
168
166
        tree2 = self.make_branch_and_tree(u'repo/branch\xe9')
169
167
        tree2.pull(tree1.branch)
170
168
        branchb_id = tree2.commit('bar')
171
 
        checkout =  tree1.branch.create_checkout('checkout', lightweight=True)
 
169
        checkout = tree1.branch.create_checkout('checkout', lightweight=True)
172
170
        self.run_bzr(['switch', u'branch\xe9'], working_dir='checkout')
173
171
        self.assertEqual(branchb_id, checkout.last_revision())
174
 
        checkout = checkout.bzrdir.open_workingtree()
 
172
        checkout = checkout.controldir.open_workingtree()
175
173
        self.assertEqual(tree2.branch.base, checkout.branch.base)
176
174
 
177
175
    def test_switch_finds_relative_unicode_branch(self):
183
181
        tree2 = self.make_branch_and_tree(u'repo/branch\xe9')
184
182
        tree2.pull(tree1.branch)
185
183
        branchb_id = tree2.commit('bar')
186
 
        checkout =  tree1.branch.create_checkout('checkout', lightweight=True)
 
184
        checkout = tree1.branch.create_checkout('checkout', lightweight=True)
187
185
        self.run_bzr(['switch', u'branch\xe9'], working_dir='checkout')
188
186
        self.assertEqual(branchb_id, checkout.last_revision())
189
 
        checkout = checkout.bzrdir.open_workingtree()
 
187
        checkout = checkout.controldir.open_workingtree()
190
188
        self.assertEqual(tree2.branch.base, checkout.branch.base)
191
189
 
192
190
    def test_switch_revision(self):
205
203
        tree.add('file-2')
206
204
        revid2 = tree.commit('rev2')
207
205
        self.run_bzr(['switch', '-b', 'anotherbranch'])
208
 
        self.assertEquals(
209
 
            set(['', 'anotherbranch']),
210
 
            set(tree.branch.bzrdir.get_branches().keys()))
 
206
        self.assertEqual(
 
207
            {'', 'anotherbranch'},
 
208
            set(tree.branch.controldir.branch_names()))
211
209
 
212
210
    def test_switch_into_unrelated_colocated(self):
213
211
        # Create a new colocated branch from an existing non-colocated branch.
217
215
        revid1 = tree.commit('rev1')
218
216
        tree.add('file-2')
219
217
        revid2 = tree.commit('rev2')
220
 
        tree.bzrdir.create_branch(name='foo')
 
218
        tree.controldir.create_branch(name='foo')
221
219
        self.run_bzr_error(['Cannot switch a branch, only a checkout.'],
222
 
            'switch foo')
 
220
                           'switch foo')
223
221
        self.run_bzr(['switch', '--force', 'foo'])
224
222
 
225
223
    def test_switch_existing_colocated(self):
226
224
        # Create a branch branch-1 that initially is a checkout of 'foo'
227
225
        # Use switch to change it to 'anotherbranch'
228
226
        repo = self.make_repository('branch-1', format='development-colo')
229
 
        target_branch = repo.bzrdir.create_branch(name='foo')
230
 
        repo.bzrdir.set_branch_reference(target_branch)
231
 
        tree = repo.bzrdir.create_workingtree()
 
227
        target_branch = repo.controldir.create_branch(name='foo')
 
228
        repo.controldir.set_branch_reference(target_branch)
 
229
        tree = repo.controldir.create_workingtree()
232
230
        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
233
231
        tree.add('file-1')
234
232
        revid1 = tree.commit('rev1')
235
233
        tree.add('file-2')
236
234
        revid2 = tree.commit('rev2')
237
 
        otherbranch = tree.bzrdir.create_branch(name='anotherbranch')
 
235
        otherbranch = tree.controldir.create_branch(name='anotherbranch')
238
236
        otherbranch.generate_revision_history(revid1)
239
237
        self.run_bzr(['switch', 'anotherbranch'], working_dir='branch-1')
240
238
        tree = WorkingTree.open("branch-1")
241
 
        self.assertEquals(tree.last_revision(), revid1)
242
 
        self.assertEquals(tree.branch.control_url, otherbranch.control_url)
 
239
        self.assertEqual(tree.last_revision(), revid1)
 
240
        self.assertEqual(tree.branch.control_url, otherbranch.control_url)
243
241
 
244
242
    def test_switch_new_colocated(self):
245
243
        # Create a branch branch-1 that initially is a checkout of 'foo'
246
244
        # Use switch to create 'anotherbranch' which derives from that
247
245
        repo = self.make_repository('branch-1', format='development-colo')
248
 
        target_branch = repo.bzrdir.create_branch(name='foo')
249
 
        repo.bzrdir.set_branch_reference(target_branch)
250
 
        tree = repo.bzrdir.create_workingtree()
 
246
        target_branch = repo.controldir.create_branch(name='foo')
 
247
        repo.controldir.set_branch_reference(target_branch)
 
248
        tree = repo.controldir.create_workingtree()
251
249
        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
252
250
        tree.add('file-1')
253
251
        revid1 = tree.commit('rev1')
254
252
        self.run_bzr(['switch', '-b', 'anotherbranch'], working_dir='branch-1')
255
253
        bzrdir = ControlDir.open("branch-1")
256
 
        self.assertEquals(
257
 
            set([b.name for b in bzrdir.list_branches()]),
258
 
            set(["foo", "anotherbranch"]))
259
 
        self.assertEquals(bzrdir.open_branch().name, "anotherbranch")
260
 
        self.assertEquals(bzrdir.open_branch().last_revision(), revid1)
 
254
        self.assertEqual(
 
255
            {b.name for b in bzrdir.list_branches()},
 
256
            {"foo", "anotherbranch"})
 
257
        self.assertEqual(bzrdir.open_branch().name, "anotherbranch")
 
258
        self.assertEqual(bzrdir.open_branch().last_revision(), revid1)
261
259
 
262
260
    def test_switch_new_colocated_unicode(self):
263
261
        # Create a branch branch-1 that initially is a checkout of 'foo'
264
262
        # Use switch to create 'branch\xe9' which derives from that
265
263
        self.requireFeature(UnicodeFilenameFeature)
266
264
        repo = self.make_repository('branch-1', format='development-colo')
267
 
        target_branch = repo.bzrdir.create_branch(name='foo')
268
 
        repo.bzrdir.set_branch_reference(target_branch)
269
 
        tree = repo.bzrdir.create_workingtree()
 
265
        target_branch = repo.controldir.create_branch(name='foo')
 
266
        repo.controldir.set_branch_reference(target_branch)
 
267
        tree = repo.controldir.create_workingtree()
270
268
        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
271
269
        tree.add('file-1')
272
270
        revid1 = tree.commit('rev1')
273
271
        self.run_bzr(['switch', '-b', u'branch\xe9'], working_dir='branch-1')
274
272
        bzrdir = ControlDir.open("branch-1")
275
 
        self.assertEquals(
276
 
            set([b.name for b in bzrdir.list_branches()]),
277
 
            set(["foo", u"branch\xe9"]))
278
 
        self.assertEquals(bzrdir.open_branch().name, u"branch\xe9")
279
 
        self.assertEquals(bzrdir.open_branch().last_revision(), revid1)
 
273
        self.assertEqual(
 
274
            {b.name for b in bzrdir.list_branches()},
 
275
            {"foo", u"branch\xe9"})
 
276
        self.assertEqual(bzrdir.open_branch().name, u"branch\xe9")
 
277
        self.assertEqual(bzrdir.open_branch().last_revision(), revid1)
280
278
 
281
279
    def test_switch_only_revision(self):
282
280
        tree = self._create_sample_tree()
288
286
        self.assertPathDoesNotExist('checkout/file-2')
289
287
        # Check that we don't accept a range
290
288
        self.run_bzr_error(
291
 
            ['bzr switch --revision takes exactly one revision identifier'],
 
289
            ['brz switch --revision takes exactly one revision identifier'],
292
290
            ['switch', '-r0..2'], working_dir='checkout')
293
291
 
294
292
    def prepare_lightweight_switch(self):
312
310
    def test_create_branch_no_branch(self):
313
311
        self.prepare_lightweight_switch()
314
312
        self.run_bzr_error(['cannot create branch without source branch'],
315
 
            'switch --create-branch ../branch2', working_dir='tree')
 
313
                           'switch --create-branch ../branch2', working_dir='tree')
316
314
 
317
315
    def test_create_branch(self):
318
316
        branch = self.make_branch('branch')
319
317
        tree = branch.create_checkout('tree', lightweight=True)
320
 
        tree.commit('one', rev_id='rev-1')
 
318
        tree.commit('one', rev_id=b'rev-1')
321
319
        self.run_bzr('switch --create-branch ../branch2', working_dir='tree')
322
320
        tree = WorkingTree.open('tree')
323
321
        self.assertEndsWith(tree.branch.base, '/branch2/')
325
323
    def test_create_branch_local(self):
326
324
        branch = self.make_branch('branch')
327
325
        tree = branch.create_checkout('tree', lightweight=True)
328
 
        tree.commit('one', rev_id='rev-1')
 
326
        tree.commit('one', rev_id=b'rev-1')
329
327
        self.run_bzr('switch --create-branch branch2', working_dir='tree')
330
328
        tree = WorkingTree.open('tree')
331
329
        # The new branch should have been created at the same level as
335
333
    def test_create_branch_short_name(self):
336
334
        branch = self.make_branch('branch')
337
335
        tree = branch.create_checkout('tree', lightweight=True)
338
 
        tree.commit('one', rev_id='rev-1')
 
336
        tree.commit('one', rev_id=b'rev-1')
339
337
        self.run_bzr('switch -b branch2', working_dir='tree')
340
338
        tree = WorkingTree.open('tree')
341
339
        # The new branch should have been created at the same level as
345
343
    def test_create_branch_directory_services(self):
346
344
        branch = self.make_branch('branch')
347
345
        tree = branch.create_checkout('tree', lightweight=True)
 
346
 
348
347
        class FooLookup(object):
349
 
            def look_up(self, name, url):
350
 
                return 'foo-'+name
 
348
            def look_up(self, name, url, purpose=None):
 
349
                return 'foo-' + name
351
350
        directories.register('foo:', FooLookup, 'Create branches named foo-')
352
351
        self.addCleanup(directories.remove, 'foo:')
353
352
        self.run_bzr('switch -b foo:branch2', working_dir='tree')
355
354
        self.assertEndsWith(tree.branch.base, 'foo-branch2/')
356
355
 
357
356
    def test_switch_with_post_switch_hook(self):
358
 
        from bzrlib import branch as _mod_branch
 
357
        from breezy import branch as _mod_branch
359
358
        calls = []
360
359
        _mod_branch.Branch.hooks.install_named_hook('post_switch',
361
 
            calls.append, None)
 
360
                                                    calls.append, None)
362
361
        self.make_branch_and_tree('branch')
363
362
        self.run_bzr('branch branch branch2')
364
363
        self.run_bzr('checkout branch checkout')
368
367
        self.assertLength(1, calls)
369
368
 
370
369
    def test_switch_lightweight_co_with_post_switch_hook(self):
371
 
        from bzrlib import branch as _mod_branch
 
370
        from breezy import branch as _mod_branch
372
371
        calls = []
373
372
        _mod_branch.Branch.hooks.install_named_hook('post_switch',
374
 
            calls.append, None)
 
373
                                                    calls.append, None)
375
374
        self.make_branch_and_tree('branch')
376
375
        self.run_bzr('branch branch branch2')
377
376
        self.run_bzr('checkout --lightweight branch checkout')
385
384
 
386
385
        # create a source branch
387
386
        a_tree = self.make_branch_and_tree('a')
388
 
        self.build_tree_contents([('a/a', 'initial\n')])
 
387
        self.build_tree_contents([('a/a', b'initial\n')])
389
388
        a_tree.add('a')
390
389
        a_tree.commit(message='initial')
391
390
 
392
391
        # clone and add a differing revision
393
 
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
394
 
        self.build_tree_contents([('b/a', 'initial\nmore\n')])
 
392
        b_tree = a_tree.controldir.sprout('b').open_workingtree()
 
393
        self.build_tree_contents([('b/a', b'initial\nmore\n')])
395
394
        b_tree.commit(message='more')
396
395
 
397
396
        self.run_bzr('checkout --lightweight a checkout')
398
397
        self.run_bzr('switch --directory checkout b')
399
 
        self.assertFileEqual('initial\nmore\n', 'checkout/a')
 
398
        self.assertFileEqual(b'initial\nmore\n', 'checkout/a')
400
399
 
401
400
 
402
401
class TestSwitchParentLocationBase(TestCaseWithTransport):
406
405
        super(TestSwitchParentLocationBase, self).setUp()
407
406
        self.script_runner = script.ScriptRunner()
408
407
        self.script_runner.run_script(self, '''
409
 
                $ bzr init-repo --no-trees repo
 
408
                $ brz init-shared-repo --no-trees repo
410
409
                Shared repository...
411
410
                Location:
412
411
                  shared repository: repo
413
 
                $ bzr init repo/trunk
 
412
                $ brz init repo/trunk
414
413
                Created a repository branch...
415
414
                Using shared repository: ...
416
415
                ''')
426
425
 
427
426
    def _checkout_and_switch(self, option=''):
428
427
        self.script_runner.run_script(self, '''
429
 
                $ bzr checkout %(option)s repo/trunk checkout
 
428
                $ brz checkout %(option)s repo/trunk checkout
430
429
                $ cd checkout
431
 
                $ bzr switch --create-branch switched
 
430
                $ brz switch --create-branch switched
432
431
                2>Tree is up to date at revision 0.
433
 
                2>Switched to branch:...switched...
 
432
                2>Switched to branch at .../switched/
434
433
                $ cd ..
435
434
                ''' % locals())
436
435
        bound_branch = branch.Branch.open_containing('checkout')[0]
438
437
        return (bound_branch, master_branch)
439
438
 
440
439
    def test_switch_parent_lightweight(self):
441
 
        """Lightweight checkout using bzr switch."""
 
440
        """Lightweight checkout using brz switch."""
442
441
        bb, mb = self._checkout_and_switch(option='--lightweight')
443
442
        self.assertParent('repo/trunk', bb)
444
443
        self.assertParent('repo/trunk', mb)
445
444
 
446
445
    def test_switch_parent_heavyweight(self):
447
 
        """Heavyweight checkout using bzr switch."""
 
446
        """Heavyweight checkout using brz switch."""
448
447
        bb, mb = self._checkout_and_switch()
449
448
        self.assertParent('repo/trunk', bb)
450
449
        self.assertParent('repo/trunk', mb)
452
451
 
453
452
class TestSwitchDoesntOpenMasterBranch(TestCaseWithTransport):
454
453
    # See https://bugs.launchpad.net/bzr/+bug/812285
455
 
    # "bzr switch --create-branch" can point the new branch's parent to the
 
454
    # "brz switch --create-branch" can point the new branch's parent to the
456
455
    # master branch, but it doesn't have to open it to do so.
457
456
 
458
457
    def test_switch_create_doesnt_open_master_branch(self):
461
460
        # Note: not a lightweight checkout
462
461
        checkout = master.branch.create_checkout('checkout')
463
462
        opened = []
 
463
 
464
464
        def open_hook(branch):
465
465
            # Just append the final directory of the branch
466
466
            name = branch.base.rstrip('/').rsplit('/', 1)[1]
474
474
        self.assertEqual(1, opened.count('master'))
475
475
 
476
476
 
477
 
class TestSmartServerSwitch(TestCaseWithTransport):
478
 
 
479
 
    def test_switch_lightweight(self):
480
 
        self.setup_smart_server_with_call_log()
481
 
        t = self.make_branch_and_tree('from')
482
 
        for count in range(9):
483
 
            t.commit(message='commit %d' % count)
484
 
        out, err = self.run_bzr(['checkout', '--lightweight', self.get_url('from'),
485
 
            'target'])
486
 
        self.reset_smart_call_log()
487
 
        self.run_bzr(['switch', self.get_url('from')], working_dir='target')
488
 
        # This figure represent the amount of work to perform this use case. It
489
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
490
 
        # being too low. If rpc_count increases, more network roundtrips have
491
 
        # become necessary for this use case. Please do not adjust this number
492
 
        # upwards without agreement from bzr's network support maintainers.
493
 
        self.assertLength(24, self.hpss_calls)
494
 
        self.assertLength(4, self.hpss_connections)
495
 
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
496
 
 
497
 
 
498
477
class TestSwitchUncommitted(TestCaseWithTransport):
499
478
 
500
479
    def prepare(self):
501
480
        tree = self.make_branch_and_tree('orig')
502
481
        tree.commit('')
503
 
        tree.branch.bzrdir.sprout('new')
 
482
        tree.branch.controldir.sprout('new')
504
483
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
505
484
        self.build_tree(['checkout/a'])
506
485
        self.assertPathExists('checkout/a')
529
508
        self.assertPathDoesNotExist('checkout/a')
530
509
        self.run_bzr(['switch', '-d', 'checkout', 'orig'])
531
510
        self.assertPathDoesNotExist('checkout/a')
 
511
 
 
512
 
 
513
class TestSwitchStandAloneCorruption(TestCaseWithTransport):
 
514
 
 
515
    def test_empty_tree_switch(self):
 
516
        """switch . on an empty tree gets infinite recursion
 
517
 
 
518
        Inspired by: https://bugs.launchpad.net/bzr/+bug/1018628
 
519
        """
 
520
        self.script_runner = script.ScriptRunner()
 
521
        self.script_runner.run_script(self, '''
 
522
            $ brz init
 
523
            Created a standalone tree (format: 2a)
 
524
            $ brz switch .
 
525
            2>brz: ERROR: switching would create a branch reference loop. Use the "bzr up" command to switch to a different revision.
 
526
            ''')
 
527
 
 
528
    def test_switch_on_previous_rev(self):
 
529
        """switch to previous rev in a standalone directory
 
530
 
 
531
        Inspired by: https://bugs.launchpad.net/brz/+bug/1018628
 
532
        """
 
533
        self.script_runner = script.ScriptRunner()
 
534
        self.script_runner.run_script(self, '''
 
535
           $ brz init
 
536
           Created a standalone tree (format: 2a)
 
537
           $ brz commit -m 1 --unchanged
 
538
           $ brz commit -m 2 --unchanged
 
539
           $ brz switch -r 1
 
540
           2>brz: ERROR: switching would create a branch reference loop. Use the "bzr up" command to switch to a different revision.''',
 
541
                                      null_output_matches_anything=True)
 
542
 
 
543
    def test_switch_create_colo_locks_repo_path(self):
 
544
        self.script_runner = script.ScriptRunner()
 
545
        self.script_runner.run_script(self, '''
 
546
            $ mkdir mywork
 
547
            $ cd mywork
 
548
            $ brz init
 
549
            Created a standalone tree (format: 2a)
 
550
            $ echo A > a && brz add a && brz commit -m A
 
551
            $ brz switch -b br1
 
552
            $ cd ..
 
553
            $ mv mywork mywork1
 
554
            $ cd mywork1
 
555
            $ brz branches
 
556
              br1
 
557
            ''', null_output_matches_anything=True)
 
558
 
 
559
    def test_switch_to_new_branch_on_old_rev(self):
 
560
        """switch to previous rev in a standalone directory
 
561
 
 
562
        Inspired by: https://bugs.launchpad.net/brz/+bug/933362
 
563
        """
 
564
        self.script_runner = script.ScriptRunner()
 
565
        self.script_runner.run_script(self, '''
 
566
           $ brz init
 
567
           Created a standalone tree (format: 2a)
 
568
           $ brz switch -b trunk
 
569
           2>Tree is up to date at revision 0.
 
570
           2>Switched to branch trunk
 
571
           $ brz commit -m 1 --unchanged
 
572
           2>Committing to: ...
 
573
           2>Committed revision 1.
 
574
           $ brz commit -m 2 --unchanged
 
575
           2>Committing to: ...
 
576
           2>Committed revision 2.
 
577
           $ brz switch -b blah -r1
 
578
           2>Updated to revision 1.
 
579
           2>Switched to branch blah
 
580
           $ brz branches
 
581
           * blah
 
582
             trunk
 
583
           $ brz st
 
584
           ''')