/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 bzrlib/tests/blackbox/test_switch.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2007-2012 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 breezy.controldir import ControlDir
24
 
from breezy import (
 
23
from bzrlib.controldir import ControlDir
 
24
from bzrlib import (
25
25
    osutils,
26
26
    urlutils,
27
27
    branch,
28
28
    )
29
 
from breezy.workingtree import WorkingTree
30
 
from breezy.tests import (
 
29
from bzrlib.workingtree import WorkingTree
 
30
from bzrlib.tests import (
31
31
    TestCaseWithTransport,
32
32
    script,
33
33
    )
34
 
from breezy.tests.features import UnicodeFilenameFeature
35
 
from breezy.directory_service import directories
 
34
from bzrlib.tests.features import UnicodeFilenameFeature
 
35
from bzrlib.directory_service import directories
36
36
 
37
 
from breezy.tests.matchers import ContainsNoVfsCalls
 
37
from bzrlib.tests.matchers import ContainsNoVfsCalls
38
38
 
39
39
 
40
40
class TestSwitch(TestCaseWithTransport):
133
133
        checkout =  tree1.branch.create_checkout('checkout', lightweight=True)
134
134
        self.run_bzr(['switch', 'branchb'], working_dir='checkout')
135
135
        self.assertEqual(branchb_id, checkout.last_revision())
136
 
        checkout = checkout.controldir.open_workingtree()
 
136
        checkout = checkout.bzrdir.open_workingtree()
137
137
        self.assertEqual(tree2.branch.base, checkout.branch.base)
138
138
 
139
139
    def test_switch_finds_relative_bound_branch(self):
154
154
        checkout = tree1.branch.create_checkout('heavyco/a', lightweight=False)
155
155
        self.run_bzr(['switch', 'branchb'], working_dir='heavyco/a')
156
156
        # Refresh checkout as 'switch' modified it
157
 
        checkout = checkout.controldir.open_workingtree()
 
157
        checkout = checkout.bzrdir.open_workingtree()
158
158
        self.assertEqual(branchb_id, checkout.last_revision())
159
159
        self.assertEqual(tree2.branch.base,
160
160
                         checkout.branch.get_bound_location())
171
171
        checkout =  tree1.branch.create_checkout('checkout', lightweight=True)
172
172
        self.run_bzr(['switch', u'branch\xe9'], working_dir='checkout')
173
173
        self.assertEqual(branchb_id, checkout.last_revision())
174
 
        checkout = checkout.controldir.open_workingtree()
 
174
        checkout = checkout.bzrdir.open_workingtree()
175
175
        self.assertEqual(tree2.branch.base, checkout.branch.base)
176
176
 
177
177
    def test_switch_finds_relative_unicode_branch(self):
186
186
        checkout =  tree1.branch.create_checkout('checkout', lightweight=True)
187
187
        self.run_bzr(['switch', u'branch\xe9'], working_dir='checkout')
188
188
        self.assertEqual(branchb_id, checkout.last_revision())
189
 
        checkout = checkout.controldir.open_workingtree()
 
189
        checkout = checkout.bzrdir.open_workingtree()
190
190
        self.assertEqual(tree2.branch.base, checkout.branch.base)
191
191
 
192
192
    def test_switch_revision(self):
205
205
        tree.add('file-2')
206
206
        revid2 = tree.commit('rev2')
207
207
        self.run_bzr(['switch', '-b', 'anotherbranch'])
208
 
        self.assertEqual(
209
 
            {'', 'anotherbranch'},
210
 
            set(tree.branch.controldir.get_branches().keys()))
 
208
        self.assertEquals(
 
209
            set(['', 'anotherbranch']),
 
210
            set(tree.branch.bzrdir.get_branches().keys()))
211
211
 
212
212
    def test_switch_into_unrelated_colocated(self):
213
213
        # Create a new colocated branch from an existing non-colocated branch.
217
217
        revid1 = tree.commit('rev1')
218
218
        tree.add('file-2')
219
219
        revid2 = tree.commit('rev2')
220
 
        tree.controldir.create_branch(name='foo')
 
220
        tree.bzrdir.create_branch(name='foo')
221
221
        self.run_bzr_error(['Cannot switch a branch, only a checkout.'],
222
222
            'switch foo')
223
223
        self.run_bzr(['switch', '--force', 'foo'])
226
226
        # Create a branch branch-1 that initially is a checkout of 'foo'
227
227
        # Use switch to change it to 'anotherbranch'
228
228
        repo = self.make_repository('branch-1', format='development-colo')
229
 
        target_branch = repo.controldir.create_branch(name='foo')
230
 
        repo.controldir.set_branch_reference(target_branch)
231
 
        tree = repo.controldir.create_workingtree()
 
229
        target_branch = repo.bzrdir.create_branch(name='foo')
 
230
        repo.bzrdir.set_branch_reference(target_branch)
 
231
        tree = repo.bzrdir.create_workingtree()
232
232
        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
233
233
        tree.add('file-1')
234
234
        revid1 = tree.commit('rev1')
235
235
        tree.add('file-2')
236
236
        revid2 = tree.commit('rev2')
237
 
        otherbranch = tree.controldir.create_branch(name='anotherbranch')
 
237
        otherbranch = tree.bzrdir.create_branch(name='anotherbranch')
238
238
        otherbranch.generate_revision_history(revid1)
239
239
        self.run_bzr(['switch', 'anotherbranch'], working_dir='branch-1')
240
240
        tree = WorkingTree.open("branch-1")
241
 
        self.assertEqual(tree.last_revision(), revid1)
242
 
        self.assertEqual(tree.branch.control_url, otherbranch.control_url)
 
241
        self.assertEquals(tree.last_revision(), revid1)
 
242
        self.assertEquals(tree.branch.control_url, otherbranch.control_url)
243
243
 
244
244
    def test_switch_new_colocated(self):
245
245
        # Create a branch branch-1 that initially is a checkout of 'foo'
246
246
        # Use switch to create 'anotherbranch' which derives from that
247
247
        repo = self.make_repository('branch-1', format='development-colo')
248
 
        target_branch = repo.controldir.create_branch(name='foo')
249
 
        repo.controldir.set_branch_reference(target_branch)
250
 
        tree = repo.controldir.create_workingtree()
 
248
        target_branch = repo.bzrdir.create_branch(name='foo')
 
249
        repo.bzrdir.set_branch_reference(target_branch)
 
250
        tree = repo.bzrdir.create_workingtree()
251
251
        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
252
252
        tree.add('file-1')
253
253
        revid1 = tree.commit('rev1')
254
254
        self.run_bzr(['switch', '-b', 'anotherbranch'], working_dir='branch-1')
255
255
        bzrdir = ControlDir.open("branch-1")
256
 
        self.assertEqual(
257
 
            {b.name for b in bzrdir.list_branches()},
258
 
            {"foo", "anotherbranch"})
259
 
        self.assertEqual(bzrdir.open_branch().name, "anotherbranch")
260
 
        self.assertEqual(bzrdir.open_branch().last_revision(), revid1)
 
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)
261
261
 
262
262
    def test_switch_new_colocated_unicode(self):
263
263
        # Create a branch branch-1 that initially is a checkout of 'foo'
264
264
        # Use switch to create 'branch\xe9' which derives from that
265
265
        self.requireFeature(UnicodeFilenameFeature)
266
266
        repo = self.make_repository('branch-1', format='development-colo')
267
 
        target_branch = repo.controldir.create_branch(name='foo')
268
 
        repo.controldir.set_branch_reference(target_branch)
269
 
        tree = repo.controldir.create_workingtree()
 
267
        target_branch = repo.bzrdir.create_branch(name='foo')
 
268
        repo.bzrdir.set_branch_reference(target_branch)
 
269
        tree = repo.bzrdir.create_workingtree()
270
270
        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
271
271
        tree.add('file-1')
272
272
        revid1 = tree.commit('rev1')
273
273
        self.run_bzr(['switch', '-b', u'branch\xe9'], working_dir='branch-1')
274
274
        bzrdir = ControlDir.open("branch-1")
275
 
        self.assertEqual(
276
 
            {b.name for b in bzrdir.list_branches()},
277
 
            {"foo", u"branch\xe9"})
278
 
        self.assertEqual(bzrdir.open_branch().name, u"branch\xe9")
279
 
        self.assertEqual(bzrdir.open_branch().last_revision(), revid1)
 
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)
280
280
 
281
281
    def test_switch_only_revision(self):
282
282
        tree = self._create_sample_tree()
288
288
        self.assertPathDoesNotExist('checkout/file-2')
289
289
        # Check that we don't accept a range
290
290
        self.run_bzr_error(
291
 
            ['brz switch --revision takes exactly one revision identifier'],
 
291
            ['bzr switch --revision takes exactly one revision identifier'],
292
292
            ['switch', '-r0..2'], working_dir='checkout')
293
293
 
294
294
    def prepare_lightweight_switch(self):
317
317
    def test_create_branch(self):
318
318
        branch = self.make_branch('branch')
319
319
        tree = branch.create_checkout('tree', lightweight=True)
320
 
        tree.commit('one', rev_id=b'rev-1')
 
320
        tree.commit('one', rev_id='rev-1')
321
321
        self.run_bzr('switch --create-branch ../branch2', working_dir='tree')
322
322
        tree = WorkingTree.open('tree')
323
323
        self.assertEndsWith(tree.branch.base, '/branch2/')
325
325
    def test_create_branch_local(self):
326
326
        branch = self.make_branch('branch')
327
327
        tree = branch.create_checkout('tree', lightweight=True)
328
 
        tree.commit('one', rev_id=b'rev-1')
 
328
        tree.commit('one', rev_id='rev-1')
329
329
        self.run_bzr('switch --create-branch branch2', working_dir='tree')
330
330
        tree = WorkingTree.open('tree')
331
331
        # The new branch should have been created at the same level as
335
335
    def test_create_branch_short_name(self):
336
336
        branch = self.make_branch('branch')
337
337
        tree = branch.create_checkout('tree', lightweight=True)
338
 
        tree.commit('one', rev_id=b'rev-1')
 
338
        tree.commit('one', rev_id='rev-1')
339
339
        self.run_bzr('switch -b branch2', working_dir='tree')
340
340
        tree = WorkingTree.open('tree')
341
341
        # The new branch should have been created at the same level as
355
355
        self.assertEndsWith(tree.branch.base, 'foo-branch2/')
356
356
 
357
357
    def test_switch_with_post_switch_hook(self):
358
 
        from breezy import branch as _mod_branch
 
358
        from bzrlib import branch as _mod_branch
359
359
        calls = []
360
360
        _mod_branch.Branch.hooks.install_named_hook('post_switch',
361
361
            calls.append, None)
368
368
        self.assertLength(1, calls)
369
369
 
370
370
    def test_switch_lightweight_co_with_post_switch_hook(self):
371
 
        from breezy import branch as _mod_branch
 
371
        from bzrlib import branch as _mod_branch
372
372
        calls = []
373
373
        _mod_branch.Branch.hooks.install_named_hook('post_switch',
374
374
            calls.append, None)
385
385
 
386
386
        # create a source branch
387
387
        a_tree = self.make_branch_and_tree('a')
388
 
        self.build_tree_contents([('a/a', b'initial\n')])
 
388
        self.build_tree_contents([('a/a', 'initial\n')])
389
389
        a_tree.add('a')
390
390
        a_tree.commit(message='initial')
391
391
 
392
392
        # clone and add a differing revision
393
 
        b_tree = a_tree.controldir.sprout('b').open_workingtree()
394
 
        self.build_tree_contents([('b/a', b'initial\nmore\n')])
 
393
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
394
        self.build_tree_contents([('b/a', 'initial\nmore\n')])
395
395
        b_tree.commit(message='more')
396
396
 
397
397
        self.run_bzr('checkout --lightweight a checkout')
406
406
        super(TestSwitchParentLocationBase, self).setUp()
407
407
        self.script_runner = script.ScriptRunner()
408
408
        self.script_runner.run_script(self, '''
409
 
                $ brz init-repo --no-trees repo
 
409
                $ bzr init-repo --no-trees repo
410
410
                Shared repository...
411
411
                Location:
412
412
                  shared repository: repo
413
 
                $ brz init repo/trunk
 
413
                $ bzr init repo/trunk
414
414
                Created a repository branch...
415
415
                Using shared repository: ...
416
416
                ''')
426
426
 
427
427
    def _checkout_and_switch(self, option=''):
428
428
        self.script_runner.run_script(self, '''
429
 
                $ brz checkout %(option)s repo/trunk checkout
 
429
                $ bzr checkout %(option)s repo/trunk checkout
430
430
                $ cd checkout
431
 
                $ brz switch --create-branch switched
 
431
                $ bzr switch --create-branch switched
432
432
                2>Tree is up to date at revision 0.
433
433
                2>Switched to branch:...switched...
434
434
                $ cd ..
438
438
        return (bound_branch, master_branch)
439
439
 
440
440
    def test_switch_parent_lightweight(self):
441
 
        """Lightweight checkout using brz switch."""
 
441
        """Lightweight checkout using bzr switch."""
442
442
        bb, mb = self._checkout_and_switch(option='--lightweight')
443
443
        self.assertParent('repo/trunk', bb)
444
444
        self.assertParent('repo/trunk', mb)
445
445
 
446
446
    def test_switch_parent_heavyweight(self):
447
 
        """Heavyweight checkout using brz switch."""
 
447
        """Heavyweight checkout using bzr switch."""
448
448
        bb, mb = self._checkout_and_switch()
449
449
        self.assertParent('repo/trunk', bb)
450
450
        self.assertParent('repo/trunk', mb)
452
452
 
453
453
class TestSwitchDoesntOpenMasterBranch(TestCaseWithTransport):
454
454
    # See https://bugs.launchpad.net/bzr/+bug/812285
455
 
    # "brz switch --create-branch" can point the new branch's parent to the
 
455
    # "bzr switch --create-branch" can point the new branch's parent to the
456
456
    # master branch, but it doesn't have to open it to do so.
457
457
 
458
458
    def test_switch_create_doesnt_open_master_branch(self):
500
500
    def prepare(self):
501
501
        tree = self.make_branch_and_tree('orig')
502
502
        tree.commit('')
503
 
        tree.branch.controldir.sprout('new')
 
503
        tree.branch.bzrdir.sprout('new')
504
504
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
505
505
        self.build_tree(['checkout/a'])
506
506
        self.assertPathExists('checkout/a')
529
529
        self.assertPathDoesNotExist('checkout/a')
530
530
        self.run_bzr(['switch', '-d', 'checkout', 'orig'])
531
531
        self.assertPathDoesNotExist('checkout/a')
532
 
 
533
 
 
534
 
class TestSwitchStandAloneCorruption(TestCaseWithTransport):
535
 
 
536
 
    def test_empty_tree_switch(self):
537
 
        """switch . on an empty tree gets infinite recursion
538
 
 
539
 
        Inspired by: https://bugs.launchpad.net/bzr/+bug/1018628
540
 
        """
541
 
        self.script_runner = script.ScriptRunner()
542
 
        self.script_runner.run_script(self, '''
543
 
            $ brz init
544
 
            Created a standalone tree (format: 2a)
545
 
            $ brz switch .
546
 
            2>brz: ERROR: switching would create a branch reference loop. Use the "bzr up" command to switch to a different revision.
547
 
            ''')
548
 
 
549
 
    def test_switch_on_previous_rev(self):
550
 
        """switch to previous rev in a standalone directory
551
 
 
552
 
        Inspired by: https://bugs.launchpad.net/brz/+bug/1018628
553
 
        """
554
 
        self.script_runner = script.ScriptRunner()
555
 
        self.script_runner.run_script(self, '''
556
 
           $ brz init
557
 
           Created a standalone tree (format: 2a)
558
 
           $ brz commit -m 1 --unchanged
559
 
           $ brz commit -m 2 --unchanged
560
 
           $ brz switch -r 1
561
 
           2>brz: ERROR: switching would create a branch reference loop. Use the "bzr up" command to switch to a different revision.''',
562
 
           null_output_matches_anything=True)
563
 
 
564
 
    def test_switch_create_colo_locks_repo_path(self):
565
 
        self.script_runner = script.ScriptRunner()
566
 
        self.script_runner.run_script(self, '''
567
 
            $ mkdir mywork
568
 
            $ cd mywork
569
 
            $ brz init
570
 
            Created a standalone tree (format: 2a)
571
 
            $ echo A > a && brz add a && brz commit -m A
572
 
            $ brz switch -b br1
573
 
            $ cd ..
574
 
            $ mv mywork mywork1
575
 
            $ cd mywork1
576
 
            $ brz branches
577
 
            * br1
578
 
            ''', null_output_matches_anything=True)