182
182
rev_id = tree.commit('first post')
184
184
self.assertEqual(rev_id, tree.last_revision())
186
def test_rename_file(self):
187
tree = self.make_branch_and_memory_tree('branch')
189
self.addCleanup(tree.unlock)
190
tree.add(['', 'foo'], ['root-id', 'foo-id'], ['directory', 'file'])
191
tree.put_file_bytes_non_atomic('foo-id', 'content\n')
192
tree.commit('one', rev_id='rev-one')
193
tree.rename_one('foo', 'bar')
194
self.assertEqual('bar', tree.id2path('foo-id'))
195
self.assertEqual('content\n', tree._file_transport.get_bytes('bar'))
196
self.assertRaises(errors.NoSuchFile,
197
tree._file_transport.get_bytes, 'foo')
198
tree.commit('two', rev_id='rev-two')
199
self.assertEqual('content\n', tree._file_transport.get_bytes('bar'))
200
self.assertRaises(errors.NoSuchFile,
201
tree._file_transport.get_bytes, 'foo')
203
rev_tree2 = tree.branch.repository.revision_tree('rev-two')
204
self.assertEqual('bar', rev_tree2.id2path('foo-id'))
205
self.assertEqual('content\n', rev_tree2.get_file_text('foo-id'))
207
def test_rename_file_to_subdir(self):
208
tree = self.make_branch_and_memory_tree('branch')
210
self.addCleanup(tree.unlock)
212
tree.mkdir('subdir', 'subdir-id')
213
tree.add('foo', 'foo-id', 'file')
214
tree.put_file_bytes_non_atomic('foo-id', 'content\n')
215
tree.commit('one', rev_id='rev-one')
217
tree.rename_one('foo', 'subdir/bar')
218
self.assertEqual('subdir/bar', tree.id2path('foo-id'))
219
self.assertEqual('content\n',
220
tree._file_transport.get_bytes('subdir/bar'))
221
tree.commit('two', rev_id='rev-two')
222
rev_tree2 = tree.branch.repository.revision_tree('rev-two')
223
self.assertEqual('subdir/bar', rev_tree2.id2path('foo-id'))