~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branchbuilder.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-09-02 06:24:16 UTC
  • mfrom: (3635.1.3 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20080902062416-dxdxccqki90bcynl
(robertc) Fix repack operations on SMB connections. (Robert Collins,
        bug 255656).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2011 Canonical Ltd
 
1
# Copyright (C) 2007 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Tests for the BranchBuilder class."""
18
18
 
19
19
from bzrlib import (
20
20
    branch as _mod_branch,
 
21
    errors,
21
22
    revision as _mod_revision,
22
23
    tests,
23
24
    )
25
26
 
26
27
 
27
28
class TestBranchBuilder(tests.TestCaseWithMemoryTransport):
28
 
 
 
29
    
29
30
    def test_create(self):
30
31
        """Test the constructor api."""
31
32
        builder = BranchBuilder(self.get_transport().clone('foo'))
58
59
            'commit 1',
59
60
            branch.repository.get_revision(branch.last_revision()).message)
60
61
 
61
 
    def test_build_commit_timestamp(self):
62
 
        """You can set a date when committing."""
63
 
        builder = self.make_branch_builder('foo')
64
 
        rev_id = builder.build_commit(timestamp=1236043340)
65
 
        branch = builder.get_branch()
66
 
        self.assertEqual((1, rev_id), branch.last_revision_info())
67
 
        rev = branch.repository.get_revision(branch.last_revision())
68
 
        self.assertEqual(
69
 
            'commit 1',
70
 
            rev.message)
71
 
        self.assertEqual(
72
 
            1236043340,
73
 
            int(rev.timestamp))
74
 
 
75
62
    def test_build_two_commits(self):
76
63
        """The second commit has the right parents and message."""
77
64
        builder = BranchBuilder(self.get_transport().clone('foo'))
86
73
            [rev_id1],
87
74
            branch.repository.get_revision(branch.last_revision()).parent_ids)
88
75
 
89
 
    def test_build_commit_parent_ids(self):
90
 
        """build_commit() takes a parent_ids argument."""
91
 
        builder = BranchBuilder(self.get_transport().clone('foo'))
92
 
        rev_id1 = builder.build_commit(
93
 
            parent_ids=["ghost"], allow_leftmost_as_ghost=True)
94
 
        rev_id2 = builder.build_commit(parent_ids=[])
95
 
        branch = builder.get_branch()
96
 
        self.assertEqual((1, rev_id2), branch.last_revision_info())
97
 
        self.assertEqual(
98
 
            ["ghost"],
99
 
            branch.repository.get_revision(rev_id1).parent_ids)
100
 
 
101
76
 
102
77
class TestBranchBuilderBuildSnapshot(tests.TestCaseWithMemoryTransport):
103
78
 
155
130
                              (u'b', 'b-id', 'directory'),
156
131
                             ], rev_tree)
157
132
 
158
 
    def test_commit_timestamp(self):
159
 
        builder = self.make_branch_builder('foo')
160
 
        rev_id = builder.build_snapshot(None, None,
161
 
            [('add', (u'', None, 'directory', None))],
162
 
            timestamp=1234567890)
163
 
        rev = builder.get_branch().repository.get_revision(rev_id)
164
 
        self.assertEqual(
165
 
            1234567890,
166
 
            int(rev.timestamp))
167
 
 
168
133
    def test_commit_message_default(self):
169
134
        builder = BranchBuilder(self.get_transport().clone('foo'))
170
135
        rev_id = builder.build_snapshot(None, None,
182
147
        rev = branch.repository.get_revision(rev_id)
183
148
        self.assertEqual(u'Foo', rev.message)
184
149
 
185
 
    def test_commit_message_callback(self):
186
 
        builder = BranchBuilder(self.get_transport().clone('foo'))
187
 
        rev_id = builder.build_snapshot(None, None,
188
 
            [('add', (u'', None, 'directory', None))],
189
 
            message_callback=lambda x:u'Foo')
190
 
        branch = builder.get_branch()
191
 
        rev = branch.repository.get_revision(rev_id)
192
 
        self.assertEqual(u'Foo', rev.message)
193
 
 
194
150
    def test_modify_file(self):
195
151
        builder = self.build_a_rev()
196
152
        rev_id2 = builder.build_snapshot('B-id', None,
241
197
            builder.build_snapshot, 'B-id', None, [('weirdo', ('foo',))])
242
198
        self.assertEqual('Unknown build action: "weirdo"', str(e))
243
199
 
244
 
    def test_rename(self):
245
 
        builder = self.build_a_rev()
246
 
        builder.build_snapshot('B-id', None,
247
 
            [('rename', ('a', 'b'))])
248
 
        rev_tree = builder.get_branch().repository.revision_tree('B-id')
249
 
        self.assertTreeShape([(u'', 'a-root-id', 'directory'),
250
 
                              (u'b', 'a-id', 'file')], rev_tree)
251
 
 
252
 
    def test_rename_into_subdir(self):
253
 
        builder = self.build_a_rev()
254
 
        builder.build_snapshot('B-id', None,
255
 
            [('add', ('dir', 'dir-id', 'directory', None)),
256
 
             ('rename', ('a', 'dir/a'))])
257
 
        rev_tree = builder.get_branch().repository.revision_tree('B-id')
258
 
        self.assertTreeShape([(u'', 'a-root-id', 'directory'),
259
 
                              (u'dir', 'dir-id', 'directory'),
260
 
                              (u'dir/a', 'a-id', 'file')], rev_tree)
261
 
 
262
 
    def test_rename_out_of_unversioned_subdir(self):
263
 
        builder = self.build_a_rev()
264
 
        builder.build_snapshot('B-id', None,
265
 
            [('add', ('dir', 'dir-id', 'directory', None)),
266
 
             ('rename', ('a', 'dir/a'))])
267
 
        builder.build_snapshot('C-id', None,
268
 
            [('rename', ('dir/a', 'a')),
269
 
             ('unversion', 'dir-id')])
270
 
        rev_tree = builder.get_branch().repository.revision_tree('C-id')
271
 
        self.assertTreeShape([(u'', 'a-root-id', 'directory'),
272
 
                              (u'a', 'a-id', 'file')], rev_tree)
 
200
    # TODO: rename a file/directory, but rename isn't supported by the
 
201
    #       MemoryTree api yet, so for now we wait until it is used
273
202
 
274
203
    def test_set_parent(self):
275
204
        builder = self.build_a_rev()
277
206
        self.addCleanup(builder.finish_series)
278
207
        builder.build_snapshot('B-id', ['A-id'],
279
208
            [('modify', ('a-id', 'new\ncontent\n'))])
280
 
        builder.build_snapshot('C-id', ['A-id'],
 
209
        builder.build_snapshot('C-id', ['A-id'], 
281
210
            [('add', ('c', 'c-id', 'file', 'alt\ncontent\n'))])
282
211
        # We should now have a graph:
283
212
        #   A
345
274
                             ], d_tree)
346
275
        # Because we copied the exact text into *this* tree, the 'c' file
347
276
        # should look like it was not modified in the merge
348
 
        self.assertEqual('C-id', d_tree.get_file_revision('c-id'))
349
 
 
350
 
    def test_set_parent_to_null(self):
351
 
        builder = self.build_a_rev()
352
 
        builder.start_series()
353
 
        self.addCleanup(builder.finish_series)
354
 
        builder.build_snapshot('B-id', [],
355
 
            [('add', ('', None, 'directory', None))])
356
 
        # We should now have a graph:
357
 
        #   A B
358
 
        # And not A => B
359
 
        repo = builder.get_branch().repository
360
 
        self.assertEqual({'A-id': (_mod_revision.NULL_REVISION,),
361
 
                          'B-id': (_mod_revision.NULL_REVISION,),},
362
 
                         repo.get_parent_map(['A-id', 'B-id']))
363
 
 
364
 
    
 
277
        self.assertEqual('C-id', d_tree.inventory['c-id'].revision)
 
278
 
365
279
    def test_start_finish_series(self):
366
280
        builder = BranchBuilder(self.get_transport().clone('foo'))
367
281
        builder.start_series()
373
287
            builder.finish_series()
374
288
        self.assertIs(None, builder._tree)
375
289
        self.assertFalse(builder._branch.is_locked())
376
 
 
377
 
    def test_ghost_mainline_history(self):
378
 
        builder = BranchBuilder(self.get_transport().clone('foo'))
379
 
        builder.start_series()
380
 
        try:
381
 
            builder.build_snapshot('tip', ['ghost'],
382
 
                [('add', ('', 'ROOT_ID', 'directory', ''))],
383
 
                allow_leftmost_as_ghost=True)
384
 
        finally:
385
 
            builder.finish_series()
386
 
        b = builder.get_branch()
387
 
        b.lock_read()
388
 
        self.addCleanup(b.unlock)
389
 
        self.assertEqual(('ghost',),
390
 
            b.repository.get_graph().get_parent_map(['tip'])['tip'])
391
 
 
392
 
    def test_unversion_root_add_new_root(self):
393
 
        builder = BranchBuilder(self.get_transport().clone('foo'))
394
 
        builder.start_series()
395
 
        builder.build_snapshot('rev-1', None,
396
 
            [('add', ('', 'TREE_ROOT', 'directory', ''))])
397
 
        builder.build_snapshot('rev-2', None,
398
 
            [('unversion', 'TREE_ROOT'),
399
 
             ('add', ('', 'my-root', 'directory', ''))])
400
 
        builder.finish_series()
401
 
        rev_tree = builder.get_branch().repository.revision_tree('rev-2')
402
 
        self.assertTreeShape([(u'', 'my-root', 'directory')], rev_tree)
403
 
 
404
 
    def test_empty_flush(self):
405
 
        """A flush with no actions before it is a no-op."""
406
 
        builder = BranchBuilder(self.get_transport().clone('foo'))
407
 
        builder.start_series()
408
 
        builder.build_snapshot('rev-1', None,
409
 
            [('add', ('', 'TREE_ROOT', 'directory', ''))])
410
 
        builder.build_snapshot('rev-2', None, [('flush', None)])
411
 
        builder.finish_series()
412
 
        rev_tree = builder.get_branch().repository.revision_tree('rev-2')
413
 
        self.assertTreeShape([(u'', 'TREE_ROOT', 'directory')], rev_tree)
414
 
 
415
 
    def test_kind_change(self):
416
 
        """It's possible to change the kind of an entry in a single snapshot
417
 
        with a bit of help from the 'flush' action.
418
 
        """
419
 
        builder = BranchBuilder(self.get_transport().clone('foo'))
420
 
        builder.start_series()
421
 
        builder.build_snapshot('A-id', None,
422
 
            [('add', (u'', 'a-root-id', 'directory', None)),
423
 
             ('add', (u'a', 'a-id', 'file', 'content\n'))])
424
 
        builder.build_snapshot('B-id', None,
425
 
            [('unversion', 'a-id'),
426
 
             ('flush', None),
427
 
             ('add', (u'a', 'a-id', 'directory', None))])
428
 
        builder.finish_series()
429
 
        rev_tree = builder.get_branch().repository.revision_tree('B-id')
430
 
        self.assertTreeShape(
431
 
            [(u'', 'a-root-id', 'directory'), (u'a', 'a-id', 'directory')],
432
 
            rev_tree)
433
 
 
434
 
    def test_pivot_root(self):
435
 
        """It's possible (albeit awkward) to move an existing dir to the root
436
 
        in a single snapshot by using unversion then flush then add.
437
 
        """
438
 
        builder = BranchBuilder(self.get_transport().clone('foo'))
439
 
        builder.start_series()
440
 
        builder.build_snapshot('A-id', None,
441
 
            [('add', (u'', 'orig-root', 'directory', None)),
442
 
             ('add', (u'dir', 'dir-id', 'directory', None))])
443
 
        builder.build_snapshot('B-id', None,
444
 
            [('unversion', 'orig-root'),  # implicitly unversions all children
445
 
             ('flush', None),
446
 
             ('add', (u'', 'dir-id', 'directory', None))])
447
 
        builder.finish_series()
448
 
        rev_tree = builder.get_branch().repository.revision_tree('B-id')
449
 
        self.assertTreeShape([(u'', 'dir-id', 'directory')], rev_tree)
450