19
19
from bzrlib.branch import Branch
20
from bzrlib.errors import NotVersionedError
21
from bzrlib.selftest import TestCaseInTempDir
20
from bzrlib.errors import NotBranchError, NotVersionedError
21
from bzrlib.tests import TestCaseInTempDir
22
22
from bzrlib.trace import mutter
23
23
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
60
60
self.assertEqual(files[1], ('file', '?', 'file', None, TreeFile()))
61
61
self.assertEqual(files[2], ('symlink', '?', 'symlink', None, TreeLink()))
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())
63
79
def test_construct_with_branch(self):
64
80
branch = Branch.initialize('.')
65
81
tree = WorkingTree(branch.base, branch)
96
112
def get_pullable_branches(self):
97
113
self.build_tree(['from/', 'from/file', 'to/'])
98
114
br_a = Branch.initialize('from')
100
br_a.working_tree().commit('foo', rev_id='A')
115
tree = br_a.working_tree()
117
tree.commit('foo', rev_id='A')
101
118
br_b = Branch.initialize('to')
102
119
return br_a, br_b
126
143
self.assertRaises(NotVersionedError,
127
144
b.working_tree().revert, ['hello.txt'])
130
b.working_tree().commit('create initial hello.txt')
145
tree = WorkingTree(b.base, b)
146
tree.add(['hello.txt'])
147
tree.commit('create initial hello.txt')
132
149
self.check_file_contents('hello.txt', 'initial hello')
133
150
file('hello.txt', 'w').write('new hello')
134
151
self.check_file_contents('hello.txt', 'new hello')
136
wt = b.working_tree()
138
153
# revert file modified since last revision
139
wt.revert(['hello.txt'])
154
tree.revert(['hello.txt'])
140
155
self.check_file_contents('hello.txt', 'initial hello')
141
156
self.check_file_contents('hello.txt~', 'new hello')
143
158
# reverting again does not clobber the backup
144
wt.revert(['hello.txt'])
159
tree.revert(['hello.txt'])
145
160
self.check_file_contents('hello.txt', 'initial hello')
146
161
self.check_file_contents('hello.txt~', 'new hello')
163
def test_unknowns(self):
164
b = Branch.initialize('.')
165
tree = WorkingTree('.', b)
166
self.build_tree(['hello.txt',
168
self.assertEquals(list(tree.unknowns()),