~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2011-02-10 12:37:27 UTC
  • mto: This revision was merged to the branch mainline in revision 5661.
  • Revision ID: v.ladeuil+lp@free.fr-20110210123727-8e0pu4wtlt6fj7nf
thread is already a python module, avoid confusion and use cethread instead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
29
29
from bzrlib.tests import TestCaseWithTransport
30
30
from bzrlib.tests import (
31
 
    fixtures,
32
 
    script,
 
31
    HardlinkFeature,
33
32
    test_server,
34
33
    )
35
 
from bzrlib.tests.features import (
36
 
    HardlinkFeature,
37
 
    )
38
 
from bzrlib.tests.blackbox import test_switch
39
34
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
40
 
from bzrlib.tests.script import run_script
41
35
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
42
36
from bzrlib.workingtree import WorkingTree
43
37
 
63
57
        self.assertFalse(b._transport.has('branch-name'))
64
58
        b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
65
59
 
66
 
    def test_branch_broken_pack(self):
67
 
        """branching with a corrupted pack file."""
68
 
        self.example_branch('a')
69
 
        # add some corruption
70
 
        packs_dir = 'a/.bzr/repository/packs/'
71
 
        fname = packs_dir + os.listdir(packs_dir)[0]
72
 
        with open(fname, 'rb+') as f:
73
 
            # Start from the end of the file to avoid choosing a place bigger
74
 
            # than the file itself.
75
 
            f.seek(-5, os.SEEK_END)
76
 
            c = f.read(1)
77
 
            f.seek(-5, os.SEEK_END)
78
 
            # Make sure we inject a value different than the one we just read
79
 
            if c == '\xFF':
80
 
                corrupt = '\x00'
81
 
            else:
82
 
                corrupt = '\xFF'
83
 
            f.write(corrupt) # make sure we corrupt something
84
 
        self.run_bzr_error(['Corruption while decompressing repository file'], 
85
 
                            'branch a b', retcode=3)
86
 
 
87
60
    def test_branch_switch_no_branch(self):
88
61
        # No branch in the current directory:
89
62
        #  => new branch will be created, but switch fails
205
178
        source.add('file1')
206
179
        source.commit('added file')
207
180
        out, err = self.run_bzr('branch source target --files-from source')
208
 
        self.assertPathExists('target/file1')
 
181
        self.failUnlessExists('target/file1')
209
182
 
210
183
    def test_branch_files_from_hardlink(self):
211
184
        self.requireFeature(HardlinkFeature)
234
207
    def test_branch_no_tree(self):
235
208
        self.example_branch('source')
236
209
        self.run_bzr('branch --no-tree source target')
237
 
        self.assertPathDoesNotExist('target/hello')
238
 
        self.assertPathDoesNotExist('target/goodbye')
 
210
        self.failIfExists('target/hello')
 
211
        self.failIfExists('target/goodbye')
239
212
 
240
213
    def test_branch_into_existing_dir(self):
241
214
        self.example_branch('a')
251
224
        # force operation
252
225
        self.run_bzr('branch a b --use-existing-dir')
253
226
        # check conflicts
254
 
        self.assertPathExists('b/hello.moved')
255
 
        self.assertPathDoesNotExist('b/godbye.moved')
 
227
        self.failUnlessExists('b/hello.moved')
 
228
        self.failIfExists('b/godbye.moved')
256
229
        # we can't branch into branch
257
230
        out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
258
231
        self.assertEqual('', out)
297
270
 
298
271
    def test_branch_fetches_all_tags(self):
299
272
        builder = self.make_branch_builder('source')
300
 
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
273
        builder.build_commit(message="Rev 1", rev_id='rev-1')
 
274
        builder.build_commit(message="Rev 2", rev_id='rev-2')
 
275
        source = builder.get_branch()
301
276
        source.tags.set_tag('tag-a', 'rev-2')
302
 
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
277
        source.set_last_revision_info(1, 'rev-1')
303
278
        # Now source has a tag not in its ancestry.  Make a branch from it.
304
279
        self.run_bzr('branch source new-branch')
305
280
        new_branch = branch.Branch.open('new-branch')
344
319
        # mainline.
345
320
        out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
346
321
        self.assertEqual('', out)
347
 
        self.assertEqual('Branched 2 revisions.\n',
 
322
        self.assertEqual('Branched 2 revision(s).\n',
348
323
            err)
349
324
        # it should have preserved the branch format, and so it should be
350
325
        # capable of supporting stacking, but not actually have a stacked_on
451
426
        # being too low. If rpc_count increases, more network roundtrips have
452
427
        # become necessary for this use case. Please do not adjust this number
453
428
        # upwards without agreement from bzr's network support maintainers.
454
 
        self.assertLength(39, self.hpss_calls)
 
429
        self.assertLength(36, self.hpss_calls)
455
430
 
456
431
    def test_branch_from_trivial_branch_streaming_acceptance(self):
457
432
        self.setup_smart_server_with_call_log()
466
441
        # being too low. If rpc_count increases, more network roundtrips have
467
442
        # become necessary for this use case. Please do not adjust this number
468
443
        # upwards without agreement from bzr's network support maintainers.
469
 
        self.assertLength(10, self.hpss_calls)
 
444
        self.assertLength(9, self.hpss_calls)
470
445
 
471
446
    def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
472
447
        self.setup_smart_server_with_call_log()
486
461
        # being too low. If rpc_count increases, more network roundtrips have
487
462
        # become necessary for this use case. Please do not adjust this number
488
463
        # upwards without agreement from bzr's network support maintainers.
489
 
        self.assertLength(15, self.hpss_calls)
 
464
        self.assertLength(14, self.hpss_calls)
490
465
 
491
466
    def test_branch_from_branch_with_tags(self):
492
467
        self.setup_smart_server_with_call_log()
493
468
        builder = self.make_branch_builder('source')
494
 
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
495
 
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
469
        builder.build_commit(message="Rev 1", rev_id='rev-1')
 
470
        builder.build_commit(message="Rev 2", rev_id='rev-2')
 
471
        source = builder.get_branch()
496
472
        source.tags.set_tag('tag-a', 'rev-2')
497
473
        source.tags.set_tag('tag-missing', 'missing-rev')
 
474
        source.set_last_revision_info(1, 'rev-1')
498
475
        # Now source has a tag not in its ancestry.  Make a branch from it.
499
476
        self.reset_smart_call_log()
500
477
        out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
503
480
        # being too low. If rpc_count increases, more network roundtrips have
504
481
        # become necessary for this use case. Please do not adjust this number
505
482
        # upwards without agreement from bzr's network support maintainers.
506
 
        self.assertLength(10, self.hpss_calls)
507
 
 
508
 
    def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
509
 
        self.setup_smart_server_with_call_log()
510
 
        t = self.make_branch_and_tree('from')
511
 
        for count in range(9):
512
 
            t.commit(message='commit %d' % count)
513
 
        self.reset_smart_call_log()
514
 
        out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
515
 
            'local-target'])
516
 
        # XXX: the number of hpss calls for this case isn't deterministic yet,
517
 
        # so we can't easily assert about the number of calls.
518
 
        #self.assertLength(XXX, self.hpss_calls)
519
 
        # We can assert that none of the calls were readv requests for rix
520
 
        # files, though (demonstrating that at least get_parent_map calls are
521
 
        # not using VFS RPCs).
522
 
        readvs_of_rix_files = [
523
 
            c for c in self.hpss_calls
524
 
            if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
525
 
        self.assertLength(0, readvs_of_rix_files)
 
483
        self.assertLength(9, self.hpss_calls)
526
484
 
527
485
 
528
486
class TestRemoteBranch(TestCaseWithSFTPServer):
548
506
        # Ensure that no working tree what created remotely
549
507
        self.assertFalse(t.has('remote/file'))
550
508
 
551
 
 
552
 
class TestDeprecatedAliases(TestCaseWithTransport):
553
 
 
554
 
    def test_deprecated_aliases(self):
555
 
        """bzr branch can be called clone or get, but those names are deprecated.
556
 
 
557
 
        See bug 506265.
558
 
        """
559
 
        for command in ['clone', 'get']:
560
 
            run_script(self, """
561
 
            $ bzr %(command)s A B
562
 
            2>The command 'bzr %(command)s' has been deprecated in bzr 2.4. Please use 'bzr branch' instead.
563
 
            2>bzr: ERROR: Not a branch...
564
 
            """ % locals())
565
 
 
566
 
 
567
 
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
568
 
 
569
 
    def _checkout_and_branch(self, option=''):
570
 
        self.script_runner.run_script(self, '''
571
 
                $ bzr checkout %(option)s repo/trunk checkout
572
 
                $ cd checkout
573
 
                $ bzr branch --switch ../repo/trunk ../repo/branched
574
 
                2>Branched 0 revisions.
575
 
                2>Tree is up to date at revision 0.
576
 
                2>Switched to branch:...branched...
577
 
                $ cd ..
578
 
                ''' % locals())
579
 
        bound_branch = branch.Branch.open_containing('checkout')[0]
580
 
        master_branch = branch.Branch.open_containing('repo/branched')[0]
581
 
        return (bound_branch, master_branch)
582
 
 
583
 
    def test_branch_switch_parent_lightweight(self):
584
 
        """Lightweight checkout using bzr branch --switch."""
585
 
        bb, mb = self._checkout_and_branch(option='--lightweight')
586
 
        self.assertParent('repo/trunk', bb)
587
 
        self.assertParent('repo/trunk', mb)
588
 
 
589
 
    def test_branch_switch_parent_heavyweight(self):
590
 
        """Heavyweight checkout using bzr branch --switch."""
591
 
        bb, mb = self._checkout_and_branch()
592
 
        self.assertParent('repo/trunk', bb)
593
 
        self.assertParent('repo/trunk', mb)