~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Patch Queue Manager
  • Date: 2011-10-14 16:54:26 UTC
  • mfrom: (6216.1.1 remove-this-file)
  • Revision ID: pqm@pqm.ubuntu.com-20111014165426-tjix4e6idryf1r2z
(jelmer) Remove an accidentally committed .THIS file. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
22
22
from bzrlib import (
23
23
    branch,
24
24
    bzrdir,
 
25
    controldir,
25
26
    errors,
26
 
    repository,
27
27
    revision as _mod_revision,
28
28
    )
29
29
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
30
30
from bzrlib.tests import TestCaseWithTransport
31
31
from bzrlib.tests import (
32
 
    KnownFailure,
 
32
    fixtures,
 
33
    script,
 
34
    test_server,
 
35
    )
 
36
from bzrlib.tests.features import (
33
37
    HardlinkFeature,
34
 
    test_server,
35
38
    )
 
39
from bzrlib.tests.blackbox import test_switch
36
40
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
 
41
from bzrlib.tests.script import run_script
37
42
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
38
43
from bzrlib.workingtree import WorkingTree
39
44
 
59
64
        self.assertFalse(b._transport.has('branch-name'))
60
65
        b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
61
66
 
 
67
    def test_into_colocated(self):
 
68
        """Branch from a branch into a colocated branch."""
 
69
        self.example_branch('a')
 
70
        out, err = self.run_bzr(
 
71
            'init --format=development-colo file:b,branch=orig')
 
72
        self.assertEqual(
 
73
            """Created a standalone tree (format: development-colo)\n""",
 
74
            out)
 
75
        self.assertEqual('', err)
 
76
        out, err = self.run_bzr(
 
77
            'branch --use-existing-dir a file:b,branch=thiswasa')
 
78
        self.assertEqual('', out)
 
79
        self.assertEqual('Branched 2 revisions.\n', err)
 
80
        out, err = self.run_bzr('branches b')
 
81
        self.assertEqual(" orig\n thiswasa\n", out)
 
82
        self.assertEqual('', err)
 
83
 
 
84
    def test_branch_broken_pack(self):
 
85
        """branching with a corrupted pack file."""
 
86
        self.example_branch('a')
 
87
        # add some corruption
 
88
        packs_dir = 'a/.bzr/repository/packs/'
 
89
        fname = packs_dir + os.listdir(packs_dir)[0]
 
90
        with open(fname, 'rb+') as f:
 
91
            # Start from the end of the file to avoid choosing a place bigger
 
92
            # than the file itself.
 
93
            f.seek(-5, os.SEEK_END)
 
94
            c = f.read(1)
 
95
            f.seek(-5, os.SEEK_END)
 
96
            # Make sure we inject a value different than the one we just read
 
97
            if c == '\xFF':
 
98
                corrupt = '\x00'
 
99
            else:
 
100
                corrupt = '\xFF'
 
101
            f.write(corrupt) # make sure we corrupt something
 
102
        self.run_bzr_error(['Corruption while decompressing repository file'], 
 
103
                            'branch a b', retcode=3)
 
104
 
62
105
    def test_branch_switch_no_branch(self):
63
106
        # No branch in the current directory:
64
107
        #  => new branch will be created, but switch fails
134
177
 
135
178
        def make_shared_tree(path):
136
179
            shared_repo.bzrdir.root_transport.mkdir(path)
137
 
            shared_repo.bzrdir.create_branch_convenience('repo/' + path)
 
180
            controldir.ControlDir.create_branch_convenience('repo/' + path)
138
181
            return WorkingTree.open('repo/' + path)
139
182
        tree_a = make_shared_tree('a')
140
183
        self.build_tree(['repo/a/file'])
180
223
        source.add('file1')
181
224
        source.commit('added file')
182
225
        out, err = self.run_bzr('branch source target --files-from source')
183
 
        self.failUnlessExists('target/file1')
 
226
        self.assertPathExists('target/file1')
184
227
 
185
228
    def test_branch_files_from_hardlink(self):
186
229
        self.requireFeature(HardlinkFeature)
209
252
    def test_branch_no_tree(self):
210
253
        self.example_branch('source')
211
254
        self.run_bzr('branch --no-tree source target')
212
 
        self.failIfExists('target/hello')
213
 
        self.failIfExists('target/goodbye')
 
255
        self.assertPathDoesNotExist('target/hello')
 
256
        self.assertPathDoesNotExist('target/goodbye')
214
257
 
215
258
    def test_branch_into_existing_dir(self):
216
259
        self.example_branch('a')
226
269
        # force operation
227
270
        self.run_bzr('branch a b --use-existing-dir')
228
271
        # check conflicts
229
 
        self.failUnlessExists('b/hello.moved')
230
 
        self.failIfExists('b/godbye.moved')
 
272
        self.assertPathExists('b/hello.moved')
 
273
        self.assertPathDoesNotExist('b/godbye.moved')
231
274
        # we can't branch into branch
232
275
        out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
233
276
        self.assertEqual('', out)
270
313
        self.run_bzr('checkout --lightweight a b')
271
314
        self.assertLength(2, calls)
272
315
 
 
316
    def test_branch_fetches_all_tags(self):
 
317
        builder = self.make_branch_builder('source')
 
318
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
319
        source.tags.set_tag('tag-a', 'rev-2')
 
320
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
321
        # Now source has a tag not in its ancestry.  Make a branch from it.
 
322
        self.run_bzr('branch source new-branch')
 
323
        new_branch = branch.Branch.open('new-branch')
 
324
        # The tag is present, and so is its revision.
 
325
        self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
 
326
        new_branch.repository.get_revision('rev-2')
 
327
 
273
328
 
274
329
class TestBranchStacked(TestCaseWithTransport):
275
330
    """Tests for branch --stacked"""
307
362
        # mainline.
308
363
        out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
309
364
        self.assertEqual('', out)
310
 
        self.assertEqual('Branched 2 revision(s).\n',
 
365
        self.assertEqual('Branched 2 revisions.\n',
311
366
            err)
312
367
        # it should have preserved the branch format, and so it should be
313
368
        # capable of supporting stacking, but not actually have a stacked_on
414
469
        # being too low. If rpc_count increases, more network roundtrips have
415
470
        # become necessary for this use case. Please do not adjust this number
416
471
        # upwards without agreement from bzr's network support maintainers.
417
 
        self.assertLength(38, self.hpss_calls)
 
472
        self.assertLength(39, self.hpss_calls)
418
473
 
419
474
    def test_branch_from_trivial_branch_streaming_acceptance(self):
420
475
        self.setup_smart_server_with_call_log()
451
506
        # upwards without agreement from bzr's network support maintainers.
452
507
        self.assertLength(15, self.hpss_calls)
453
508
 
 
509
    def test_branch_from_branch_with_tags(self):
 
510
        self.setup_smart_server_with_call_log()
 
511
        builder = self.make_branch_builder('source')
 
512
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
513
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
514
        source.tags.set_tag('tag-a', 'rev-2')
 
515
        source.tags.set_tag('tag-missing', 'missing-rev')
 
516
        # Now source has a tag not in its ancestry.  Make a branch from it.
 
517
        self.reset_smart_call_log()
 
518
        out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
 
519
        # This figure represent the amount of work to perform this use case. It
 
520
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
521
        # being too low. If rpc_count increases, more network roundtrips have
 
522
        # become necessary for this use case. Please do not adjust this number
 
523
        # upwards without agreement from bzr's network support maintainers.
 
524
        self.assertLength(10, self.hpss_calls)
 
525
 
 
526
    def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
 
527
        self.setup_smart_server_with_call_log()
 
528
        t = self.make_branch_and_tree('from')
 
529
        for count in range(9):
 
530
            t.commit(message='commit %d' % count)
 
531
        self.reset_smart_call_log()
 
532
        out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
 
533
            'local-target'])
 
534
        # XXX: the number of hpss calls for this case isn't deterministic yet,
 
535
        # so we can't easily assert about the number of calls.
 
536
        #self.assertLength(XXX, self.hpss_calls)
 
537
        # We can assert that none of the calls were readv requests for rix
 
538
        # files, though (demonstrating that at least get_parent_map calls are
 
539
        # not using VFS RPCs).
 
540
        readvs_of_rix_files = [
 
541
            c for c in self.hpss_calls
 
542
            if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
 
543
        self.assertLength(0, readvs_of_rix_files)
 
544
 
454
545
 
455
546
class TestRemoteBranch(TestCaseWithSFTPServer):
456
547
 
475
566
        # Ensure that no working tree what created remotely
476
567
        self.assertFalse(t.has('remote/file'))
477
568
 
 
569
 
 
570
class TestDeprecatedAliases(TestCaseWithTransport):
 
571
 
 
572
    def test_deprecated_aliases(self):
 
573
        """bzr branch can be called clone or get, but those names are deprecated.
 
574
 
 
575
        See bug 506265.
 
576
        """
 
577
        for command in ['clone', 'get']:
 
578
            run_script(self, """
 
579
            $ bzr %(command)s A B
 
580
            2>The command 'bzr %(command)s' has been deprecated in bzr 2.4. Please use 'bzr branch' instead.
 
581
            2>bzr: ERROR: Not a branch...
 
582
            """ % locals())
 
583
 
 
584
 
 
585
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
 
586
 
 
587
    def _checkout_and_branch(self, option=''):
 
588
        self.script_runner.run_script(self, '''
 
589
                $ bzr checkout %(option)s repo/trunk checkout
 
590
                $ cd checkout
 
591
                $ bzr branch --switch ../repo/trunk ../repo/branched
 
592
                2>Branched 0 revisions.
 
593
                2>Tree is up to date at revision 0.
 
594
                2>Switched to branch:...branched...
 
595
                $ cd ..
 
596
                ''' % locals())
 
597
        bound_branch = branch.Branch.open_containing('checkout')[0]
 
598
        master_branch = branch.Branch.open_containing('repo/branched')[0]
 
599
        return (bound_branch, master_branch)
 
600
 
 
601
    def test_branch_switch_parent_lightweight(self):
 
602
        """Lightweight checkout using bzr branch --switch."""
 
603
        bb, mb = self._checkout_and_branch(option='--lightweight')
 
604
        self.assertParent('repo/trunk', bb)
 
605
        self.assertParent('repo/trunk', mb)
 
606
 
 
607
    def test_branch_switch_parent_heavyweight(self):
 
608
        """Heavyweight checkout using bzr branch --switch."""
 
609
        bb, mb = self._checkout_and_branch()
 
610
        self.assertParent('repo/trunk', bb)
 
611
        self.assertParent('repo/trunk', mb)