379
379
self.get_previous_heads([self.inv_D, self.inv_B]))
381
381
# TODO: test two inventories with the same file revision
384
class TestExecutable(TestCaseInTempDir):
386
def test_stays_executable(self):
387
basic_inv = """<inventory format="5">
388
<file file_id="a-20051208024829-849e76f7968d7a86" name="a" executable="yes" />
389
<file file_id="b-20051208024829-849e76f7968d7a86" name="b" />
393
b = Branch.initialize('b1')
394
open('b1/a', 'wb').write('a test\n')
395
open('b1/b', 'wb').write('b test\n')
396
os.chmod('b1/a', 0755)
397
os.chmod('b1/b', 0644)
398
# Manually writing the inventory, to ensure that
399
# the executable="yes" entry is set for 'a' and not for 'b'
400
open('b1/.bzr/inventory', 'wb').write(basic_inv)
402
a_id = "a-20051208024829-849e76f7968d7a86"
403
b_id = "b-20051208024829-849e76f7968d7a86"
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')
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(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'))
427
# Make sure that revert is able to bring them back,
428
# and sets 'a' back to being executable
430
t.revert(['b1/a', 'b1/b'], rev_tree, backups=False)
431
self.assertEqual(['a', 'b'], [cn for cn,ie in t.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")
436
# Now remove them again, and make sure that after a
437
# commit, they are still marked correctly
440
t.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'))
448
# 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
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")
463
# Now make sure that 'bzr branch' also preserves the
465
# TODO: Maybe this should be a blackbox test
466
b.clone('b2', revision='r1')
467
b2 = Branch.open('b2')
468
self.assertEquals('r1', b2.last_revision())
469
t2 = b2.working_tree()
471
self.assertEqual(['a', 'b'], [cn for cn,ie in t2.inventory.iter_entries()])
472
self.failUnless(t2.is_executable(a_id), "'a' lost the execute bit")
473
self.failIf(t2.is_executable(b_id), "'b' gained an execute bit")
475
# Make sure pull will delete the files
477
self.assertEquals('r2', b2.last_revision())
478
# FIXME: Same thing here, t2 needs to be recreated
480
t2 = b2.working_tree()
481
self.assertEqual([], [cn for cn,ie in t2.inventory.iter_entries()])
483
# Now commit the changes on the first branch
484
# so that the second branch can pull the changes
485
# and make sure that the executable bit has been copied
486
t.commit('resurrected', rev_id='r3')
491
t2 = b2.working_tree()
492
self.assertEquals('r3', b2.last_revision())
493
self.assertEqual(['a', 'b'], [cn for cn,ie in t2.inventory.iter_entries()])
495
self.failUnless(t2.is_executable(a_id), "'a' lost the execute bit")
496
self.failIf(t2.is_executable(b_id), "'b' gained an execute bit")