133
133
self.failIf(link.has_text())
136
class TestEntryDiffing(TestCaseInTempDir):
136
class TestEntryDiffing(TestCaseWithTransport):
139
139
super(TestEntryDiffing, self).setUp()
140
self.branch = Branch.initialize('.')
140
self.wt = self.make_branch_and_tree('.')
141
self.branch = self.wt.branch
141
142
print >> open('file', 'wb'), 'foo'
142
self.branch.add(['file'], ['fileid'])
143
self.wt.add(['file'], ['fileid'])
143
144
if has_symlinks():
144
145
os.symlink('target1', 'symlink')
145
self.branch.add(['symlink'], ['linkid'])
146
self.branch.commit('message_1', rev_id = '1')
146
self.wt.add(['symlink'], ['linkid'])
147
self.wt.commit('message_1', rev_id = '1')
147
148
print >> open('file', 'wb'), 'bar'
148
149
if has_symlinks():
149
150
os.unlink('symlink')
150
151
os.symlink('target2', 'symlink')
151
self.tree_1 = self.branch.revision_tree('1')
152
self.inv_1 = self.branch.get_inventory('1')
152
self.tree_1 = self.branch.repository.revision_tree('1')
153
self.inv_1 = self.branch.repository.get_inventory('1')
153
154
self.file_1 = self.inv_1['fileid']
154
self.tree_2 = self.branch.working_tree()
155
self.inv_2 = self.branch.inventory
155
self.tree_2 = self.wt
156
self.inv_2 = self.tree_2.read_working_inventory()
156
157
self.file_2 = self.inv_2['fileid']
157
158
if has_symlinks():
158
159
self.link_1 = self.inv_1['linkid']
239
240
# to change, and then test merge patterns
240
241
# with fake parent entries.
241
242
super(TestSnapshot, self).setUp()
242
self.branch = Branch.initialize('.')
243
self.build_tree(['subdir/', 'subdir/file'])
244
self.branch.add(['subdir', 'subdir/file'], ['dirid', 'fileid'])
243
self.wt = self.make_branch_and_tree('.')
244
self.branch = self.wt.branch
245
self.build_tree(['subdir/', 'subdir/file'], line_endings='binary')
246
self.wt.add(['subdir', 'subdir/file'],
245
248
if has_symlinks():
247
self.branch.commit('message_1', rev_id = '1')
248
self.tree_1 = self.branch.revision_tree('1')
249
self.inv_1 = self.branch.get_inventory('1')
250
self.wt.commit('message_1', rev_id = '1')
251
self.tree_1 = self.branch.repository.revision_tree('1')
252
self.inv_1 = self.branch.repository.get_inventory('1')
250
253
self.file_1 = self.inv_1['fileid']
251
self.work_tree = self.branch.working_tree()
252
self.file_active = self.work_tree.inventory['fileid']
254
self.file_active = self.wt.inventory['fileid']
254
256
def test_snapshot_new_revision(self):
255
257
# This tests that a simple commit with no parents makes a new
256
258
# revision value in the inventory entry
257
self.file_active.snapshot('2', 'subdir/file', {}, self.work_tree,
258
self.branch.weave_store,
259
self.file_active.snapshot('2', 'subdir/file', {}, self.wt,
260
self.branch.repository.weave_store,
259
261
self.branch.get_transaction())
260
262
# expected outcome - file_1 has a revision id of '2', and we can get
261
263
# its text of 'file contents' out of the weave.
262
264
self.assertEqual(self.file_1.revision, '1')
263
265
self.assertEqual(self.file_active.revision, '2')
264
266
# this should be a separate test probably, but lets check it once..
265
lines = self.branch.weave_store.get_lines('fileid','2',
266
self.branch.get_transaction())
267
lines = self.branch.repository.weave_store.get_weave(
269
self.branch.get_transaction()).get_lines('2')
267
270
self.assertEqual(lines, ['contents of subdir/file\n'])
269
272
def test_snapshot_unchanged(self):
270
273
#This tests that a simple commit does not make a new entry for
271
274
# an unchanged inventory entry
272
275
self.file_active.snapshot('2', 'subdir/file', {'1':self.file_1},
273
self.work_tree, self.branch.weave_store,
277
self.branch.repository.weave_store,
274
278
self.branch.get_transaction())
275
279
self.assertEqual(self.file_1.revision, '1')
276
280
self.assertEqual(self.file_active.revision, '1')
277
self.assertRaises(errors.WeaveError,
278
self.branch.weave_store.get_lines, 'fileid', '2',
279
self.branch.get_transaction())
281
vf = self.branch.repository.weave_store.get_weave(
283
self.branch.repository.get_transaction())
284
self.assertRaises(errors.RevisionNotPresent,
281
288
def test_snapshot_merge_identical_different_revid(self):
282
289
# This tests that a commit with two identical parents, one of which has
290
297
self.assertEqual(self.file_1, other_ie)
291
298
other_ie.revision = 'other'
292
299
self.assertNotEqual(self.file_1, other_ie)
293
self.branch.weave_store.add_identical_text('fileid', '1', 'other', ['1'],
294
self.branch.get_transaction())
300
versionfile = self.branch.repository.weave_store.get_weave(
301
'fileid', self.branch.repository.get_transaction())
302
versionfile.clone_text('other', '1', ['1'])
295
303
self.file_active.snapshot('2', 'subdir/file',
296
304
{'1':self.file_1, 'other':other_ie},
297
self.work_tree, self.branch.weave_store,
306
self.branch.repository.weave_store,
298
307
self.branch.get_transaction())
299
308
self.assertEqual(self.file_active.revision, '2')
323
332
# D) fileid present in two inventories and one is
324
333
# a descendent of the other. (B, D)
325
334
super(TestPreviousHeads, self).setUp()
335
self.wt = self.make_branch_and_tree('.')
336
self.branch = self.wt.branch
326
337
self.build_tree(['file'])
327
self.branch = Branch.initialize('.')
328
self.branch.commit('new branch', allow_pointless=True, rev_id='A')
329
self.inv_A = self.branch.get_inventory('A')
330
self.branch.add(['file'], ['fileid'])
331
self.branch.commit('add file', rev_id='B')
332
self.inv_B = self.branch.get_inventory('B')
333
self.branch.put_controlfile('revision-history', 'A\n')
338
self.wt.commit('new branch', allow_pointless=True, rev_id='A')
339
self.inv_A = self.branch.repository.get_inventory('A')
340
self.wt.add(['file'], ['fileid'])
341
self.wt.commit('add file', rev_id='B')
342
self.inv_B = self.branch.repository.get_inventory('B')
343
uncommit(self.branch, tree=self.wt)
334
344
self.assertEqual(self.branch.revision_history(), ['A'])
335
self.branch.commit('another add of file', rev_id='C')
336
self.inv_C = self.branch.get_inventory('C')
337
self.branch.add_pending_merge('B')
338
self.branch.commit('merge in B', rev_id='D')
339
self.inv_D = self.branch.get_inventory('D')
340
self.file_active = self.branch.working_tree().inventory['fileid']
341
self.weave = self.branch.weave_store.get_weave('fileid',
342
self.branch.get_transaction())
345
self.wt.commit('another add of file', rev_id='C')
346
self.inv_C = self.branch.repository.get_inventory('C')
347
self.wt.add_pending_merge('B')
348
self.wt.commit('merge in B', rev_id='D')
349
self.inv_D = self.branch.repository.get_inventory('D')
350
self.file_active = self.wt.inventory['fileid']
351
self.weave = self.branch.repository.weave_store.get_weave('fileid',
352
self.branch.repository.get_transaction())
344
354
def get_previous_heads(self, inventories):
345
return self.file_active.find_previous_heads(inventories, self.weave)
355
return self.file_active.find_previous_heads(
357
self.branch.repository.weave_store,
358
self.branch.repository.get_transaction())
347
360
def test_fileid_in_no_inventory(self):
348
361
self.assertEqual({}, self.get_previous_heads([self.inv_A]))
370
383
self.get_previous_heads([self.inv_D, self.inv_B]))
372
385
# TODO: test two inventories with the same file revision
388
class TestExecutable(TestCaseWithTransport):
390
def test_stays_executable(self):
391
a_id = "a-20051208024829-849e76f7968d7a86"
392
b_id = "b-20051208024829-849e76f7968d7a86"
393
wt = self.make_branch_and_tree('b1')
395
open('b1/a', 'wb').write('a test\n')
396
open('b1/b', 'wb').write('b test\n')
397
os.chmod('b1/a', 0755)
398
os.chmod('b1/b', 0644)
399
wt.add(['a', 'b'], [a_id, b_id])
400
wt.inventory[a_id].executable = True
401
self.failUnless(wt.is_executable(a_id), "'a' lost the execute bit")
403
# reopen the tree and ensure it stuck.
404
wt = wt.bzrdir.open_workingtree()
405
self.assertEqual(['a', 'b'], [cn for cn,ie in wt.inventory.iter_entries()])
407
self.failUnless(wt.is_executable(a_id), "'a' lost the execute bit")
408
self.failIf(wt.is_executable(b_id), "'b' gained an execute bit")
410
wt.commit('adding a,b', rev_id='r1')
412
rev_tree = b.repository.revision_tree('r1')
413
self.failUnless(rev_tree.is_executable(a_id), "'a' lost the execute bit")
414
self.failIf(rev_tree.is_executable(b_id), "'b' gained an execute bit")
416
self.failUnless(rev_tree.inventory[a_id].executable)
417
self.failIf(rev_tree.inventory[b_id].executable)
419
# Make sure the entries are gone
422
self.failIf(wt.has_id(a_id))
423
self.failIf(wt.has_filename('a'))
424
self.failIf(wt.has_id(b_id))
425
self.failIf(wt.has_filename('b'))
427
# Make sure that revert is able to bring them back,
428
# and sets 'a' back to being executable
430
wt.revert(['a', 'b'], rev_tree, backups=False)
431
self.assertEqual(['a', 'b'], [cn for cn,ie in wt.inventory.iter_entries()])
433
self.failUnless(wt.is_executable(a_id), "'a' lost the execute bit")
434
self.failIf(wt.is_executable(b_id), "'b' gained an execute bit")
436
# Now remove them again, and make sure that after a
437
# commit, they are still marked correctly
440
wt.commit('removed', rev_id='r2')
442
self.assertEqual([], [cn for cn,ie in wt.inventory.iter_entries()])
443
self.failIf(wt.has_id(a_id))
444
self.failIf(wt.has_filename('a'))
445
self.failIf(wt.has_id(b_id))
446
self.failIf(wt.has_filename('b'))
448
# Now revert back to the previous commit
449
wt.revert([], rev_tree, backups=False)
450
self.assertEqual(['a', 'b'], [cn for cn,ie in wt.inventory.iter_entries()])
452
self.failUnless(wt.is_executable(a_id), "'a' lost the execute bit")
453
self.failIf(wt.is_executable(b_id), "'b' gained an execute bit")
455
# Now make sure that 'bzr branch' also preserves the
457
# TODO: Maybe this should be a blackbox test
458
d2 = b.bzrdir.clone('b2', revision_id='r1')
459
t2 = d2.open_workingtree()
461
self.assertEquals('r1', b2.last_revision())
463
self.assertEqual(['a', 'b'], [cn for cn,ie in t2.inventory.iter_entries()])
464
self.failUnless(t2.is_executable(a_id), "'a' lost the execute bit")
465
self.failIf(t2.is_executable(b_id), "'b' gained an execute bit")
467
# Make sure pull will delete the files
469
self.assertEquals('r2', b2.last_revision())
470
self.assertEqual([], [cn for cn,ie in t2.inventory.iter_entries()])
472
# Now commit the changes on the first branch
473
# so that the second branch can pull the changes
474
# and make sure that the executable bit has been copied
475
wt.commit('resurrected', rev_id='r3')
478
self.assertEquals('r3', b2.last_revision())
479
self.assertEqual(['a', 'b'], [cn for cn,ie in t2.inventory.iter_entries()])
481
self.failUnless(t2.is_executable(a_id), "'a' lost the execute bit")
482
self.failIf(t2.is_executable(b_id), "'b' gained an execute bit")
484
class TestRevert(TestCaseWithTransport):
485
def test_dangling_id(self):
486
wt = self.make_branch_and_tree('b1')
487
self.assertEqual(len(wt.inventory), 1)
488
open('b1/a', 'wb').write('a test\n')
490
self.assertEqual(len(wt.inventory), 2)
493
self.assertEqual(len(wt.inventory), 1)