~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2010-07-29 11:17:57 UTC
  • mfrom: (5050.3.17 2.2)
  • mto: This revision was merged to the branch mainline in revision 5365.
  • Revision ID: andrew.bennetts@canonical.com-20100729111757-018h3pcefo7z0dnq
Merge lp:bzr/2.2 into lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2010 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,
26
25
    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
 
    fixtures,
33
 
    script,
 
32
    KnownFailure,
 
33
    HardlinkFeature,
34
34
    test_server,
35
35
    )
36
 
from bzrlib.tests.features import (
37
 
    HardlinkFeature,
38
 
    )
39
 
from bzrlib.tests.blackbox import test_switch
40
36
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
41
 
from bzrlib.tests.script import run_script
42
37
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
43
38
from bzrlib.workingtree import WorkingTree
44
39
 
64
59
        self.assertFalse(b._transport.has('branch-name'))
65
60
        b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
66
61
 
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
 
 
105
62
    def test_branch_switch_no_branch(self):
106
63
        # No branch in the current directory:
107
64
        #  => new branch will be created, but switch fails
177
134
 
178
135
        def make_shared_tree(path):
179
136
            shared_repo.bzrdir.root_transport.mkdir(path)
180
 
            controldir.ControlDir.create_branch_convenience('repo/' + path)
 
137
            shared_repo.bzrdir.create_branch_convenience('repo/' + path)
181
138
            return WorkingTree.open('repo/' + path)
182
139
        tree_a = make_shared_tree('a')
183
140
        self.build_tree(['repo/a/file'])
223
180
        source.add('file1')
224
181
        source.commit('added file')
225
182
        out, err = self.run_bzr('branch source target --files-from source')
226
 
        self.assertPathExists('target/file1')
 
183
        self.failUnlessExists('target/file1')
227
184
 
228
185
    def test_branch_files_from_hardlink(self):
229
186
        self.requireFeature(HardlinkFeature)
252
209
    def test_branch_no_tree(self):
253
210
        self.example_branch('source')
254
211
        self.run_bzr('branch --no-tree source target')
255
 
        self.assertPathDoesNotExist('target/hello')
256
 
        self.assertPathDoesNotExist('target/goodbye')
 
212
        self.failIfExists('target/hello')
 
213
        self.failIfExists('target/goodbye')
257
214
 
258
215
    def test_branch_into_existing_dir(self):
259
216
        self.example_branch('a')
269
226
        # force operation
270
227
        self.run_bzr('branch a b --use-existing-dir')
271
228
        # check conflicts
272
 
        self.assertPathExists('b/hello.moved')
273
 
        self.assertPathDoesNotExist('b/godbye.moved')
 
229
        self.failUnlessExists('b/hello.moved')
 
230
        self.failIfExists('b/godbye.moved')
274
231
        # we can't branch into branch
275
232
        out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
276
233
        self.assertEqual('', out)
313
270
        self.run_bzr('checkout --lightweight a b')
314
271
        self.assertLength(2, calls)
315
272
 
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
 
 
328
273
 
329
274
class TestBranchStacked(TestCaseWithTransport):
330
275
    """Tests for branch --stacked"""
362
307
        # mainline.
363
308
        out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
364
309
        self.assertEqual('', out)
365
 
        self.assertEqual('Branched 2 revisions.\n',
 
310
        self.assertEqual('Branched 2 revision(s).\n',
366
311
            err)
367
312
        # it should have preserved the branch format, and so it should be
368
313
        # capable of supporting stacking, but not actually have a stacked_on
469
414
        # being too low. If rpc_count increases, more network roundtrips have
470
415
        # become necessary for this use case. Please do not adjust this number
471
416
        # upwards without agreement from bzr's network support maintainers.
472
 
        self.assertLength(39, self.hpss_calls)
 
417
        self.assertLength(38, self.hpss_calls)
473
418
 
474
419
    def test_branch_from_trivial_branch_streaming_acceptance(self):
475
420
        self.setup_smart_server_with_call_log()
506
451
        # upwards without agreement from bzr's network support maintainers.
507
452
        self.assertLength(15, self.hpss_calls)
508
453
 
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
 
 
545
454
 
546
455
class TestRemoteBranch(TestCaseWithSFTPServer):
547
456
 
566
475
        # Ensure that no working tree what created remotely
567
476
        self.assertFalse(t.has('remote/file'))
568
477
 
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)