~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branchbuilder.py

Fix up inter_changes with dirstate both C and python.

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'))
143
130
                              (u'b', 'b-id', 'directory'),
144
131
                             ], rev_tree)
145
132
 
146
 
    def test_commit_timestamp(self):
147
 
        builder = self.make_branch_builder('foo')
148
 
        rev_id = builder.build_snapshot(None, None,
149
 
            [('add', (u'', None, 'directory', None))],
150
 
            timestamp=1234567890)
151
 
        rev = builder.get_branch().repository.get_revision(rev_id)
152
 
        self.assertEqual(
153
 
            1234567890,
154
 
            int(rev.timestamp))
155
 
 
156
133
    def test_commit_message_default(self):
157
134
        builder = BranchBuilder(self.get_transport().clone('foo'))
158
135
        rev_id = builder.build_snapshot(None, None,
170
147
        rev = branch.repository.get_revision(rev_id)
171
148
        self.assertEqual(u'Foo', rev.message)
172
149
 
173
 
    def test_commit_message_callback(self):
174
 
        builder = BranchBuilder(self.get_transport().clone('foo'))
175
 
        rev_id = builder.build_snapshot(None, None,
176
 
            [('add', (u'', None, 'directory', None))],
177
 
            message_callback=lambda x:u'Foo')
178
 
        branch = builder.get_branch()
179
 
        rev = branch.repository.get_revision(rev_id)
180
 
        self.assertEqual(u'Foo', rev.message)
181
 
 
182
150
    def test_modify_file(self):
183
151
        builder = self.build_a_rev()
184
152
        rev_id2 = builder.build_snapshot('B-id', None,
229
197
            builder.build_snapshot, 'B-id', None, [('weirdo', ('foo',))])
230
198
        self.assertEqual('Unknown build action: "weirdo"', str(e))
231
199
 
232
 
    def test_rename(self):
233
 
        builder = self.build_a_rev()
234
 
        builder.build_snapshot('B-id', None,
235
 
            [('rename', ('a', 'b'))])
236
 
        rev_tree = builder.get_branch().repository.revision_tree('B-id')
237
 
        self.assertTreeShape([(u'', 'a-root-id', 'directory'),
238
 
                              (u'b', 'a-id', 'file')], rev_tree)
239
 
 
240
 
    def test_rename_into_subdir(self):
241
 
        builder = self.build_a_rev()
242
 
        builder.build_snapshot('B-id', None,
243
 
            [('add', ('dir', 'dir-id', 'directory', None)),
244
 
             ('rename', ('a', 'dir/a'))])
245
 
        rev_tree = builder.get_branch().repository.revision_tree('B-id')
246
 
        self.assertTreeShape([(u'', 'a-root-id', 'directory'),
247
 
                              (u'dir', 'dir-id', 'directory'),
248
 
                              (u'dir/a', 'a-id', 'file')], rev_tree)
249
 
 
250
 
    def test_rename_out_of_unversioned_subdir(self):
251
 
        builder = self.build_a_rev()
252
 
        builder.build_snapshot('B-id', None,
253
 
            [('add', ('dir', 'dir-id', 'directory', None)),
254
 
             ('rename', ('a', 'dir/a'))])
255
 
        builder.build_snapshot('C-id', None,
256
 
            [('rename', ('dir/a', 'a')),
257
 
             ('unversion', 'dir-id')])
258
 
        rev_tree = builder.get_branch().repository.revision_tree('C-id')
259
 
        self.assertTreeShape([(u'', 'a-root-id', 'directory'),
260
 
                              (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
261
202
 
262
203
    def test_set_parent(self):
263
204
        builder = self.build_a_rev()
265
206
        self.addCleanup(builder.finish_series)
266
207
        builder.build_snapshot('B-id', ['A-id'],
267
208
            [('modify', ('a-id', 'new\ncontent\n'))])
268
 
        builder.build_snapshot('C-id', ['A-id'],
 
209
        builder.build_snapshot('C-id', ['A-id'], 
269
210
            [('add', ('c', 'c-id', 'file', 'alt\ncontent\n'))])
270
211
        # We should now have a graph:
271
212
        #   A
333
274
                             ], d_tree)
334
275
        # Because we copied the exact text into *this* tree, the 'c' file
335
276
        # should look like it was not modified in the merge
336
 
        self.assertEqual('C-id', d_tree.get_file_revision('c-id'))
337
 
 
338
 
    def test_set_parent_to_null(self):
339
 
        builder = self.build_a_rev()
340
 
        builder.start_series()
341
 
        self.addCleanup(builder.finish_series)
342
 
        builder.build_snapshot('B-id', [],
343
 
            [('add', ('', None, 'directory', None))])
344
 
        # We should now have a graph:
345
 
        #   A B
346
 
        # And not A => B
347
 
        repo = builder.get_branch().repository
348
 
        self.assertEqual({'A-id': (_mod_revision.NULL_REVISION,),
349
 
                          'B-id': (_mod_revision.NULL_REVISION,),},
350
 
                         repo.get_parent_map(['A-id', 'B-id']))
351
 
 
352
 
    
 
277
        self.assertEqual('C-id', d_tree.inventory['c-id'].revision)
 
278
 
353
279
    def test_start_finish_series(self):
354
280
        builder = BranchBuilder(self.get_transport().clone('foo'))
355
281
        builder.start_series()
361
287
            builder.finish_series()
362
288
        self.assertIs(None, builder._tree)
363
289
        self.assertFalse(builder._branch.is_locked())
364
 
 
365
 
    def test_ghost_mainline_history(self):
366
 
        builder = BranchBuilder(self.get_transport().clone('foo'))
367
 
        builder.start_series()
368
 
        try:
369
 
            builder.build_snapshot('tip', ['ghost'],
370
 
                [('add', ('', 'ROOT_ID', 'directory', ''))],
371
 
                allow_leftmost_as_ghost=True)
372
 
        finally:
373
 
            builder.finish_series()
374
 
        b = builder.get_branch()
375
 
        b.lock_read()
376
 
        self.addCleanup(b.unlock)
377
 
        self.assertEqual(('ghost',),
378
 
            b.repository.get_graph().get_parent_map(['tip'])['tip'])
379
 
 
380
 
    def test_unversion_root_add_new_root(self):
381
 
        builder = BranchBuilder(self.get_transport().clone('foo'))
382
 
        builder.start_series()
383
 
        builder.build_snapshot('rev-1', None,
384
 
            [('add', ('', 'TREE_ROOT', 'directory', ''))])
385
 
        builder.build_snapshot('rev-2', None,
386
 
            [('unversion', 'TREE_ROOT'),
387
 
             ('add', ('', 'my-root', 'directory', ''))])
388
 
        builder.finish_series()
389
 
        rev_tree = builder.get_branch().repository.revision_tree('rev-2')
390
 
        self.assertTreeShape([(u'', 'my-root', 'directory')], rev_tree)
391
 
 
392
 
    def test_empty_flush(self):
393
 
        """A flush with no actions before it is a no-op."""
394
 
        builder = BranchBuilder(self.get_transport().clone('foo'))
395
 
        builder.start_series()
396
 
        builder.build_snapshot('rev-1', None,
397
 
            [('add', ('', 'TREE_ROOT', 'directory', ''))])
398
 
        builder.build_snapshot('rev-2', None, [('flush', None)])
399
 
        builder.finish_series()
400
 
        rev_tree = builder.get_branch().repository.revision_tree('rev-2')
401
 
        self.assertTreeShape([(u'', 'TREE_ROOT', 'directory')], rev_tree)
402
 
 
403
 
    def test_kind_change(self):
404
 
        """It's possible to change the kind of an entry in a single snapshot
405
 
        with a bit of help from the 'flush' action.
406
 
        """
407
 
        builder = BranchBuilder(self.get_transport().clone('foo'))
408
 
        builder.start_series()
409
 
        builder.build_snapshot('A-id', None,
410
 
            [('add', (u'', 'a-root-id', 'directory', None)),
411
 
             ('add', (u'a', 'a-id', 'file', 'content\n'))])
412
 
        builder.build_snapshot('B-id', None,
413
 
            [('unversion', 'a-id'),
414
 
             ('flush', None),
415
 
             ('add', (u'a', 'a-id', 'directory', None))])
416
 
        builder.finish_series()
417
 
        rev_tree = builder.get_branch().repository.revision_tree('B-id')
418
 
        self.assertTreeShape(
419
 
            [(u'', 'a-root-id', 'directory'), (u'a', 'a-id', 'directory')],
420
 
            rev_tree)
421
 
 
422
 
    def test_pivot_root(self):
423
 
        """It's possible (albeit awkward) to move an existing dir to the root
424
 
        in a single snapshot by using unversion then flush then add.
425
 
        """
426
 
        builder = BranchBuilder(self.get_transport().clone('foo'))
427
 
        builder.start_series()
428
 
        builder.build_snapshot('A-id', None,
429
 
            [('add', (u'', 'orig-root', 'directory', None)),
430
 
             ('add', (u'dir', 'dir-id', 'directory', None))])
431
 
        builder.build_snapshot('B-id', None,
432
 
            [('unversion', 'orig-root'),  # implicitly unversions all children
433
 
             ('flush', None),
434
 
             ('add', (u'', 'dir-id', 'directory', None))])
435
 
        builder.finish_series()
436
 
        rev_tree = builder.get_branch().repository.revision_tree('B-id')
437
 
        self.assertTreeShape([(u'', 'dir-id', 'directory')], rev_tree)
438