402
401
a_id = "a-20051208024829-849e76f7968d7a86"
403
402
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')
403
wt = wt.bzrdir.open_workingtree()
404
self.assertEqual(['a', 'b'], [cn for cn,ie in wt.inventory.iter_entries()])
406
self.failUnless(wt.is_executable(a_id), "'a' lost the execute bit")
407
self.failIf(wt.is_executable(b_id), "'b' gained an execute bit")
409
wt.commit('adding a,b', rev_id='r1')
412
411
rev_tree = b.repository.revision_tree('r1')
413
412
self.failUnless(rev_tree.is_executable(a_id), "'a' lost the execute bit")
419
418
# Make sure the entries are gone
420
419
os.remove('b1/a')
421
420
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'))
421
self.failIf(wt.has_id(a_id))
422
self.failIf(wt.has_filename('a'))
423
self.failIf(wt.has_id(b_id))
424
self.failIf(wt.has_filename('b'))
427
426
# Make sure that revert is able to bring them back,
428
427
# 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()])
429
wt.revert(['a', 'b'], rev_tree, backups=False)
430
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")
432
self.failUnless(wt.is_executable(a_id), "'a' lost the execute bit")
433
self.failIf(wt.is_executable(b_id), "'b' gained an execute bit")
436
435
# Now remove them again, and make sure that after a
437
436
# commit, they are still marked correctly
438
437
os.remove('b1/a')
439
438
os.remove('b1/b')
440
t.commit('removed', rev_id='r2')
439
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'))
441
self.assertEqual([], [cn for cn,ie in wt.inventory.iter_entries()])
442
self.failIf(wt.has_id(a_id))
443
self.failIf(wt.has_filename('a'))
444
self.failIf(wt.has_id(b_id))
445
self.failIf(wt.has_filename('b'))
448
447
# 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")
448
wt.revert([], rev_tree, backups=False)
449
self.assertEqual(['a', 'b'], [cn for cn,ie in wt.inventory.iter_entries()])
451
self.failUnless(wt.is_executable(a_id), "'a' lost the execute bit")
452
self.failIf(wt.is_executable(b_id), "'b' gained an execute bit")
463
454
# Now make sure that 'bzr branch' also preserves the
465
456
# TODO: Maybe this should be a blackbox test
466
b.clone('b2', revision='r1')
467
b2 = Branch.open('b2')
457
d2 = b.bzrdir.clone('b2', revision_id='r1')
458
t2 = d2.open_workingtree()
468
460
self.assertEquals('r1', b2.last_revision())
469
t2 = b2.working_tree()
471
462
self.assertEqual(['a', 'b'], [cn for cn,ie in t2.inventory.iter_entries()])
472
463
self.failUnless(t2.is_executable(a_id), "'a' lost the execute bit")
475
466
# Make sure pull will delete the files
477
468
self.assertEquals('r2', b2.last_revision())
478
# FIXME: Same thing here, t2 needs to be recreated
480
t2 = b2.working_tree()
481
469
self.assertEqual([], [cn for cn,ie in t2.inventory.iter_entries()])
483
471
# Now commit the changes on the first branch
484
472
# so that the second branch can pull the changes
485
473
# and make sure that the executable bit has been copied
486
t.commit('resurrected', rev_id='r3')
474
wt.commit('resurrected', rev_id='r3')
491
t2 = b2.working_tree()
492
477
self.assertEquals('r3', b2.last_revision())
493
478
self.assertEqual(['a', 'b'], [cn for cn,ie in t2.inventory.iter_entries()])
495
480
self.failUnless(t2.is_executable(a_id), "'a' lost the execute bit")
496
481
self.failIf(t2.is_executable(b_id), "'b' gained an execute bit")
483
class TestRevert(TestCaseWithTransport):
484
def test_dangling_id(self):
485
wt = self.make_branch_and_tree('b1')
486
self.assertEqual(len(wt.inventory), 1)
487
open('b1/a', 'wb').write('a test\n')
489
self.assertEqual(len(wt.inventory), 2)
492
self.assertEqual(len(wt.inventory), 1)