19
19
from bzrlib.branch import Branch
20
20
from bzrlib.selftest import TestCaseInTempDir
21
21
from bzrlib.trace import mutter
22
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
22
from bzrlib.workingtree import TreeEntry, TreeDirectory, TreeFile, TreeLink
25
24
class TestTreeDirectory(TestCaseInTempDir):
58
57
self.assertEqual(files[0], ('dir', '?', 'directory', None, TreeDirectory()))
59
58
self.assertEqual(files[1], ('file', '?', 'file', None, TreeFile()))
60
59
self.assertEqual(files[2], ('symlink', '?', 'symlink', None, TreeLink()))
62
def test_construct_with_branch(self):
63
branch = Branch.initialize('.')
64
tree = WorkingTree(branch.base, branch)
65
self.assertEqual(branch, tree.branch)
66
self.assertEqual(branch.base, tree.basedir)
68
def test_construct_without_branch(self):
69
branch = Branch.initialize('.')
70
tree = WorkingTree(branch.base)
71
self.assertEqual(branch.base, tree.branch.base)
72
self.assertEqual(branch.base, tree.basedir)
74
def test_basic_relpath(self):
75
# for comprehensive relpath tests, see whitebox.py.
76
branch = Branch.initialize('.')
77
tree = WorkingTree(branch.base)
78
self.assertEqual('child',
79
tree.relpath(os.path.join(os.getcwd(), 'child')))
81
def test_lock_locks_branch(self):
82
branch = Branch.initialize('.')
83
tree = WorkingTree(branch.base)
85
self.assertEqual(1, tree.branch._lock_count)
86
self.assertEqual('r', tree.branch._lock_mode)
88
self.assertEqual(None, tree.branch._lock_count)
90
self.assertEqual(1, tree.branch._lock_count)
91
self.assertEqual('w', tree.branch._lock_mode)
93
self.assertEqual(None, tree.branch._lock_count)
95
def get_pullable_branches(self):
96
self.build_tree(['from/', 'from/file', 'to/'])
97
br_a = Branch.initialize('from')
99
br_a.commit('foo', rev_id='A')
100
br_b = Branch.initialize('to')
104
br_a, br_b = self.get_pullable_branches()
105
br_b.working_tree().pull(br_a)
106
self.failUnless(br_b.has_revision('A'))
107
self.assertEqual(['A'], br_b.revision_history())
109
def test_pull_overwrites(self):
110
br_a, br_b = self.get_pullable_branches()
111
br_b.commit('foo', rev_id='B')
112
self.assertEqual(['B'], br_b.revision_history())
113
br_b.working_tree().pull(br_a, overwrite=True)
114
self.failUnless(br_b.has_revision('A'))
115
self.failUnless(br_b.has_revision('B'))
116
self.assertEqual(['A'], br_b.revision_history())