277
277
self.branch.get_transaction())
278
278
self.assertEqual(self.file_1.revision, '1')
279
279
self.assertEqual(self.file_active.revision, '1')
280
self.assertRaises(errors.WeaveError,
281
self.branch.repository.weave_store.get_lines,
282
'fileid', '2', self.branch.get_transaction())
280
vf = self.branch.repository.weave_store.get_weave(
282
self.branch.repository.get_transaction())
283
self.assertRaises(errors.RevisionNotPresent,
284
287
def test_snapshot_merge_identical_different_revid(self):
285
288
# This tests that a commit with two identical parents, one of which has
293
296
self.assertEqual(self.file_1, other_ie)
294
297
other_ie.revision = 'other'
295
298
self.assertNotEqual(self.file_1, other_ie)
296
self.branch.repository.weave_store.add_identical_text('fileid', '1',
297
'other', ['1'], self.branch.get_transaction())
299
versionfile = self.branch.repository.weave_store.get_weave(
300
'fileid', self.branch.repository.get_transaction())
301
versionfile.clone_text('other', '1', ['1'])
298
302
self.file_active.snapshot('2', 'subdir/file',
299
303
{'1':self.file_1, 'other':other_ie},
402
406
a_id = "a-20051208024829-849e76f7968d7a86"
403
407
b_id = "b-20051208024829-849e76f7968d7a86"
404
t = WorkingTree('b1', b)
405
self.assertEqual(['a', 'b'], [cn for cn,ie in t.inventory.iter_entries()])
407
self.failUnless(t.is_executable(a_id), "'a' lost the execute bit")
408
self.failIf(t.is_executable(b_id), "'b' gained an execute bit")
410
t.commit('adding a,b', rev_id='r1')
408
wt = wt.bzrdir.open_workingtree()
409
self.assertEqual(['a', 'b'], [cn for cn,ie in wt.inventory.iter_entries()])
411
self.failUnless(wt.is_executable(a_id), "'a' lost the execute bit")
412
self.failIf(wt.is_executable(b_id), "'b' gained an execute bit")
414
wt.commit('adding a,b', rev_id='r1')
412
416
rev_tree = b.repository.revision_tree('r1')
413
417
self.failUnless(rev_tree.is_executable(a_id), "'a' lost the execute bit")
419
423
# Make sure the entries are gone
420
424
os.remove('b1/a')
421
425
os.remove('b1/b')
422
self.failIf(t.has_id(a_id))
423
self.failIf(t.has_filename('a'))
424
self.failIf(t.has_id(b_id))
425
self.failIf(t.has_filename('b'))
426
self.failIf(wt.has_id(a_id))
427
self.failIf(wt.has_filename('a'))
428
self.failIf(wt.has_id(b_id))
429
self.failIf(wt.has_filename('b'))
427
431
# Make sure that revert is able to bring them back,
428
432
# and sets 'a' back to being executable
430
t.revert(['a', 'b'], rev_tree, backups=False)
431
self.assertEqual(['a', 'b'], [cn for cn,ie in t.inventory.iter_entries()])
434
wt.revert(['a', 'b'], rev_tree, backups=False)
435
self.assertEqual(['a', 'b'], [cn for cn,ie in wt.inventory.iter_entries()])
433
self.failUnless(t.is_executable(a_id), "'a' lost the execute bit")
434
self.failIf(t.is_executable(b_id), "'b' gained an execute bit")
437
self.failUnless(wt.is_executable(a_id), "'a' lost the execute bit")
438
self.failIf(wt.is_executable(b_id), "'b' gained an execute bit")
436
440
# Now remove them again, and make sure that after a
437
441
# commit, they are still marked correctly
438
442
os.remove('b1/a')
439
443
os.remove('b1/b')
440
t.commit('removed', rev_id='r2')
444
wt.commit('removed', rev_id='r2')
442
self.assertEqual([], [cn for cn,ie in t.inventory.iter_entries()])
443
self.failIf(t.has_id(a_id))
444
self.failIf(t.has_filename('a'))
445
self.failIf(t.has_id(b_id))
446
self.failIf(t.has_filename('b'))
446
self.assertEqual([], [cn for cn,ie in wt.inventory.iter_entries()])
447
self.failIf(wt.has_id(a_id))
448
self.failIf(wt.has_filename('a'))
449
self.failIf(wt.has_id(b_id))
450
self.failIf(wt.has_filename('b'))
448
452
# Now revert back to the previous commit
449
t.revert([], rev_tree, backups=False)
450
# TODO: FIXME: For some reason, after revert, the tree does not
451
# regenerate its working inventory, so we have to manually delete
452
# the working tree, and create a new one
453
# This seems to happen any time you do a merge operation on the
456
t = WorkingTree('b1', b)
458
self.assertEqual(['a', 'b'], [cn for cn,ie in t.inventory.iter_entries()])
460
self.failUnless(t.is_executable(a_id), "'a' lost the execute bit")
461
self.failIf(t.is_executable(b_id), "'b' gained an execute bit")
453
wt.revert([], rev_tree, backups=False)
454
self.assertEqual(['a', 'b'], [cn for cn,ie in wt.inventory.iter_entries()])
456
self.failUnless(wt.is_executable(a_id), "'a' lost the execute bit")
457
self.failIf(wt.is_executable(b_id), "'b' gained an execute bit")
463
459
# Now make sure that 'bzr branch' also preserves the
465
461
# TODO: Maybe this should be a blackbox test
466
b.clone('b2', revision='r1')
467
b2 = Branch.open('b2')
462
d2 = b.bzrdir.clone('b2', revision_id='r1')
463
t2 = d2.open_workingtree()
468
465
self.assertEquals('r1', b2.last_revision())
469
t2 = b2.working_tree()
471
467
self.assertEqual(['a', 'b'], [cn for cn,ie in t2.inventory.iter_entries()])
472
468
self.failUnless(t2.is_executable(a_id), "'a' lost the execute bit")
475
471
# Make sure pull will delete the files
477
473
self.assertEquals('r2', b2.last_revision())
478
# FIXME: Same thing here, t2 needs to be recreated
480
t2 = b2.working_tree()
481
474
self.assertEqual([], [cn for cn,ie in t2.inventory.iter_entries()])
483
476
# Now commit the changes on the first branch
484
477
# so that the second branch can pull the changes
485
478
# and make sure that the executable bit has been copied
486
t.commit('resurrected', rev_id='r3')
479
wt.commit('resurrected', rev_id='r3')
491
t2 = b2.working_tree()
492
482
self.assertEquals('r3', b2.last_revision())
493
483
self.assertEqual(['a', 'b'], [cn for cn,ie in t2.inventory.iter_entries()])
495
485
self.failUnless(t2.is_executable(a_id), "'a' lost the execute bit")
496
486
self.failIf(t2.is_executable(b_id), "'b' gained an execute bit")
488
class TestRevert(TestCaseWithTransport):
489
def test_dangling_id(self):
490
wt = self.make_branch_and_tree('b1')
491
self.assertEqual(len(wt.inventory), 1)
492
open('b1/a', 'wb').write('a test\n')
494
self.assertEqual(len(wt.inventory), 2)
497
self.assertEqual(len(wt.inventory), 1)