/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: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2006-2012 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
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
 
"""Black-box tests for brz branch."""
 
18
"""Black-box tests for bzr branch."""
19
19
 
20
20
import os
21
21
 
22
 
from breezy import (
 
22
from bzrlib import (
23
23
    branch,
 
24
    bzrdir,
24
25
    controldir,
25
26
    errors,
26
27
    revision as _mod_revision,
27
28
    tests,
28
29
    )
29
 
from breezy.bzr import (
30
 
    bzrdir,
31
 
    )
32
 
from breezy.bzr.knitrepo import RepositoryFormatKnit1
33
 
from breezy.tests import (
 
30
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
 
31
from bzrlib.tests import (
34
32
    fixtures,
35
33
    test_server,
36
34
    )
37
 
from breezy.tests.features import (
 
35
from bzrlib.tests.features import (
38
36
    HardlinkFeature,
39
37
    )
40
 
from breezy.tests.blackbox import test_switch
41
 
from breezy.tests.matchers import ContainsNoVfsCalls
42
 
from breezy.tests.test_sftp_transport import TestCaseWithSFTPServer
43
 
from breezy.tests.script import run_script
44
 
from breezy.urlutils import local_path_to_url, strip_trailing_slash
45
 
from breezy.workingtree import WorkingTree
 
38
from bzrlib.tests.blackbox import test_switch
 
39
from bzrlib.tests.matchers import ContainsNoVfsCalls
 
40
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
 
41
from bzrlib.tests.script import run_script
 
42
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
 
43
from bzrlib.workingtree import WorkingTree
46
44
 
47
45
 
48
46
class TestBranch(tests.TestCaseWithTransport):
49
47
 
50
48
    def example_branch(self, path='.', format=None):
51
49
        tree = self.make_branch_and_tree(path, format=format)
52
 
        self.build_tree_contents([(path + '/hello', b'foo')])
 
50
        self.build_tree_contents([(path + '/hello', 'foo')])
53
51
        tree.add('hello')
54
52
        tree.commit(message='setup')
55
 
        self.build_tree_contents([(path + '/goodbye', b'baz')])
 
53
        self.build_tree_contents([(path + '/goodbye', 'baz')])
56
54
        tree.add('goodbye')
57
55
        tree.commit(message='setup')
58
56
        return tree
65
63
        self.run_bzr('branch a c -r 1')
66
64
        # previously was erroneously created by branching
67
65
        self.assertFalse(b._transport.has('branch-name'))
68
 
        b.controldir.open_workingtree().commit(message='foo', allow_pointless=True)
 
66
        b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
69
67
 
70
68
    def test_branch_no_to_location(self):
71
69
        """The to_location is derived from the source branch name."""
73
71
        a = self.example_branch('something/a').branch
74
72
        self.run_bzr('branch something/a')
75
73
        b = branch.Branch.open('a')
76
 
        self.assertEqual(b.last_revision_info(), a.last_revision_info())
 
74
        self.assertEquals(b.last_revision_info(), a.last_revision_info())
77
75
 
78
76
    def test_into_colocated(self):
79
77
        """Branch from a branch into a colocated branch."""
81
79
        out, err = self.run_bzr(
82
80
            'init --format=development-colo file:b,branch=orig')
83
81
        self.assertEqual(
84
 
            """Created a standalone tree (format: development-colo)\n""",
 
82
            """Created a lightweight checkout (format: development-colo)\n""",
85
83
            out)
86
84
        self.assertEqual('', err)
87
85
        out, err = self.run_bzr(
91
89
        out, err = self.run_bzr('branches b')
92
90
        self.assertEqual("  orig\n  thiswasa\n", out)
93
91
        self.assertEqual('', err)
94
 
        out, err = self.run_bzr('branch a file:b,branch=orig', retcode=3)
 
92
        out,err = self.run_bzr('branch a file:b,branch=orig', retcode=3)
95
93
        self.assertEqual('', out)
96
94
        self.assertEqual(
97
 
            'brz: ERROR: Already a branch: "file:b,branch=orig".\n', err)
 
95
            'bzr: ERROR: Already a branch: "file:b,branch=orig".\n', err)
98
96
 
99
97
    def test_from_colocated(self):
100
98
        """Branch from a colocated branch into a regular branch."""
101
99
        tree = self.example_branch('a', format='development-colo')
102
 
        tree.controldir.create_branch(name='somecolo')
 
100
        tree.bzrdir.create_branch(name='somecolo')
103
101
        out, err = self.run_bzr('branch %s,branch=somecolo' %
104
102
            local_path_to_url('a'))
105
103
        self.assertEqual('', out)
169
167
 
170
168
    def test_branch_into_empty_dir(self):
171
169
        t = self.example_branch('source')
172
 
        self.make_controldir('target')
 
170
        self.make_bzrdir('target')
173
171
        self.run_bzr("branch source target")
174
 
        self.assertEqual(2, len(t.branch.repository.all_revision_ids()))
 
172
        self.assertEquals(2, len(t.branch.repository.all_revision_ids()))
175
173
 
176
174
    def test_branch_switch_checkout(self):
177
175
        # Checkout in the current directory:
210
208
        shared_repo.set_make_working_trees(True)
211
209
 
212
210
        def make_shared_tree(path):
213
 
            shared_repo.controldir.root_transport.mkdir(path)
 
211
            shared_repo.bzrdir.root_transport.mkdir(path)
214
212
            controldir.ControlDir.create_branch_convenience('repo/' + path)
215
213
            return WorkingTree.open('repo/' + path)
216
214
        tree_a = make_shared_tree('a')
217
215
        self.build_tree(['repo/a/file'])
218
216
        tree_a.add('file')
219
 
        tree_a.commit('commit a-1', rev_id=b'a-1')
 
217
        tree_a.commit('commit a-1', rev_id='a-1')
220
218
        f = open('repo/a/file', 'ab')
221
219
        f.write('more stuff\n')
222
220
        f.close()
223
 
        tree_a.commit('commit a-2', rev_id=b'a-2')
 
221
        tree_a.commit('commit a-2', rev_id='a-2')
224
222
 
225
223
        tree_b = make_shared_tree('b')
226
224
        self.build_tree(['repo/b/file'])
227
225
        tree_b.add('file')
228
 
        tree_b.commit('commit b-1', rev_id=b'b-1')
 
226
        tree_b.commit('commit b-1', rev_id='b-1')
229
227
 
230
228
        self.assertTrue(shared_repo.has_revision('a-1'))
231
229
        self.assertTrue(shared_repo.has_revision('a-2'))
265
263
        self.build_tree(['source/file1'])
266
264
        source.add('file1')
267
265
        source.commit('added file')
268
 
        source.controldir.sprout('second')
 
266
        source.bzrdir.sprout('second')
269
267
        out, err = self.run_bzr('branch source target --files-from second'
270
268
                                ' --hardlink')
271
269
        source_stat = os.stat('source/file1')
291
289
 
292
290
    def test_branch_into_existing_dir(self):
293
291
        self.example_branch('a')
294
 
        # existing dir with similar files but no .brz dir
 
292
        # existing dir with similar files but no .bzr dir
295
293
        self.build_tree_contents([('b/',)])
296
 
        self.build_tree_contents([('b/hello', b'bar')])  # different content
297
 
        self.build_tree_contents([('b/goodbye', b'baz')])# same content
 
294
        self.build_tree_contents([('b/hello', 'bar')])  # different content
 
295
        self.build_tree_contents([('b/goodbye', 'baz')])# same content
298
296
        # fails without --use-existing-dir
299
 
        out, err = self.run_bzr('branch a b', retcode=3)
 
297
        out,err = self.run_bzr('branch a b', retcode=3)
300
298
        self.assertEqual('', out)
301
 
        self.assertEqual('brz: ERROR: Target directory "b" already exists.\n',
 
299
        self.assertEqual('bzr: ERROR: Target directory "b" already exists.\n',
302
300
            err)
303
301
        # force operation
304
302
        self.run_bzr('branch a b --use-existing-dir')
306
304
        self.assertPathExists('b/hello.moved')
307
305
        self.assertPathDoesNotExist('b/godbye.moved')
308
306
        # we can't branch into branch
309
 
        out, err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
 
307
        out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
310
308
        self.assertEqual('', out)
311
 
        self.assertEqual('brz: ERROR: Already a branch: "b".\n', err)
 
309
        self.assertEqual('bzr: ERROR: Already a branch: "b".\n', err)
312
310
 
313
311
    def test_branch_bind(self):
314
312
        self.example_branch('a')
349
347
 
350
348
    def test_branch_fetches_all_tags(self):
351
349
        builder = self.make_branch_builder('source')
352
 
        source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(builder)
353
 
        source.tags.set_tag('tag-a', rev2)
 
350
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
351
        source.tags.set_tag('tag-a', 'rev-2')
354
352
        source.get_config_stack().set('branch.fetch_tags', True)
355
353
        # Now source has a tag not in its ancestry.  Make a branch from it.
356
354
        self.run_bzr('branch source new-branch')
357
355
        new_branch = branch.Branch.open('new-branch')
358
356
        # The tag is present, and so is its revision.
359
 
        self.assertEqual(rev2, new_branch.tags.lookup_tag('tag-a'))
360
 
        new_branch.repository.get_revision(rev2)
 
357
        self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
 
358
        new_branch.repository.get_revision('rev-2')
361
359
 
362
360
 
363
361
class TestBranchStacked(tests.TestCaseWithTransport):
389
387
            format='1.9')
390
388
        branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
391
389
        # with some work on it
392
 
        work_tree = trunk_tree.branch.controldir.sprout('local').open_workingtree()
 
390
        work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
393
391
        work_tree.commit('moar work plz')
394
392
        work_tree.branch.push(branch_tree.branch)
395
393
        # branching our local branch gives us a new stacked branch pointing at
415
413
            format='1.9')
416
414
        branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
417
415
        # with some work on it
418
 
        work_tree = trunk_tree.branch.controldir.sprout('local').open_workingtree()
 
416
        work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
419
417
        branch_revid = work_tree.commit('moar work plz')
420
418
        work_tree.branch.push(branch_tree.branch)
421
419
        # you can chain branches on from there
531
529
        t = self.make_branch_and_tree('trunk')
532
530
        for count in range(8):
533
531
            t.commit(message='commit %d' % count)
534
 
        tree2 = t.branch.controldir.sprout('feature', stacked=True
 
532
        tree2 = t.branch.bzrdir.sprout('feature', stacked=True
535
533
            ).open_workingtree()
536
 
        local_tree = t.branch.controldir.sprout('local-working').open_workingtree()
 
534
        local_tree = t.branch.bzrdir.sprout('local-working').open_workingtree()
537
535
        local_tree.commit('feature change')
538
536
        local_tree.branch.push(tree2.branch)
539
537
        self.reset_smart_call_log()
551
549
    def test_branch_from_branch_with_tags(self):
552
550
        self.setup_smart_server_with_call_log()
553
551
        builder = self.make_branch_builder('source')
554
 
        source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(builder)
 
552
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
555
553
        source.get_config_stack().set('branch.fetch_tags', True)
556
 
        source.tags.set_tag('tag-a', rev2)
 
554
        source.tags.set_tag('tag-a', 'rev-2')
557
555
        source.tags.set_tag('tag-missing', 'missing-rev')
558
556
        # Now source has a tag not in its ancestry.  Make a branch from it.
559
557
        self.reset_smart_call_log()
595
593
    def setUp(self):
596
594
        super(TestRemoteBranch, self).setUp()
597
595
        tree = self.make_branch_and_tree('branch')
598
 
        self.build_tree_contents([('branch/file', b'file content\n')])
 
596
        self.build_tree_contents([('branch/file', 'file content\n')])
599
597
        tree.add('file')
600
598
        tree.commit('file created')
601
599
 
614
612
        self.assertFalse(t.has('remote/file'))
615
613
 
616
614
 
 
615
class TestDeprecatedAliases(tests.TestCaseWithTransport):
 
616
 
 
617
    def test_deprecated_aliases(self):
 
618
        """bzr branch can be called clone or get, but those names are
 
619
        deprecated.
 
620
 
 
621
        See bug 506265.
 
622
        """
 
623
        for command in ['clone', 'get']:
 
624
            run_script(self, """
 
625
            $ bzr %(command)s A B
 
626
            2>The command 'bzr %(command)s' has been deprecated in bzr 2.4. Please use 'bzr branch' instead.
 
627
            2>bzr: ERROR: Not a branch...
 
628
            """ % locals())
 
629
 
 
630
 
617
631
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
618
632
 
619
633
    def _checkout_and_branch(self, option=''):
620
634
        self.script_runner.run_script(self, '''
621
 
                $ brz checkout %(option)s repo/trunk checkout
 
635
                $ bzr checkout %(option)s repo/trunk checkout
622
636
                $ cd checkout
623
 
                $ brz branch --switch ../repo/trunk ../repo/branched
 
637
                $ bzr branch --switch ../repo/trunk ../repo/branched
624
638
                2>Branched 0 revisions.
625
639
                2>Tree is up to date at revision 0.
626
640
                2>Switched to branch:...branched...
631
645
        return (bound_branch, master_branch)
632
646
 
633
647
    def test_branch_switch_parent_lightweight(self):
634
 
        """Lightweight checkout using brz branch --switch."""
 
648
        """Lightweight checkout using bzr branch --switch."""
635
649
        bb, mb = self._checkout_and_branch(option='--lightweight')
636
650
        self.assertParent('repo/trunk', bb)
637
651
        self.assertParent('repo/trunk', mb)
638
652
 
639
653
    def test_branch_switch_parent_heavyweight(self):
640
 
        """Heavyweight checkout using brz branch --switch."""
 
654
        """Heavyweight checkout using bzr branch --switch."""
641
655
        bb, mb = self._checkout_and_branch()
642
656
        self.assertParent('repo/trunk', bb)
643
657
        self.assertParent('repo/trunk', mb)