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

  • Committer: John Arbash Meinel
  • Date: 2008-07-22 18:47:24 UTC
  • mto: (3514.4.6 merge_lca_multi)
  • mto: This revision was merged to the branch mainline in revision 3590.
  • Revision ID: john@arbash-meinel.com-20080722184724-as3agicle15r1szy
Add the ability to force a basis for a revision.

This includes the ability to merge in another tree, though it won't
actually *do* the merge under the covers.
You have to manually set what you want the texts to be like.

Show diffs side-by-side

added added

removed removed

Lines of Context:
178
178
        builder = self.build_a_rev()
179
179
        self.assertRaises(errors.UnknownBuildAction,
180
180
            builder.build_snapshot, None, 'B-id', [('weirdo', ('foo',))])
 
181
 
 
182
    # TODO: rename a file/directory, but rename isn't supported by the
 
183
    #       MemoryTree api yet, so for now we wait until it is used
 
184
 
 
185
    def test_set_parent(self):
 
186
        builder = self.build_a_rev()
 
187
        builder.build_snapshot(['A-id'], 'B-id',
 
188
            [('modify', ('a-id', 'new\ncontent\n'))])
 
189
        builder.build_snapshot(['A-id'], 'C-id',
 
190
            [('add', ('c', 'c-id', 'file', 'alt\ncontent\n'))])
 
191
        # We should now have a graph:
 
192
        #   A
 
193
        #   |\
 
194
        #   C B
 
195
        # And not A => B => C
 
196
        repo = builder.get_branch().repository
 
197
        repo.lock_read()
 
198
        self.addCleanup(repo.unlock)
 
199
        self.assertEqual({'B-id': ('A-id',), 'C-id': ('A-id',)},
 
200
                         repo.get_parent_map(['B-id', 'C-id']))
 
201
        b_tree = repo.revision_tree('B-id')
 
202
        self.assertTreeShape([(u'', 'a-root-id', 'directory'),
 
203
                              (u'a', 'a-id', 'file'),
 
204
                             ], b_tree)
 
205
        self.assertEqual('new\ncontent\n', b_tree.get_file_text('a-id'))
 
206
 
 
207
        # We should still be using the content from A in C, not from B
 
208
        c_tree = repo.revision_tree('C-id')
 
209
        self.assertTreeShape([(u'', 'a-root-id', 'directory'),
 
210
                              (u'a', 'a-id', 'file'),
 
211
                              (u'c', 'c-id', 'file'),
 
212
                             ], c_tree)
 
213
        self.assertEqual('contents', c_tree.get_file_text('a-id'))
 
214
        self.assertEqual('alt\ncontent\n', c_tree.get_file_text('c-id'))
 
215
 
 
216
    def test_set_merge_parent(self):
 
217
        builder = self.build_a_rev()
 
218
        builder.build_snapshot(['A-id'], 'B-id',
 
219
            [('add', ('b', 'b-id', 'file', 'b\ncontent\n'))])
 
220
        builder.build_snapshot(['A-id'], 'C-id',
 
221
            [('add', ('c', 'c-id', 'file', 'alt\ncontent\n'))])
 
222
        builder.build_snapshot(['B-id', 'C-id'], 'D-id', [])
 
223
        repo = builder.get_branch().repository
 
224
        repo.lock_read()
 
225
        self.addCleanup(repo.unlock)
 
226
        self.assertEqual({'B-id': ('A-id',), 'C-id': ('A-id',),
 
227
                          'D-id': ('B-id', 'C-id')},
 
228
                         repo.get_parent_map(['B-id', 'C-id', 'D-id']))
 
229
        d_tree = repo.revision_tree('D-id')
 
230
        # Note: by default a merge node does *not* pull in the changes from the
 
231
        #       merged tree, you have to supply it yourself.
 
232
        self.assertTreeShape([(u'', 'a-root-id', 'directory'),
 
233
                              (u'a', 'a-id', 'file'),
 
234
                              (u'b', 'b-id', 'file'),
 
235
                             ], d_tree)
 
236
 
 
237
    def test_set_merge_parent_and_contents(self):
 
238
        builder = self.build_a_rev()
 
239
        builder.build_snapshot(['A-id'], 'B-id',
 
240
            [('add', ('b', 'b-id', 'file', 'b\ncontent\n'))])
 
241
        builder.build_snapshot(['A-id'], 'C-id',
 
242
            [('add', ('c', 'c-id', 'file', 'alt\ncontent\n'))])
 
243
        builder.build_snapshot(['B-id', 'C-id'], 'D-id',
 
244
            [('add', ('c', 'c-id', 'file', 'alt\ncontent\n'))])
 
245
        repo = builder.get_branch().repository
 
246
        repo.lock_read()
 
247
        self.addCleanup(repo.unlock)
 
248
        self.assertEqual({'B-id': ('A-id',), 'C-id': ('A-id',),
 
249
                          'D-id': ('B-id', 'C-id')},
 
250
                         repo.get_parent_map(['B-id', 'C-id', 'D-id']))
 
251
        d_tree = repo.revision_tree('D-id')
 
252
        self.assertTreeShape([(u'', 'a-root-id', 'directory'),
 
253
                              (u'a', 'a-id', 'file'),
 
254
                              (u'b', 'b-id', 'file'),
 
255
                              (u'c', 'c-id', 'file'),
 
256
                             ], d_tree)
 
257
        # Because we copied the exact text into *this* tree, the 'c' file
 
258
        # should look like it was not modified in the merge
 
259
        self.assertEqual('C-id', d_tree.inventory['c-id'].revision)