/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_branch.py

  • Committer: Martin Pool
  • Date: 2011-08-24 09:34:35 UTC
  • mto: (6015.33.12 2.4)
  • mto: This revision was merged to the branch mainline in revision 6233.
  • Revision ID: mbp@canonical.com-20110824093435-h4tckaau084ywpcv
Correction to 'bzr serve' syntax in admin guide (thanks i41)

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
23
23
    branch,
24
24
    bzrdir,
25
25
    errors,
26
 
    repository,
27
26
    revision as _mod_revision,
28
27
    )
29
28
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
30
 
from bzrlib.tests.blackbox import ExternalBase
 
29
from bzrlib.tests import TestCaseWithTransport
31
30
from bzrlib.tests import (
32
 
    KnownFailure,
 
31
    fixtures,
33
32
    HardlinkFeature,
 
33
    script,
34
34
    test_server,
35
35
    )
 
36
from bzrlib.tests.blackbox import test_switch
36
37
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
 
38
from bzrlib.tests.script import run_script
37
39
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
38
40
from bzrlib.workingtree import WorkingTree
39
41
 
40
42
 
41
 
class TestBranch(ExternalBase):
 
43
class TestBranch(TestCaseWithTransport):
42
44
 
43
45
    def example_branch(self, path='.'):
44
46
        tree = self.make_branch_and_tree(path)
59
61
        self.assertFalse(b._transport.has('branch-name'))
60
62
        b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
61
63
 
 
64
    def test_branch_broken_pack(self):
 
65
        """branching with a corrupted pack file."""
 
66
        self.example_branch('a')
 
67
        # add some corruption
 
68
        packs_dir = 'a/.bzr/repository/packs/'
 
69
        fname = packs_dir + os.listdir(packs_dir)[0]
 
70
        with open(fname, 'rb+') as f:
 
71
            # Start from the end of the file to avoid choosing a place bigger
 
72
            # than the file itself.
 
73
            f.seek(-5, os.SEEK_END)
 
74
            c = f.read(1)
 
75
            f.seek(-5, os.SEEK_END)
 
76
            # Make sure we inject a value different than the one we just read
 
77
            if c == '\xFF':
 
78
                corrupt = '\x00'
 
79
            else:
 
80
                corrupt = '\xFF'
 
81
            f.write(corrupt) # make sure we corrupt something
 
82
        self.run_bzr_error(['Corruption while decompressing repository file'], 
 
83
                            'branch a b', retcode=3)
 
84
 
62
85
    def test_branch_switch_no_branch(self):
63
86
        # No branch in the current directory:
64
87
        #  => new branch will be created, but switch fails
174
197
        target_stat = os.stat('target/file1')
175
198
        self.assertEqual(source_stat, target_stat)
176
199
 
 
200
    def test_branch_files_from(self):
 
201
        source = self.make_branch_and_tree('source')
 
202
        self.build_tree(['source/file1'])
 
203
        source.add('file1')
 
204
        source.commit('added file')
 
205
        out, err = self.run_bzr('branch source target --files-from source')
 
206
        self.assertPathExists('target/file1')
 
207
 
 
208
    def test_branch_files_from_hardlink(self):
 
209
        self.requireFeature(HardlinkFeature)
 
210
        source = self.make_branch_and_tree('source')
 
211
        self.build_tree(['source/file1'])
 
212
        source.add('file1')
 
213
        source.commit('added file')
 
214
        source.bzrdir.sprout('second')
 
215
        out, err = self.run_bzr('branch source target --files-from second'
 
216
                                ' --hardlink')
 
217
        source_stat = os.stat('source/file1')
 
218
        second_stat = os.stat('second/file1')
 
219
        target_stat = os.stat('target/file1')
 
220
        self.assertNotEqual(source_stat, target_stat)
 
221
        self.assertEqual(second_stat, target_stat)
 
222
 
177
223
    def test_branch_standalone(self):
178
224
        shared_repo = self.make_repository('repo', shared=True)
179
225
        self.example_branch('source')
186
232
    def test_branch_no_tree(self):
187
233
        self.example_branch('source')
188
234
        self.run_bzr('branch --no-tree source target')
189
 
        self.failIfExists('target/hello')
190
 
        self.failIfExists('target/goodbye')
 
235
        self.assertPathDoesNotExist('target/hello')
 
236
        self.assertPathDoesNotExist('target/goodbye')
191
237
 
192
238
    def test_branch_into_existing_dir(self):
193
239
        self.example_branch('a')
203
249
        # force operation
204
250
        self.run_bzr('branch a b --use-existing-dir')
205
251
        # check conflicts
206
 
        self.failUnlessExists('b/hello.moved')
207
 
        self.failIfExists('b/godbye.moved')
 
252
        self.assertPathExists('b/hello.moved')
 
253
        self.assertPathDoesNotExist('b/godbye.moved')
208
254
        # we can't branch into branch
209
255
        out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
210
256
        self.assertEqual('', out)
247
293
        self.run_bzr('checkout --lightweight a b')
248
294
        self.assertLength(2, calls)
249
295
 
250
 
 
251
 
class TestBranchStacked(ExternalBase):
 
296
    def test_branch_fetches_all_tags(self):
 
297
        builder = self.make_branch_builder('source')
 
298
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
299
        source.tags.set_tag('tag-a', 'rev-2')
 
300
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
301
        # Now source has a tag not in its ancestry.  Make a branch from it.
 
302
        self.run_bzr('branch source new-branch')
 
303
        new_branch = branch.Branch.open('new-branch')
 
304
        # The tag is present, and so is its revision.
 
305
        self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
 
306
        new_branch.repository.get_revision('rev-2')
 
307
 
 
308
 
 
309
class TestBranchStacked(TestCaseWithTransport):
252
310
    """Tests for branch --stacked"""
253
311
 
254
312
    def assertRevisionInRepository(self, repo_path, revid):
376
434
            err)
377
435
 
378
436
 
379
 
class TestSmartServerBranching(ExternalBase):
 
437
class TestSmartServerBranching(TestCaseWithTransport):
380
438
 
381
439
    def test_branch_from_trivial_branch_to_same_server_branch_acceptance(self):
382
440
        self.setup_smart_server_with_call_log()
391
449
        # being too low. If rpc_count increases, more network roundtrips have
392
450
        # become necessary for this use case. Please do not adjust this number
393
451
        # upwards without agreement from bzr's network support maintainers.
394
 
        self.assertLength(38, self.hpss_calls)
 
452
        self.assertLength(37, self.hpss_calls)
395
453
 
396
454
    def test_branch_from_trivial_branch_streaming_acceptance(self):
397
455
        self.setup_smart_server_with_call_log()
428
486
        # upwards without agreement from bzr's network support maintainers.
429
487
        self.assertLength(15, self.hpss_calls)
430
488
 
 
489
    def test_branch_from_branch_with_tags(self):
 
490
        self.setup_smart_server_with_call_log()
 
491
        builder = self.make_branch_builder('source')
 
492
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
493
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
494
        source.tags.set_tag('tag-a', 'rev-2')
 
495
        source.tags.set_tag('tag-missing', 'missing-rev')
 
496
        # Now source has a tag not in its ancestry.  Make a branch from it.
 
497
        self.reset_smart_call_log()
 
498
        out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
 
499
        # This figure represent the amount of work to perform this use case. It
 
500
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
501
        # being too low. If rpc_count increases, more network roundtrips have
 
502
        # become necessary for this use case. Please do not adjust this number
 
503
        # upwards without agreement from bzr's network support maintainers.
 
504
        self.assertLength(10, self.hpss_calls)
 
505
 
 
506
    def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
 
507
        self.setup_smart_server_with_call_log()
 
508
        t = self.make_branch_and_tree('from')
 
509
        for count in range(9):
 
510
            t.commit(message='commit %d' % count)
 
511
        self.reset_smart_call_log()
 
512
        out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
 
513
            'local-target'])
 
514
        # XXX: the number of hpss calls for this case isn't deterministic yet,
 
515
        # so we can't easily assert about the number of calls.
 
516
        #self.assertLength(XXX, self.hpss_calls)
 
517
        # We can assert that none of the calls were readv requests for rix
 
518
        # files, though (demonstrating that at least get_parent_map calls are
 
519
        # not using VFS RPCs).
 
520
        readvs_of_rix_files = [
 
521
            c for c in self.hpss_calls
 
522
            if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
 
523
        self.assertLength(0, readvs_of_rix_files)
 
524
 
431
525
 
432
526
class TestRemoteBranch(TestCaseWithSFTPServer):
433
527
 
452
546
        # Ensure that no working tree what created remotely
453
547
        self.assertFalse(t.has('remote/file'))
454
548
 
 
549
 
 
550
class TestDeprecatedAliases(TestCaseWithTransport):
 
551
 
 
552
    def test_deprecated_aliases(self):
 
553
        """bzr branch can be called clone or get, but those names are deprecated.
 
554
 
 
555
        See bug 506265.
 
556
        """
 
557
        for command in ['clone', 'get']:
 
558
            run_script(self, """
 
559
            $ bzr %(command)s A B
 
560
            2>The command 'bzr %(command)s' has been deprecated in bzr 2.4. Please use 'bzr branch' instead.
 
561
            2>bzr: ERROR: Not a branch...
 
562
            """ % locals())
 
563
 
 
564
 
 
565
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
 
566
 
 
567
    def _checkout_and_branch(self, option=''):
 
568
        self.script_runner.run_script(self, '''
 
569
                $ bzr checkout %(option)s repo/trunk checkout
 
570
                $ cd checkout
 
571
                $ bzr branch --switch ../repo/trunk ../repo/branched
 
572
                2>Branched 0 revision(s).
 
573
                2>Tree is up to date at revision 0.
 
574
                2>Switched to branch:...branched...
 
575
                $ cd ..
 
576
                ''' % locals())
 
577
        bound_branch = branch.Branch.open_containing('checkout')[0]
 
578
        master_branch = branch.Branch.open_containing('repo/branched')[0]
 
579
        return (bound_branch, master_branch)
 
580
 
 
581
    def test_branch_switch_parent_lightweight(self):
 
582
        """Lightweight checkout using bzr branch --switch."""
 
583
        bb, mb = self._checkout_and_branch(option='--lightweight')
 
584
        self.assertParent('repo/trunk', bb)
 
585
        self.assertParent('repo/trunk', mb)
 
586
 
 
587
    def test_branch_switch_parent_heavyweight(self):
 
588
        """Heavyweight checkout using bzr branch --switch."""
 
589
        bb, mb = self._checkout_and_branch()
 
590
        self.assertParent('repo/trunk', bb)
 
591
        self.assertParent('repo/trunk', mb)