~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_workingtree/test_workingtree.py

  • Committer: Jelmer Vernooij
  • Date: 2012-02-20 12:19:29 UTC
  • mfrom: (6437.23.11 2.5)
  • mto: (6581.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6582.
  • Revision ID: jelmer@samba.org-20120220121929-7ni2psvjoatm1yp4
Merge bzr/2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from bzrlib import (
24
24
    branch,
25
 
    branchbuilder,
26
25
    bzrdir,
27
26
    config,
28
27
    errors,
29
28
    osutils,
 
29
    revision as _mod_revision,
30
30
    symbol_versioning,
31
31
    tests,
32
32
    trace,
37
37
    PathsNotVersionedError,
38
38
    )
39
39
from bzrlib.inventory import Inventory
 
40
from bzrlib.mutabletree import MutableTree
40
41
from bzrlib.osutils import pathjoin, getcwd, has_symlinks
41
42
from bzrlib.tests import (
42
43
    features,
174
175
        tree = self.make_branch_and_tree('.')
175
176
 
176
177
        self.build_tree(['hello.txt'])
177
 
        file('hello.txt', 'w').write('initial hello')
 
178
        with file('hello.txt', 'w') as f: f.write('initial hello')
178
179
 
179
180
        self.assertRaises(PathsNotVersionedError,
180
181
                          tree.revert, ['hello.txt'])
182
183
        tree.commit('create initial hello.txt')
183
184
 
184
185
        self.check_file_contents('hello.txt', 'initial hello')
185
 
        file('hello.txt', 'w').write('new hello')
 
186
        with file('hello.txt', 'w') as f: f.write('new hello')
186
187
        self.check_file_contents('hello.txt', 'new hello')
187
188
 
188
189
        # revert file modified since last revision
196
197
        self.check_file_contents('hello.txt.~1~', 'new hello')
197
198
 
198
199
        # backup files are numbered
199
 
        file('hello.txt', 'w').write('new hello2')
 
200
        with file('hello.txt', 'w') as f: f.write('new hello2')
200
201
        tree.revert(['hello.txt'])
201
202
        self.check_file_contents('hello.txt', 'initial hello')
202
203
        self.check_file_contents('hello.txt.~1~', 'new hello')
205
206
    def test_revert_missing(self):
206
207
        # Revert a file that has been deleted since last commit
207
208
        tree = self.make_branch_and_tree('.')
208
 
        file('hello.txt', 'w').write('initial hello')
 
209
        with file('hello.txt', 'w') as f: f.write('initial hello')
209
210
        tree.add('hello.txt')
210
211
        tree.commit('added hello.txt')
211
212
        os.unlink('hello.txt')
249
250
 
250
251
        wt.commit('create initial state')
251
252
 
252
 
        revid = b.revision_history()[0]
 
253
        revid = b.last_revision()
253
254
        self.log('first revision_id is {%s}' % revid)
254
255
 
255
256
        tree = b.repository.revision_tree(revid)
312
313
        cloned = cloned_dir.open_workingtree()
313
314
        self.assertEqual(cloned.get_parent_ids(), wt.get_parent_ids())
314
315
 
 
316
    def test_clone_empty(self):
 
317
        wt = self.make_branch_and_tree('source')
 
318
        cloned_dir = wt.bzrdir.clone('target', revision_id=_mod_revision.NULL_REVISION)
 
319
        cloned = cloned_dir.open_workingtree()
 
320
        self.assertEqual(cloned.get_parent_ids(), wt.get_parent_ids())
 
321
 
315
322
    def test_last_revision(self):
316
323
        wt = self.make_branch_and_tree('source')
317
324
        self.assertEqual([], wt.get_parent_ids())
445
452
            revision_id='a')
446
453
        self.assertEqual(['a'], made_tree.get_parent_ids())
447
454
 
 
455
    def test_post_build_tree_hook(self):
 
456
        calls = []
 
457
        def track_post_build_tree(tree):
 
458
            calls.append(tree.last_revision())
 
459
        source = self.make_branch_and_tree('source')
 
460
        source.commit('a', rev_id='a', allow_pointless=True)
 
461
        source.commit('b', rev_id='b', allow_pointless=True)
 
462
        self.build_tree(['new/'])
 
463
        made_control = self.bzrdir_format.initialize('new')
 
464
        source.branch.repository.clone(made_control)
 
465
        source.branch.clone(made_control)
 
466
        MutableTree.hooks.install_named_hook("post_build_tree",
 
467
            track_post_build_tree, "Test")
 
468
        made_tree = self.workingtree_format.initialize(made_control,
 
469
            revision_id='a')
 
470
        self.assertEqual(['a'], calls)
 
471
 
448
472
    def test_update_sets_last_revision(self):
449
473
        # working tree formats from the meta-dir format and newer support
450
474
        # setting the last revision on a tree independently of that on the
466
490
        # current format
467
491
        self.build_tree(['checkout/', 'tree/file'])
468
492
        checkout = bzrdir.BzrDirMetaFormat1().initialize('checkout')
469
 
        branch.BranchReferenceFormat().initialize(checkout,
470
 
            target_branch=main_branch)
 
493
        checkout.set_branch_reference(main_branch)
471
494
        old_tree = self.workingtree_format.initialize(checkout)
472
495
        # now commit to 'tree'
473
496
        wt.add('file')
534
557
        # current format
535
558
        self.build_tree(['checkout/', 'tree/file'])
536
559
        checkout = bzrdir.BzrDirMetaFormat1().initialize('checkout')
537
 
        branch.BranchReferenceFormat().initialize(checkout,
538
 
            target_branch=main_branch)
 
560
        checkout.set_branch_reference(main_branch)
539
561
        old_tree = self.workingtree_format.initialize(checkout)
540
562
        # now commit to 'tree'
541
563
        wt.add('file')
623
645
        # which should have pivoted the local tip into a merge
624
646
        self.assertEqual([master_tip, 'bar'], tree.get_parent_ids())
625
647
        # and the local branch history should match the masters now.
626
 
        self.assertEqual(master_tree.branch.revision_history(),
627
 
            tree.branch.revision_history())
 
648
        self.assertEqual(master_tree.branch.last_revision(),
 
649
            tree.branch.last_revision())
628
650
 
629
651
    def test_update_takes_revision_parameter(self):
630
652
        wt = self.make_branch_and_tree('wt')
686
708
    def make_merge_conflicts(self):
687
709
        from bzrlib.merge import merge_inner
688
710
        tree = self.make_branch_and_tree('mine')
689
 
        file('mine/bloo', 'wb').write('one')
690
 
        file('mine/blo', 'wb').write('on')
 
711
        with file('mine/bloo', 'wb') as f: f.write('one')
 
712
        with file('mine/blo', 'wb') as f: f.write('on')
691
713
        tree.add(['bloo', 'blo'])
692
714
        tree.commit("blah", allow_pointless=False)
693
715
        base = tree.branch.repository.revision_tree(tree.last_revision())
694
716
        bzrdir.BzrDir.open("mine").sprout("other")
695
 
        file('other/bloo', 'wb').write('two')
 
717
        with file('other/bloo', 'wb') as f: f.write('two')
696
718
        othertree = WorkingTree.open('other')
697
719
        othertree.commit('blah', allow_pointless=False)
698
 
        file('mine/bloo', 'wb').write('three')
 
720
        with file('mine/bloo', 'wb') as f: f.write('three')
699
721
        tree.commit("blah", allow_pointless=False)
700
722
        merge_inner(tree.branch, othertree, base, this_tree=tree)
701
723
        return tree
940
962
            case_sensitive = True
941
963
        tree = self.make_branch_and_tree('test')
942
964
        self.assertEqual(case_sensitive, tree.case_sensitive)
 
965
        if not isinstance(tree, InventoryWorkingTree):
 
966
            raise TestNotApplicable("get_format_string is only available "
 
967
                                    "on bzr working trees")
943
968
        # now we cheat, and make a file that matches the case-sensitive name
944
969
        t = tree.bzrdir.get_workingtree_transport(None)
945
970
        try:
951
976
        tree = tree.bzrdir.open_workingtree()
952
977
        self.assertFalse(tree.case_sensitive)
953
978
 
 
979
    def test_supports_executable(self):
 
980
        self.build_tree(['filename'])
 
981
        tree = self.make_branch_and_tree('.')
 
982
        tree.add('filename')
 
983
        self.assertIsInstance(tree._supports_executable(), bool)
 
984
        if tree._supports_executable():
 
985
            tree.lock_read()
 
986
            try:
 
987
                self.assertFalse(tree.is_executable(tree.path2id('filename')))
 
988
            finally:
 
989
                tree.unlock()
 
990
            os.chmod('filename', 0755)
 
991
            self.addCleanup(tree.lock_read().unlock)
 
992
            self.assertTrue(tree.is_executable(tree.path2id('filename')))
 
993
        else:
 
994
            self.addCleanup(tree.lock_read().unlock)
 
995
            self.assertFalse(tree.is_executable(tree.path2id('filename')))
 
996
 
954
997
    def test_all_file_ids_with_missing(self):
955
998
        tree = self.make_branch_and_tree('tree')
956
999
        tree.lock_write()
1001
1044
            4 5-M
1002
1045
            |
1003
1046
            W
1004
 
         """
1005
 
        builder = branchbuilder.BranchBuilder(
1006
 
            self.get_transport(),
1007
 
            format=self.workingtree_format._matchingbzrdir)
 
1047
        """
 
1048
        format = self.workingtree_format.get_controldir_for_branch()
 
1049
        builder = self.make_branch_builder(".", format=format)
1008
1050
        builder.start_series()
1009
1051
        # mainline
1010
1052
        builder.build_snapshot(