/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: Jelmer Vernooij
  • Date: 2011-10-24 19:21:00 UTC
  • mto: This revision was merged to the branch mainline in revision 6232.
  • Revision ID: jelmer@samba.org-20111024192100-tirpujp3ycs1btmh
s/importance/necessity

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,
 
32
    script,
 
33
    test_server,
 
34
    )
 
35
from bzrlib.tests.features import (
33
36
    HardlinkFeature,
34
 
    test_server,
35
37
    )
 
38
from bzrlib.tests.blackbox import test_switch
36
39
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
 
40
from bzrlib.tests.script import run_script
37
41
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
38
42
from bzrlib.workingtree import WorkingTree
39
43
 
40
44
 
41
 
class TestBranch(ExternalBase):
 
45
class TestBranch(TestCaseWithTransport):
42
46
 
43
47
    def example_branch(self, path='.'):
44
48
        tree = self.make_branch_and_tree(path)
59
63
        self.assertFalse(b._transport.has('branch-name'))
60
64
        b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
61
65
 
 
66
    def test_into_colocated(self):
 
67
        """Branch from a branch into a colocated branch."""
 
68
        self.example_branch('a')
 
69
        out, err = self.run_bzr(
 
70
            'init --format=development-colo file:b,branch=orig')
 
71
        self.assertEqual(
 
72
            """Created a standalone tree (format: development-colo)\n""",
 
73
            out)
 
74
        self.assertEqual('', err)
 
75
        out, err = self.run_bzr(
 
76
            'branch --use-existing-dir a file:b,branch=thiswasa')
 
77
        self.assertEqual('', out)
 
78
        self.assertEqual('Branched 2 revisions.\n', err)
 
79
        out, err = self.run_bzr('branches b')
 
80
        self.assertEqual(" orig\n thiswasa\n", out)
 
81
        self.assertEqual('', err)
 
82
 
 
83
    def test_branch_broken_pack(self):
 
84
        """branching with a corrupted pack file."""
 
85
        self.example_branch('a')
 
86
        # add some corruption
 
87
        packs_dir = 'a/.bzr/repository/packs/'
 
88
        fname = packs_dir + os.listdir(packs_dir)[0]
 
89
        with open(fname, 'rb+') as f:
 
90
            # Start from the end of the file to avoid choosing a place bigger
 
91
            # than the file itself.
 
92
            f.seek(-5, os.SEEK_END)
 
93
            c = f.read(1)
 
94
            f.seek(-5, os.SEEK_END)
 
95
            # Make sure we inject a value different than the one we just read
 
96
            if c == '\xFF':
 
97
                corrupt = '\x00'
 
98
            else:
 
99
                corrupt = '\xFF'
 
100
            f.write(corrupt) # make sure we corrupt something
 
101
        self.run_bzr_error(['Corruption while decompressing repository file'], 
 
102
                            'branch a b', retcode=3)
 
103
 
62
104
    def test_branch_switch_no_branch(self):
63
105
        # No branch in the current directory:
64
106
        #  => new branch will be created, but switch fails
174
216
        target_stat = os.stat('target/file1')
175
217
        self.assertEqual(source_stat, target_stat)
176
218
 
 
219
    def test_branch_files_from(self):
 
220
        source = self.make_branch_and_tree('source')
 
221
        self.build_tree(['source/file1'])
 
222
        source.add('file1')
 
223
        source.commit('added file')
 
224
        out, err = self.run_bzr('branch source target --files-from source')
 
225
        self.assertPathExists('target/file1')
 
226
 
 
227
    def test_branch_files_from_hardlink(self):
 
228
        self.requireFeature(HardlinkFeature)
 
229
        source = self.make_branch_and_tree('source')
 
230
        self.build_tree(['source/file1'])
 
231
        source.add('file1')
 
232
        source.commit('added file')
 
233
        source.bzrdir.sprout('second')
 
234
        out, err = self.run_bzr('branch source target --files-from second'
 
235
                                ' --hardlink')
 
236
        source_stat = os.stat('source/file1')
 
237
        second_stat = os.stat('second/file1')
 
238
        target_stat = os.stat('target/file1')
 
239
        self.assertNotEqual(source_stat, target_stat)
 
240
        self.assertEqual(second_stat, target_stat)
 
241
 
177
242
    def test_branch_standalone(self):
178
243
        shared_repo = self.make_repository('repo', shared=True)
179
244
        self.example_branch('source')
186
251
    def test_branch_no_tree(self):
187
252
        self.example_branch('source')
188
253
        self.run_bzr('branch --no-tree source target')
189
 
        self.failIfExists('target/hello')
190
 
        self.failIfExists('target/goodbye')
 
254
        self.assertPathDoesNotExist('target/hello')
 
255
        self.assertPathDoesNotExist('target/goodbye')
191
256
 
192
257
    def test_branch_into_existing_dir(self):
193
258
        self.example_branch('a')
203
268
        # force operation
204
269
        self.run_bzr('branch a b --use-existing-dir')
205
270
        # check conflicts
206
 
        self.failUnlessExists('b/hello.moved')
207
 
        self.failIfExists('b/godbye.moved')
 
271
        self.assertPathExists('b/hello.moved')
 
272
        self.assertPathDoesNotExist('b/godbye.moved')
208
273
        # we can't branch into branch
209
274
        out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
210
275
        self.assertEqual('', out)
247
312
        self.run_bzr('checkout --lightweight a b')
248
313
        self.assertLength(2, calls)
249
314
 
250
 
 
251
 
class TestBranchStacked(ExternalBase):
 
315
    def test_branch_fetches_all_tags(self):
 
316
        builder = self.make_branch_builder('source')
 
317
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
318
        source.tags.set_tag('tag-a', 'rev-2')
 
319
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
320
        # Now source has a tag not in its ancestry.  Make a branch from it.
 
321
        self.run_bzr('branch source new-branch')
 
322
        new_branch = branch.Branch.open('new-branch')
 
323
        # The tag is present, and so is its revision.
 
324
        self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
 
325
        new_branch.repository.get_revision('rev-2')
 
326
 
 
327
 
 
328
class TestBranchStacked(TestCaseWithTransport):
252
329
    """Tests for branch --stacked"""
253
330
 
254
331
    def assertRevisionInRepository(self, repo_path, revid):
284
361
        # mainline.
285
362
        out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
286
363
        self.assertEqual('', out)
287
 
        self.assertEqual('Branched 2 revision(s).\n',
 
364
        self.assertEqual('Branched 2 revisions.\n',
288
365
            err)
289
366
        # it should have preserved the branch format, and so it should be
290
367
        # capable of supporting stacking, but not actually have a stacked_on
376
453
            err)
377
454
 
378
455
 
379
 
class TestSmartServerBranching(ExternalBase):
 
456
class TestSmartServerBranching(TestCaseWithTransport):
380
457
 
381
458
    def test_branch_from_trivial_branch_to_same_server_branch_acceptance(self):
382
459
        self.setup_smart_server_with_call_log()
391
468
        # being too low. If rpc_count increases, more network roundtrips have
392
469
        # become necessary for this use case. Please do not adjust this number
393
470
        # upwards without agreement from bzr's network support maintainers.
394
 
        self.assertLength(38, self.hpss_calls)
 
471
        self.assertLength(39, self.hpss_calls)
395
472
 
396
473
    def test_branch_from_trivial_branch_streaming_acceptance(self):
397
474
        self.setup_smart_server_with_call_log()
428
505
        # upwards without agreement from bzr's network support maintainers.
429
506
        self.assertLength(15, self.hpss_calls)
430
507
 
 
508
    def test_branch_from_branch_with_tags(self):
 
509
        self.setup_smart_server_with_call_log()
 
510
        builder = self.make_branch_builder('source')
 
511
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
512
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
513
        source.tags.set_tag('tag-a', 'rev-2')
 
514
        source.tags.set_tag('tag-missing', 'missing-rev')
 
515
        # Now source has a tag not in its ancestry.  Make a branch from it.
 
516
        self.reset_smart_call_log()
 
517
        out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
 
518
        # This figure represent the amount of work to perform this use case. It
 
519
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
520
        # being too low. If rpc_count increases, more network roundtrips have
 
521
        # become necessary for this use case. Please do not adjust this number
 
522
        # upwards without agreement from bzr's network support maintainers.
 
523
        self.assertLength(10, self.hpss_calls)
 
524
 
 
525
    def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
 
526
        self.setup_smart_server_with_call_log()
 
527
        t = self.make_branch_and_tree('from')
 
528
        for count in range(9):
 
529
            t.commit(message='commit %d' % count)
 
530
        self.reset_smart_call_log()
 
531
        out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
 
532
            'local-target'])
 
533
        # XXX: the number of hpss calls for this case isn't deterministic yet,
 
534
        # so we can't easily assert about the number of calls.
 
535
        #self.assertLength(XXX, self.hpss_calls)
 
536
        # We can assert that none of the calls were readv requests for rix
 
537
        # files, though (demonstrating that at least get_parent_map calls are
 
538
        # not using VFS RPCs).
 
539
        readvs_of_rix_files = [
 
540
            c for c in self.hpss_calls
 
541
            if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
 
542
        self.assertLength(0, readvs_of_rix_files)
 
543
 
431
544
 
432
545
class TestRemoteBranch(TestCaseWithSFTPServer):
433
546
 
452
565
        # Ensure that no working tree what created remotely
453
566
        self.assertFalse(t.has('remote/file'))
454
567
 
 
568
 
 
569
class TestDeprecatedAliases(TestCaseWithTransport):
 
570
 
 
571
    def test_deprecated_aliases(self):
 
572
        """bzr branch can be called clone or get, but those names are deprecated.
 
573
 
 
574
        See bug 506265.
 
575
        """
 
576
        for command in ['clone', 'get']:
 
577
            run_script(self, """
 
578
            $ bzr %(command)s A B
 
579
            2>The command 'bzr %(command)s' has been deprecated in bzr 2.4. Please use 'bzr branch' instead.
 
580
            2>bzr: ERROR: Not a branch...
 
581
            """ % locals())
 
582
 
 
583
 
 
584
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
 
585
 
 
586
    def _checkout_and_branch(self, option=''):
 
587
        self.script_runner.run_script(self, '''
 
588
                $ bzr checkout %(option)s repo/trunk checkout
 
589
                $ cd checkout
 
590
                $ bzr branch --switch ../repo/trunk ../repo/branched
 
591
                2>Branched 0 revisions.
 
592
                2>Tree is up to date at revision 0.
 
593
                2>Switched to branch:...branched...
 
594
                $ cd ..
 
595
                ''' % locals())
 
596
        bound_branch = branch.Branch.open_containing('checkout')[0]
 
597
        master_branch = branch.Branch.open_containing('repo/branched')[0]
 
598
        return (bound_branch, master_branch)
 
599
 
 
600
    def test_branch_switch_parent_lightweight(self):
 
601
        """Lightweight checkout using bzr branch --switch."""
 
602
        bb, mb = self._checkout_and_branch(option='--lightweight')
 
603
        self.assertParent('repo/trunk', bb)
 
604
        self.assertParent('repo/trunk', mb)
 
605
 
 
606
    def test_branch_switch_parent_heavyweight(self):
 
607
        """Heavyweight checkout using bzr branch --switch."""
 
608
        bb, mb = self._checkout_and_branch()
 
609
        self.assertParent('repo/trunk', bb)
 
610
        self.assertParent('repo/trunk', mb)