220
221
self.assertEqual(output.getvalue(),
221
222
"=== target changed 'target1' => 'target2'\n")
225
class TestSnapshot(TestCaseInTempDir):
228
# for full testing we'll need a branch
229
# with a subdir to test parent changes.
230
# and a file, link and dir under that.
231
# but right now I only need one attribute
232
# to change, and then test merge patterns
233
# with fake parent entries.
234
super(TestSnapshot, self).setUp()
235
self.branch = Branch.initialize('.')
236
self.build_tree(['subdir/', 'subdir/file'])
237
self.branch.add(['subdir', 'subdir/file'], ['dirid', 'fileid'])
240
self.branch.commit('message_1', rev_id = '1')
241
self.tree_1 = self.branch.revision_tree('1')
242
self.inv_1 = self.branch.get_inventory('1')
243
self.file_1 = self.inv_1['fileid']
244
self.work_tree = self.branch.working_tree()
245
self.file_active = self.work_tree.inventory['fileid']
247
def test_snapshot_new_revision(self):
248
# This tests that a simple commit with no parents makes a new
249
# revision value in the inventory entry
250
self.file_active.snapshot('2', 'subdir/file', {}, self.work_tree,
251
self.branch.weave_store)
252
# expected outcome - file_1 has a revision id of '2', and we can get
253
# its text of 'file contents' out of the weave.
254
self.assertEqual(self.file_1.revision, '1')
255
self.assertEqual(self.file_active.revision, '2')
256
# this should be a separate test probably, but lets check it once..
257
lines = self.branch.weave_store.get_lines('fileid','2')
258
self.assertEqual(lines, ['contents of subdir/file\n'])
260
def test_snapshot_unchanged(self):
261
#This tests that a simple commit does not make a new entry for
262
# an unchanged inventory entry
263
self.file_active.snapshot('2', 'subdir/file', {'1':self.file_1},
264
self.work_tree, self.branch.weave_store)
265
self.assertEqual(self.file_1.revision, '1')
266
self.assertEqual(self.file_active.revision, '1')
267
self.assertRaises(errors.WeaveError,
268
self.branch.weave_store.get_lines, 'fileid', '2')
270
def test_snapshot_merge_identical_different_revid(self):
271
# This tests that a commit with two identical parents, one of which has
272
# a different revision id, results in a new revision id in the entry.
273
other_ie = inventory.InventoryFile('fileid', 'newname', self.file_1.parent_id)
274
other_ie = inventory.InventoryFile('fileid', 'file', self.file_1.parent_id)
275
other_ie.revision = '1'
276
other_ie.text_sha1 = self.file_1.text_sha1
277
other_ie.text_size = self.file_1.text_size
278
self.assertEqual(self.file_1, other_ie)
279
other_ie.revision = 'other'
280
self.assertNotEqual(self.file_1, other_ie)
281
self.branch.weave_store.add_identical_text('fileid', '1', 'other', ['1'])
282
self.file_active.snapshot('2', 'subdir/file',
283
{'1':self.file_1, 'other':other_ie},
284
self.work_tree, self.branch.weave_store)
285
self.assertEqual(self.file_active.revision, '2')
287
def test_snapshot_changed(self):
288
# This tests that a commit with one different parent results in a new
289
# revision id in the entry.
290
self.file_active.name='newname'
291
rename('subdir/file', 'subdir/newname')
292
self.file_active.snapshot('2', 'subdir/newname', {'1':self.file_1},
294
self.branch.weave_store)
295
# expected outcome - file_1 has a revision id of '2'
296
self.assertEqual(self.file_active.revision, '2')