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

  • Committer: Martin Pool
  • Date: 2007-02-21 05:34:56 UTC
  • mfrom: (2296 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2309.
  • Revision ID: mbp@sourcefrog.net-20070221053456-vyr6o0ehqnbetrvb
merge trunk, in particular new Branch6 changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
from StringIO import StringIO
26
26
 
 
27
from bzrlib import (
 
28
    branch as _mod_branch,
 
29
    bzrdir,
 
30
    errors,
 
31
    urlutils,
 
32
    )
27
33
import bzrlib.branch
28
34
from bzrlib.branch import (BzrBranch5, 
29
35
                           BzrBranchFormat5)
30
 
import bzrlib.bzrdir as bzrdir
31
36
from bzrlib.bzrdir import (BzrDirMetaFormat1, BzrDirMeta1, 
32
37
                           BzrDir, BzrDirFormat)
33
38
from bzrlib.errors import (NotBranchError,
77
82
        finally:
78
83
            branch.unlock()
79
84
 
 
85
    def test_set_push_location(self):
 
86
        from bzrlib.config import (locations_config_filename,
 
87
                                   ensure_config_dir_exists)
 
88
        ensure_config_dir_exists()
 
89
        fn = locations_config_filename()
 
90
        branch = self.make_branch('.', format='knit')
 
91
        branch.set_push_location('foo')
 
92
        local_path = urlutils.local_path_from_url(branch.base[:-1])
 
93
        self.assertFileEqual("[%s]\n"
 
94
                             "push_location = foo\n"
 
95
                             "push_location:policy = norecurse" % local_path,
 
96
                             fn)
 
97
 
 
98
    # TODO RBC 20051029 test getting a push location from a branch in a
 
99
    # recursive section - that is, it appends the branch name.
 
100
 
80
101
 
81
102
class SampleBranchFormat(bzrlib.branch.BranchFormat):
82
103
    """A sample format
141
162
        bzrlib.branch.BranchFormat.register_format(format)
142
163
        # which branch.Open will refuse (not supported)
143
164
        self.assertRaises(UnsupportedFormatError, bzrlib.branch.Branch.open, self.get_url())
 
165
        self.make_branch_and_tree('foo')
144
166
        # but open_downlevel will work
145
167
        self.assertEqual(format.open(dir), bzrdir.BzrDir.open(self.get_url()).open_branch(unsupported=True))
146
168
        # unregister the format
147
169
        bzrlib.branch.BranchFormat.unregister_format(format)
 
170
        self.make_branch_and_tree('bar')
 
171
 
 
172
    def test_checkout_format(self):
 
173
        branch = self.make_repository('repository', shared=True)
 
174
        branch = self.make_branch('repository/branch',
 
175
            format='metaweave')
 
176
        tree = branch.create_checkout('checkout')
 
177
        self.assertIs(tree.branch.__class__, _mod_branch.BzrBranch5)
 
178
 
 
179
 
 
180
class TestBranch6(TestCaseWithTransport):
 
181
 
 
182
    def test_creation(self):
 
183
        format = BzrDirMetaFormat1()
 
184
        format.set_branch_format(_mod_branch.BzrBranchFormat6())
 
185
        branch = self.make_branch('a', format=format)
 
186
        self.assertIsInstance(branch, _mod_branch.BzrBranch6)
 
187
        branch = self.make_branch('b', format='experimental-branch6')
 
188
        self.assertIsInstance(branch, _mod_branch.BzrBranch6)
 
189
        branch = _mod_branch.Branch.open('a')
 
190
        self.assertIsInstance(branch, _mod_branch.BzrBranch6)
 
191
 
 
192
    def test_layout(self):
 
193
        branch = self.make_branch('a', format='experimental-branch6')
 
194
        self.failUnlessExists('a/.bzr/branch/last-revision')
 
195
        self.failIfExists('a/.bzr/branch/revision-history')
 
196
 
 
197
    def test_config(self):
 
198
        """Ensure that all configuration data is stored in the branch"""
 
199
        branch = self.make_branch('a', format='experimental-branch6')
 
200
        branch.set_parent('http://bazaar-vcs.org')
 
201
        self.failIfExists('a/.bzr/branch/parent')
 
202
        self.assertEqual('http://bazaar-vcs.org', branch.get_parent())
 
203
        branch.set_push_location('sftp://bazaar-vcs.org')
 
204
        config = branch.get_config()._get_branch_data_config()
 
205
        self.assertEqual('sftp://bazaar-vcs.org',
 
206
                         config.get_user_option('push_location'))
 
207
        branch.set_bound_location('ftp://bazaar-vcs.org')
 
208
        self.failIfExists('a/.bzr/branch/bound')
 
209
        self.assertEqual('ftp://bazaar-vcs.org', branch.get_bound_location())
 
210
 
 
211
    def test_set_revision_history(self):
 
212
        tree = self.make_branch_and_memory_tree('.',
 
213
            format='experimental-branch6')
 
214
        tree.lock_write()
 
215
        try:
 
216
            tree.add('.')
 
217
            tree.commit('foo', rev_id='foo')
 
218
            tree.commit('bar', rev_id='bar')
 
219
            tree.branch.set_revision_history(['foo', 'bar'])
 
220
            tree.branch.set_revision_history(['foo'])
 
221
            self.assertRaises(errors.NotLefthandHistory,
 
222
                              tree.branch.set_revision_history, ['bar'])
 
223
        finally:
 
224
            tree.unlock()
 
225
 
 
226
    def test_append_revision(self):
 
227
        tree = self.make_branch_and_tree('branch1',
 
228
            format='experimental-branch6')
 
229
        tree.lock_write()
 
230
        try:
 
231
            tree.add('.')
 
232
            tree.commit('foo', rev_id='foo')
 
233
            tree.commit('bar', rev_id='bar')
 
234
            tree.commit('baz', rev_id='baz')
 
235
            tree.set_last_revision('bar')
 
236
            tree.branch.set_last_revision_info(2, 'bar')
 
237
            tree.commit('qux', rev_id='qux')
 
238
            tree.add_parent_tree_id('baz')
 
239
            tree.commit('qux', rev_id='quxx')
 
240
            tree.branch.set_last_revision_info(0, 'null:')
 
241
            self.assertRaises(errors.NotLeftParentDescendant,
 
242
                              tree.branch.append_revision, 'bar')
 
243
            tree.branch.append_revision('foo')
 
244
            self.assertRaises(errors.NotLeftParentDescendant,
 
245
                              tree.branch.append_revision, 'baz')
 
246
            tree.branch.append_revision('bar')
 
247
            tree.branch.append_revision('baz')
 
248
            self.assertRaises(errors.NotLeftParentDescendant,
 
249
                              tree.branch.append_revision, 'quxx')
 
250
        finally:
 
251
            tree.unlock()
148
252
 
149
253
 
150
254
class TestBranchReference(TestCaseWithTransport):