~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_inv.py

  • Committer: John Arbash Meinel
  • Date: 2005-12-08 18:32:43 UTC
  • mto: (1185.50.19 bzr-jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1532.
  • Revision ID: john@arbash-meinel.com-20051208183243-89d8bc3803f44848
Added (win32 failing) test to make sure is_executable is maintained over several operations

Show diffs side-by-side

added added

removed removed

Lines of Context:
374
374
                         self.get_previous_heads([self.inv_D, self.inv_B]))
375
375
 
376
376
    # TODO: test two inventories with the same file revision 
 
377
 
 
378
 
 
379
class TestExecutable(TestCaseInTempDir):
 
380
 
 
381
    def test_stays_executable(self):
 
382
        basic_inv = """<inventory format="5">
 
383
<file file_id="a-20051208024829-849e76f7968d7a86" name="a" executable="yes" />
 
384
<file file_id="b-20051208024829-849e76f7968d7a86" name="b" />
 
385
</inventory>
 
386
"""
 
387
        os.mkdir('b1')
 
388
        b = Branch.initialize('b1')
 
389
        open('b1/a', 'wb').write('a test\n')
 
390
        open('b1/b', 'wb').write('b test\n')
 
391
        os.chmod('b1/a', 0755)
 
392
        os.chmod('b1/b', 0644)
 
393
        # Manually writing the inventory, to ensure that
 
394
        # the executable="yes" entry is set for 'a' and not for 'b'
 
395
        open('b1/.bzr/inventory', 'wb').write(basic_inv)
 
396
 
 
397
        a_id = "a-20051208024829-849e76f7968d7a86"
 
398
        b_id = "b-20051208024829-849e76f7968d7a86"
 
399
        t = b.working_tree()
 
400
        self.assertEqual(['a', 'b'], [cn for cn,ie in t.inventory.iter_entries()])
 
401
 
 
402
        self.failUnless(t.is_executable(a_id), "'a' lost the execute bit")
 
403
        self.failIf(t.is_executable(b_id), "'b' gained an execute bit")
 
404
 
 
405
        t.commit('adding a,b', rev_id='r1')
 
406
 
 
407
        rev_tree = b.revision_tree('r1')
 
408
        self.failUnless(rev_tree.is_executable(a_id), "'a' lost the execute bit")
 
409
        self.failIf(rev_tree.is_executable(b_id), "'b' gained an execute bit")
 
410
 
 
411
        self.failUnless(rev_tree.inventory[a_id].executable)
 
412
        self.failIf(rev_tree.inventory[b_id].executable)
 
413
 
 
414
        # Make sure the entries are gone
 
415
        os.remove('b1/a')
 
416
        os.remove('b1/b')
 
417
        self.failIf(t.has_id(a_id))
 
418
        self.failIf(t.has_filename('a'))
 
419
        self.failIf(t.has_id(b_id))
 
420
        self.failIf(t.has_filename('b'))
 
421
 
 
422
        # Make sure that revert is able to bring them back,
 
423
        # and sets 'a' back to being executable
 
424
 
 
425
        t.revert(['b1/a', 'b1/b'], rev_tree, backups=False)
 
426
        self.assertEqual(['a', 'b'], [cn for cn,ie in t.inventory.iter_entries()])
 
427
 
 
428
        self.failUnless(t.is_executable(a_id), "'a' lost the execute bit")
 
429
        self.failIf(t.is_executable(b_id), "'b' gained an execute bit")
 
430
 
 
431
        # Now remove them again, and make sure that after a
 
432
        # commit, they are still marked correctly
 
433
        os.remove('b1/a')
 
434
        os.remove('b1/b')
 
435
        t.commit('removed', rev_id='r2')
 
436
 
 
437
        self.assertEqual([], [cn for cn,ie in t.inventory.iter_entries()])
 
438
        self.failIf(t.has_id(a_id))
 
439
        self.failIf(t.has_filename('a'))
 
440
        self.failIf(t.has_id(b_id))
 
441
        self.failIf(t.has_filename('b'))
 
442
 
 
443
        # Now revert back to the previous commit
 
444
        t.revert([], rev_tree, backups=False)
 
445
        # TODO: FIXME: For some reason, after revert, the tree does not 
 
446
        # regenerate its working inventory, so we have to manually delete
 
447
        # the working tree, and create a new one
 
448
        # This seems to happen any time you do a merge operation on the
 
449
        # working tree
 
450
        del t
 
451
        t = b.working_tree()
 
452
 
 
453
        self.assertEqual(['a', 'b'], [cn for cn,ie in t.inventory.iter_entries()])
 
454
 
 
455
        self.failUnless(t.is_executable(a_id), "'a' lost the execute bit")
 
456
        self.failIf(t.is_executable(b_id), "'b' gained an execute bit")
 
457
 
 
458
        # Now make sure that 'bzr branch' also preserves the
 
459
        # executable bit
 
460
        # TODO: Maybe this should be a blackbox test
 
461
        from bzrlib.clone import copy_branch
 
462
        copy_branch(b, 'b2', revision='r1')
 
463
        b2 = Branch.open('b2')
 
464
        self.assertEquals('r1', b2.last_revision())
 
465
        t2 = b2.working_tree()
 
466
 
 
467
        self.assertEqual(['a', 'b'], [cn for cn,ie in t2.inventory.iter_entries()])
 
468
        self.failUnless(t2.is_executable(a_id), "'a' lost the execute bit")
 
469
        self.failIf(t2.is_executable(b_id), "'b' gained an execute bit")
 
470
 
 
471
        # Make sure pull will delete the files
 
472
        t2.pull(b)
 
473
        self.assertEquals('r2', b2.last_revision())
 
474
        # FIXME: Same thing here, t2 needs to be recreated
 
475
        del t2
 
476
        t2 = b2.working_tree()
 
477
        self.assertEqual([], [cn for cn,ie in t2.inventory.iter_entries()])
 
478
 
 
479
        # Now commit the changes on the first branch
 
480
        # so that the second branch can pull the changes
 
481
        # and make sure that the executable bit has been copied
 
482
        t.commit('resurrected', rev_id='r3')
 
483
 
 
484
        t2.pull(b)
 
485
        # FIXME: And here
 
486
        del t2
 
487
        t2 = b2.working_tree()
 
488
        self.assertEquals('r3', b2.last_revision())
 
489
        self.assertEqual(['a', 'b'], [cn for cn,ie in t2.inventory.iter_entries()])
 
490
 
 
491
        self.failUnless(t2.is_executable(a_id), "'a' lost the execute bit")
 
492
        self.failIf(t2.is_executable(b_id), "'b' gained an execute bit")