13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Test Tree.changes_from() for WorkingTree specific scenarios."""
19
from bzrlib import revision
20
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
23
class TestChangesFrom(TestCaseWithWorkingTree):
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""test the functions in bzrlib/delta.py"""
19
from bzrlib import delta, revision, transform
20
from bzrlib.tests import TestCaseWithTransport
23
class TestCompareTrees(TestCaseWithTransport):
26
super(TestChangesFrom, self).setUp()
26
TestCaseWithTransport.setUp(self)
27
27
self.tree = self.make_branch_and_tree('tree')
28
28
files = ['a', 'b/', 'b/c']
29
self.build_tree(files, transport=self.tree.bzrdir.root_transport)
29
self.build_tree(['tree/' + f for f in files])
30
30
self.tree.add(files, ['a-id', 'b-id', 'c-id'])
31
31
self.tree.commit('initial tree')
33
def test_revision_tree_against_empty(self):
34
empty_tree = self.tree.branch.repository.revision_tree(
35
revision.NULL_REVISION)
36
d = delta.compare_trees(empty_tree, self.tree.basis_tree())
37
self.assertEqual([('a', 'a-id', 'file'),
38
('b', 'b-id', 'directory'),
39
('b/c', 'c-id', 'file'),
41
self.assertEqual([], d.removed)
42
self.assertEqual([], d.renamed)
43
self.assertEqual([], d.modified)
45
d = delta.compare_trees(self.tree.basis_tree(), empty_tree)
46
self.assertEqual([], d.added)
47
self.assertEqual([('a', 'a-id', 'file'),
48
('b', 'b-id', 'directory'),
49
('b/c', 'c-id', 'file'),
51
self.assertEqual([], d.renamed)
52
self.assertEqual([], d.modified)
54
def test_tree_modified(self):
55
open('tree/a', 'wb').write('foobar\n')
57
d = delta.compare_trees(self.tree.basis_tree(), self.tree)
58
self.assertEqual([], d.added)
59
self.assertEqual([], d.removed)
60
self.assertEqual([], d.renamed)
61
self.assertEqual([('a', 'a-id', 'file', True, False)], d.modified)
63
def test_tree_meta_modified(self):
64
tt = transform.TreeTransform(self.tree)
65
trans_id = tt.trans_id_tree_path('b/c')
66
tt.set_executability(True, trans_id)
69
d = delta.compare_trees(self.tree.basis_tree(), self.tree)
71
self.assertEqual([], d.added)
72
self.assertEqual([], d.removed)
73
self.assertEqual([], d.renamed)
74
self.assertEqual([('b/c', 'c-id', 'file', False, True)], d.modified)
76
def test_tree_renamed(self):
77
self.tree.rename_one('a', 'd')
79
d = delta.compare_trees(self.tree.basis_tree(), self.tree)
81
self.assertEqual([], d.added)
82
self.assertEqual([], d.removed)
83
self.assertEqual([('a', 'd', 'a-id', 'file', False, False)], d.renamed)
84
self.assertEqual([], d.modified)
86
def test_tree_renamed_modified(self):
87
self.tree.rename_one('a', 'd')
88
open('tree/d', 'wb').write('bar\n')
90
d = delta.compare_trees(self.tree.basis_tree(), self.tree)
92
self.assertEqual([], d.added)
93
self.assertEqual([], d.removed)
94
self.assertEqual([('a', 'd', 'a-id', 'file', True, False)], d.renamed)
95
self.assertEqual([], d.modified)
97
def test_tree_renamed_meta_modified(self):
98
tt = transform.TreeTransform(self.tree)
99
trans_id = tt.trans_id_tree_path('b/c')
100
parent_trans_id = tt.trans_id_tree_path('')
101
tt.adjust_path('e', parent_trans_id, trans_id)
102
tt.set_executability(True, trans_id)
105
d = delta.compare_trees(self.tree.basis_tree(), self.tree)
107
self.assertEqual([], d.added)
108
self.assertEqual([], d.removed)
109
self.assertEqual([('b/c', 'e', 'c-id', 'file', False, True)], d.renamed)
110
self.assertEqual([], d.modified)
112
def test_subset_file(self):
113
empty_tree = self.tree.branch.repository.revision_tree(
114
revision.NULL_REVISION)
116
d = delta.compare_trees(empty_tree, self.tree.basis_tree(),
117
specific_files=['a'])
118
self.assertEqual([('a', 'a-id', 'file')], d.added)
119
self.assertEqual([], d.removed)
120
self.assertEqual([], d.renamed)
121
self.assertEqual([], d.modified)
123
def test_subset_multiple(self):
124
empty_tree = self.tree.branch.repository.revision_tree(
125
revision.NULL_REVISION)
127
d = delta.compare_trees(empty_tree, self.tree,
128
specific_files=['a', 'b/c'])
129
self.assertEqual([('a', 'a-id', 'file'),
130
('b/c', 'c-id', 'file'),
132
self.assertEqual([], d.removed)
133
self.assertEqual([], d.renamed)
134
self.assertEqual([], d.modified)
136
def test_subset_dir(self):
137
"""Restricting to a directory checks the dir, and all children."""
138
empty_tree = self.tree.branch.repository.revision_tree(
139
revision.NULL_REVISION)
141
d = delta.compare_trees(empty_tree, self.tree,
142
specific_files=['b'])
143
self.assertEqual([('b', 'b-id', 'directory'),
144
('b/c', 'c-id', 'file'),
146
self.assertEqual([], d.removed)
147
self.assertEqual([], d.renamed)
148
self.assertEqual([], d.modified)
33
150
def test_unknown(self):
34
151
self.build_tree(['tree/unknown'])
35
# Unknowns are not reported by changes_from
36
d = self.tree.changes_from(self.tree.basis_tree())
152
# Unknowns are not reported by compare_trees
153
d = delta.compare_trees(self.tree.basis_tree(), self.tree)
37
154
self.assertEqual([], d.added)
38
155
self.assertEqual([], d.removed)
39
156
self.assertEqual([], d.renamed)