~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree.py

Merge from integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
import os
19
19
from bzrlib.branch import Branch
20
 
from bzrlib.selftest import TestCaseInTempDir
 
20
from bzrlib.errors import NotBranchError, NotVersionedError
 
21
from bzrlib.tests import TestCaseInTempDir
21
22
from bzrlib.trace import mutter
22
23
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
23
24
                                WorkingTree)
59
60
        self.assertEqual(files[1], ('file', '?', 'file', None, TreeFile()))
60
61
        self.assertEqual(files[2], ('symlink', '?', 'symlink', None, TreeLink()))
61
62
 
 
63
    def test_open_containing(self):
 
64
        branch = Branch.initialize('.')
 
65
        wt, relpath = WorkingTree.open_containing()
 
66
        self.assertEqual('', relpath)
 
67
        self.assertEqual(wt.basedir, branch.base)
 
68
        wt, relpath = WorkingTree.open_containing('.')
 
69
        self.assertEqual('', relpath)
 
70
        self.assertEqual(wt.basedir, branch.base)
 
71
        wt, relpath = WorkingTree.open_containing('./foo')
 
72
        self.assertEqual('foo', relpath)
 
73
        self.assertEqual(wt.basedir, branch.base)
 
74
        # paths that are urls are just plain wrong for working trees.
 
75
        self.assertRaises(NotBranchError,
 
76
                          WorkingTree.open_containing, 
 
77
                          'file:///' + os.getcwdu())
 
78
 
62
79
    def test_construct_with_branch(self):
63
80
        branch = Branch.initialize('.')
64
81
        tree = WorkingTree(branch.base, branch)
95
112
    def get_pullable_branches(self):
96
113
        self.build_tree(['from/', 'from/file', 'to/'])
97
114
        br_a = Branch.initialize('from')
98
 
        br_a.add('file')
99
 
        br_a.commit('foo', rev_id='A')
 
115
        tree = br_a.working_tree()
 
116
        tree.add('file')
 
117
        tree.commit('foo', rev_id='A')
100
118
        br_b = Branch.initialize('to')
101
119
        return br_a, br_b
102
120
 
108
126
 
109
127
    def test_pull_overwrites(self):
110
128
        br_a, br_b = self.get_pullable_branches()
111
 
        br_b.commit('foo', rev_id='B')
 
129
        br_b.working_tree().commit('foo', rev_id='B')
112
130
        self.assertEqual(['B'], br_b.revision_history())
113
131
        br_b.working_tree().pull(br_a, overwrite=True)
114
132
        self.failUnless(br_b.storage.has_revision('A'))
115
133
        self.failUnless(br_b.storage.has_revision('B'))
116
134
        self.assertEqual(['A'], br_b.revision_history())
 
135
 
 
136
    def test_revert(self):
 
137
        """Test selected-file revert"""
 
138
        b = Branch.initialize('.')
 
139
 
 
140
        self.build_tree(['hello.txt'])
 
141
        file('hello.txt', 'w').write('initial hello')
 
142
 
 
143
        self.assertRaises(NotVersionedError,
 
144
                          b.working_tree().revert, ['hello.txt'])
 
145
        tree = WorkingTree(b.base, b)
 
146
        tree.add(['hello.txt'])
 
147
        tree.commit('create initial hello.txt')
 
148
 
 
149
        self.check_file_contents('hello.txt', 'initial hello')
 
150
        file('hello.txt', 'w').write('new hello')
 
151
        self.check_file_contents('hello.txt', 'new hello')
 
152
 
 
153
        # revert file modified since last revision
 
154
        tree.revert(['hello.txt'])
 
155
        self.check_file_contents('hello.txt', 'initial hello')
 
156
        self.check_file_contents('hello.txt~', 'new hello')
 
157
 
 
158
        # reverting again does not clobber the backup
 
159
        tree.revert(['hello.txt'])
 
160
        self.check_file_contents('hello.txt', 'initial hello')
 
161
        self.check_file_contents('hello.txt~', 'new hello')
 
162
 
 
163
    def test_unknowns(self):
 
164
        b = Branch.initialize('.')
 
165
        tree = WorkingTree('.', b)
 
166
        self.build_tree(['hello.txt',
 
167
                         'hello.txt~'])
 
168
        self.assertEquals(list(tree.unknowns()),
 
169
                          ['hello.txt'])
 
170