79
83
if not isinstance(self.workingtree_format, WorkingTreeFormat4):
86
def test_move_target_not_dir(self):
87
tree = self.make_branch_and_tree('.')
88
self.build_tree(['a'])
91
self.assertRaises(errors.BzrMoveFailedError,
92
tree.move, ['a'], 'not-a-dir')
94
def test_move_non_existent(self):
95
tree = self.make_branch_and_tree('.')
96
self.build_tree(['a/'])
98
self.assertRaises(errors.BzrMoveFailedError,
99
tree.move, ['not-a-file'], 'a')
101
def test_move_target_not_versioned(self):
102
tree = self.make_branch_and_tree('.')
103
self.build_tree(['a/', 'b'])
105
self.assertRaises(errors.BzrMoveFailedError,
106
tree.move, ['b'], 'a')
108
# TODO: jam 20070225 What about a test when the target is now a directory,
109
# but in the past it was a file. Theoretically WorkingTree should
110
# notice the kind change.
112
def test_move_unversioned(self):
113
tree = self.make_branch_and_tree('.')
114
self.build_tree(['a/', 'b'])
116
self.assertRaises(errors.BzrMoveFailedError,
117
tree.move, ['b'], 'a')
119
def test_move_multi_unversioned(self):
120
tree = self.make_branch_and_tree('.')
121
self.build_tree(['a/', 'b', 'c', 'd'])
122
tree.add(['a', 'c', 'd'])
123
self.assertRaises(errors.BzrMoveFailedError,
124
tree.move, ['c', 'b', 'd'], 'a')
125
self.assertRaises(errors.BzrMoveFailedError,
126
tree.move, ['b', 'c', 'd'], 'a')
127
self.assertRaises(errors.BzrMoveFailedError,
128
tree.move, ['c', 'd', 'b'], 'a')
130
def get_tree_layout(self, tree):
131
"""Get the (path, file_id) pairs for the current tree."""
134
return [(path, ie.file_id) for path, ie
135
in tree.iter_entries_by_dir()]
139
def assertTreeLayout(self, expected, tree):
140
"""Check that the tree has the correct layout."""
141
actual = self.get_tree_layout(tree)
142
self.assertEqual(expected, actual)
144
def test_move_subdir(self):
145
tree = self.make_branch_and_tree('.')
146
self.build_tree(['a', 'b/', 'b/c'])
147
tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
148
root_id = tree.get_root_id()
149
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
150
('b/c', 'c-id')], tree)
151
a_contents = tree.get_file_text('a-id')
152
tree.move(['a'], 'b')
153
self.assertTreeLayout([('', root_id), ('b', 'b-id'), ('b/a', 'a-id'),
154
('b/c', 'c-id')], tree)
155
self.failIfExists('a')
156
self.failUnlessExists('b/a')
157
self.check_file_contents('b/a', a_contents)
159
def test_move_parent_dir(self):
160
tree = self.make_branch_and_tree('.')
161
self.build_tree(['a', 'b/', 'b/c'])
162
tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
163
root_id = tree.get_root_id()
164
c_contents = tree.get_file_text('c-id')
165
tree.move(['b/c'], '')
166
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
167
('c', 'c-id')], tree)
168
self.failIfExists('b/c')
169
self.failUnlessExists('c')
170
self.check_file_contents('c', c_contents)
173
self.run_bzr('mv', 'a', 'b')
174
self.assertMoved('a','b')
176
self.run_bzr('mv', 'b', 'subdir')
177
self.assertMoved('b','subdir/b')
179
self.run_bzr('mv', 'subdir/b', 'a')
180
self.assertMoved('subdir/b','a')
182
self.run_bzr('mv', 'a', 'c', 'subdir')
183
self.assertMoved('a','subdir/a')
184
self.assertMoved('c','subdir/c')
186
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
187
self.assertMoved('subdir/a','subdir/newa')