/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_inv.py

Merge from integration, mode-changes are broken.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from bzrlib.diff import internal_diff
23
23
from bzrlib.inventory import Inventory, ROOT_ID
24
24
import bzrlib.inventory as inventory
25
 
from bzrlib.osutils import has_symlinks, rename
 
25
from bzrlib.osutils import has_symlinks, rename, pathjoin
26
26
from bzrlib.tests import TestCase, TestCaseInTempDir
27
27
 
28
28
 
31
31
    def test_is_within(self):
32
32
        from bzrlib.osutils import is_inside_any
33
33
 
34
 
        SRC_FOO_C = os.path.join('src', 'foo.c')
 
34
        SRC_FOO_C = pathjoin('src', 'foo.c')
35
35
        for dirs, fn in [(['src', 'doc'], SRC_FOO_C),
36
36
                         (['src'], SRC_FOO_C),
37
37
                         (['src'], 'src'),
379
379
                         self.get_previous_heads([self.inv_D, self.inv_B]))
380
380
 
381
381
    # TODO: test two inventories with the same file revision 
 
382
 
 
383
 
 
384
class TestExecutable(TestCaseInTempDir):
 
385
 
 
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" />
 
390
</inventory>
 
391
"""
 
392
        os.mkdir('b1')
 
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)
 
401
 
 
402
        a_id = "a-20051208024829-849e76f7968d7a86"
 
403
        b_id = "b-20051208024829-849e76f7968d7a86"
 
404
        t = b.working_tree()
 
405
        self.assertEqual(['a', 'b'], [cn for cn,ie in t.inventory.iter_entries()])
 
406
 
 
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")
 
409
 
 
410
        t.commit('adding a,b', rev_id='r1')
 
411
 
 
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")
 
415
 
 
416
        self.failUnless(rev_tree.inventory[a_id].executable)
 
417
        self.failIf(rev_tree.inventory[b_id].executable)
 
418
 
 
419
        # Make sure the entries are gone
 
420
        os.remove('b1/a')
 
421
        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
 
 
427
        # Make sure that revert is able to bring them back,
 
428
        # and sets 'a' back to being executable
 
429
 
 
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()])
 
432
 
 
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")
 
435
 
 
436
        # Now remove them again, and make sure that after a
 
437
        # commit, they are still marked correctly
 
438
        os.remove('b1/a')
 
439
        os.remove('b1/b')
 
440
        t.commit('removed', rev_id='r2')
 
441
 
 
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'))
 
447
 
 
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
 
454
        # working tree
 
455
        del t
 
456
        t = b.working_tree()
 
457
 
 
458
        self.assertEqual(['a', 'b'], [cn for cn,ie in t.inventory.iter_entries()])
 
459
 
 
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")
 
462
 
 
463
        # Now make sure that 'bzr branch' also preserves the
 
464
        # executable bit
 
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()
 
470
 
 
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")
 
474
 
 
475
        # Make sure pull will delete the files
 
476
        t2.pull(b)
 
477
        self.assertEquals('r2', b2.last_revision())
 
478
        # FIXME: Same thing here, t2 needs to be recreated
 
479
        del t2
 
480
        t2 = b2.working_tree()
 
481
        self.assertEqual([], [cn for cn,ie in t2.inventory.iter_entries()])
 
482
 
 
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')
 
487
 
 
488
        t2.pull(b)
 
489
        # FIXME: And here
 
490
        del t2
 
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()])
 
494
 
 
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")