178
178
builder = self.build_a_rev()
179
179
self.assertRaises(errors.UnknownBuildAction,
180
180
builder.build_snapshot, None, 'B-id', [('weirdo', ('foo',))])
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
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:
195
# And not A => B => C
196
repo = builder.get_branch().repository
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'),
205
self.assertEqual('new\ncontent\n', b_tree.get_file_text('a-id'))
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'),
213
self.assertEqual('contents', c_tree.get_file_text('a-id'))
214
self.assertEqual('alt\ncontent\n', c_tree.get_file_text('c-id'))
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
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'),
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
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'),
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)