~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2011-10-06 00:14:01 UTC
  • mto: This revision was merged to the branch mainline in revision 6216.
  • Revision ID: jelmer@samba.org-20111006001401-o14rsyp6gdy5vt3o
Fix plugin use of revision_history.

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_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
 
62
87
    def test_branch_switch_no_branch(self):
63
88
        # No branch in the current directory:
64
89
        #  => new branch will be created, but switch fails
174
199
        target_stat = os.stat('target/file1')
175
200
        self.assertEqual(source_stat, target_stat)
176
201
 
 
202
    def test_branch_files_from(self):
 
203
        source = self.make_branch_and_tree('source')
 
204
        self.build_tree(['source/file1'])
 
205
        source.add('file1')
 
206
        source.commit('added file')
 
207
        out, err = self.run_bzr('branch source target --files-from source')
 
208
        self.assertPathExists('target/file1')
 
209
 
 
210
    def test_branch_files_from_hardlink(self):
 
211
        self.requireFeature(HardlinkFeature)
 
212
        source = self.make_branch_and_tree('source')
 
213
        self.build_tree(['source/file1'])
 
214
        source.add('file1')
 
215
        source.commit('added file')
 
216
        source.bzrdir.sprout('second')
 
217
        out, err = self.run_bzr('branch source target --files-from second'
 
218
                                ' --hardlink')
 
219
        source_stat = os.stat('source/file1')
 
220
        second_stat = os.stat('second/file1')
 
221
        target_stat = os.stat('target/file1')
 
222
        self.assertNotEqual(source_stat, target_stat)
 
223
        self.assertEqual(second_stat, target_stat)
 
224
 
177
225
    def test_branch_standalone(self):
178
226
        shared_repo = self.make_repository('repo', shared=True)
179
227
        self.example_branch('source')
186
234
    def test_branch_no_tree(self):
187
235
        self.example_branch('source')
188
236
        self.run_bzr('branch --no-tree source target')
189
 
        self.failIfExists('target/hello')
190
 
        self.failIfExists('target/goodbye')
 
237
        self.assertPathDoesNotExist('target/hello')
 
238
        self.assertPathDoesNotExist('target/goodbye')
191
239
 
192
240
    def test_branch_into_existing_dir(self):
193
241
        self.example_branch('a')
203
251
        # force operation
204
252
        self.run_bzr('branch a b --use-existing-dir')
205
253
        # check conflicts
206
 
        self.failUnlessExists('b/hello.moved')
207
 
        self.failIfExists('b/godbye.moved')
 
254
        self.assertPathExists('b/hello.moved')
 
255
        self.assertPathDoesNotExist('b/godbye.moved')
208
256
        # we can't branch into branch
209
257
        out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
210
258
        self.assertEqual('', out)
247
295
        self.run_bzr('checkout --lightweight a b')
248
296
        self.assertLength(2, calls)
249
297
 
250
 
 
251
 
class TestBranchStacked(ExternalBase):
 
298
    def test_branch_fetches_all_tags(self):
 
299
        builder = self.make_branch_builder('source')
 
300
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
301
        source.tags.set_tag('tag-a', 'rev-2')
 
302
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
303
        # Now source has a tag not in its ancestry.  Make a branch from it.
 
304
        self.run_bzr('branch source new-branch')
 
305
        new_branch = branch.Branch.open('new-branch')
 
306
        # The tag is present, and so is its revision.
 
307
        self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
 
308
        new_branch.repository.get_revision('rev-2')
 
309
 
 
310
 
 
311
class TestBranchStacked(TestCaseWithTransport):
252
312
    """Tests for branch --stacked"""
253
313
 
254
314
    def assertRevisionInRepository(self, repo_path, revid):
284
344
        # mainline.
285
345
        out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
286
346
        self.assertEqual('', out)
287
 
        self.assertEqual('Branched 2 revision(s).\n',
 
347
        self.assertEqual('Branched 2 revisions.\n',
288
348
            err)
289
349
        # it should have preserved the branch format, and so it should be
290
350
        # capable of supporting stacking, but not actually have a stacked_on
376
436
            err)
377
437
 
378
438
 
379
 
class TestSmartServerBranching(ExternalBase):
 
439
class TestSmartServerBranching(TestCaseWithTransport):
380
440
 
381
441
    def test_branch_from_trivial_branch_to_same_server_branch_acceptance(self):
382
442
        self.setup_smart_server_with_call_log()
391
451
        # being too low. If rpc_count increases, more network roundtrips have
392
452
        # become necessary for this use case. Please do not adjust this number
393
453
        # upwards without agreement from bzr's network support maintainers.
394
 
        self.assertLength(38, self.hpss_calls)
 
454
        self.assertLength(39, self.hpss_calls)
395
455
 
396
456
    def test_branch_from_trivial_branch_streaming_acceptance(self):
397
457
        self.setup_smart_server_with_call_log()
428
488
        # upwards without agreement from bzr's network support maintainers.
429
489
        self.assertLength(15, self.hpss_calls)
430
490
 
 
491
    def test_branch_from_branch_with_tags(self):
 
492
        self.setup_smart_server_with_call_log()
 
493
        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')
 
496
        source.tags.set_tag('tag-a', 'rev-2')
 
497
        source.tags.set_tag('tag-missing', 'missing-rev')
 
498
        # Now source has a tag not in its ancestry.  Make a branch from it.
 
499
        self.reset_smart_call_log()
 
500
        out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
 
501
        # This figure represent the amount of work to perform this use case. It
 
502
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
503
        # being too low. If rpc_count increases, more network roundtrips have
 
504
        # become necessary for this use case. Please do not adjust this number
 
505
        # 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)
 
526
 
431
527
 
432
528
class TestRemoteBranch(TestCaseWithSFTPServer):
433
529
 
452
548
        # Ensure that no working tree what created remotely
453
549
        self.assertFalse(t.has('remote/file'))
454
550
 
 
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)