96
96
def test_put_new_file(self):
97
97
branch = self.make_branch('branch')
98
98
tree = branch.create_memorytree()
100
tree.add(['', 'foo'], kinds=['directory', 'file'])
101
tree.put_file_bytes_non_atomic('foo', 'barshoom')
102
self.assertEqual('barshoom', tree.get_file('foo').read())
99
with tree.lock_write():
100
tree.add(['', 'foo'], kinds=['directory', 'file'])
101
tree.put_file_bytes_non_atomic('foo', b'barshoom')
102
self.assertEqual(b'barshoom', tree.get_file('foo').read())
105
104
def test_put_existing_file(self):
106
105
branch = self.make_branch('branch')
107
106
tree = branch.create_memorytree()
109
tree.add(['', 'foo'], kinds=['directory', 'file'])
110
tree.put_file_bytes_non_atomic('foo', 'first-content')
111
tree.put_file_bytes_non_atomic('foo', 'barshoom')
112
self.assertEqual('barshoom', tree.get_file('foo').read())
107
with tree.lock_write():
108
tree.add(['', 'foo'], kinds=['directory', 'file'])
109
tree.put_file_bytes_non_atomic('foo', b'first-content')
110
tree.put_file_bytes_non_atomic('foo', b'barshoom')
111
self.assertEqual(b'barshoom', tree.get_file('foo').read())
115
113
def test_add_in_subdir(self):
116
114
branch = self.make_branch('branch')
117
115
tree = branch.create_memorytree()
119
self.addCleanup(tree.unlock)
120
tree.add([''], None, ['directory'])
122
tree.put_file_bytes_non_atomic('adir/afile', 'barshoom')
123
tree.add(['adir/afile'], None, ['file'])
124
self.assertTrue(tree.is_versioned('adir/afile'))
125
self.assertTrue(tree.is_versioned('adir'))
116
with tree.lock_write():
117
tree.add([''], None, ['directory'])
119
tree.put_file_bytes_non_atomic('adir/afile', b'barshoom')
120
tree.add(['adir/afile'], None, ['file'])
121
self.assertTrue(tree.is_versioned('adir/afile'))
122
self.assertTrue(tree.is_versioned('adir'))
127
124
def test_commit_trivial(self):
128
125
"""Smoke test for commit on a MemoryTree.
133
130
branch = self.make_branch('branch')
134
131
tree = branch.create_memorytree()
136
tree.add(['', 'foo'], kinds=['directory', 'file'])
137
tree.put_file_bytes_non_atomic('foo', 'barshoom')
138
revision_id = tree.commit('message baby')
139
# the parents list for the tree should have changed.
140
self.assertEqual([revision_id], tree.get_parent_ids())
132
with tree.lock_write():
133
tree.add(['', 'foo'], kinds=['directory', 'file'])
134
tree.put_file_bytes_non_atomic('foo', b'barshoom')
135
revision_id = tree.commit('message baby')
136
# the parents list for the tree should have changed.
137
self.assertEqual([revision_id], tree.get_parent_ids())
142
138
# and we should have a revision that is accessible outside the tree lock
143
139
revtree = tree.branch.repository.revision_tree(revision_id)
145
self.addCleanup(revtree.unlock)
146
self.assertEqual('barshoom', revtree.get_file('foo').read())
140
with revtree.lock_read():
141
self.assertEqual(b'barshoom', revtree.get_file('foo').read())
148
143
def test_unversion(self):
149
144
"""Some test for unversion of a memory tree."""
168
163
tree = self.make_branch_and_memory_tree('branch')
169
164
tree.lock_write()
170
165
self.addCleanup(tree.unlock)
171
tree.add(['', 'foo'], ['root-id', 'foo-id'], ['directory', 'file'])
172
tree.put_file_bytes_non_atomic('foo', 'content\n')
173
tree.commit('one', rev_id='rev-one')
166
tree.add(['', 'foo'], [b'root-id', b'foo-id'], ['directory', 'file'])
167
tree.put_file_bytes_non_atomic('foo', b'content\n')
168
tree.commit('one', rev_id=b'rev-one')
174
169
tree.rename_one('foo', 'bar')
175
self.assertEqual('bar', tree.id2path('foo-id'))
170
self.assertEqual('bar', tree.id2path(b'foo-id'))
176
171
self.assertEqual('content\n', tree._file_transport.get_bytes('bar'))
177
172
self.assertRaises(errors.NoSuchFile,
178
173
tree._file_transport.get_bytes, 'foo')
179
tree.commit('two', rev_id='rev-two')
180
self.assertEqual('content\n', tree._file_transport.get_bytes('bar'))
174
tree.commit('two', rev_id=b'rev-two')
175
self.assertEqual(b'content\n', tree._file_transport.get_bytes('bar'))
181
176
self.assertRaises(errors.NoSuchFile,
182
177
tree._file_transport.get_bytes, 'foo')
184
rev_tree2 = tree.branch.repository.revision_tree('rev-two')
185
self.assertEqual('bar', rev_tree2.id2path('foo-id'))
186
self.assertEqual('content\n', rev_tree2.get_file_text('bar'))
179
rev_tree2 = tree.branch.repository.revision_tree(b'rev-two')
180
self.assertEqual('bar', rev_tree2.id2path(b'foo-id'))
181
self.assertEqual(b'content\n', rev_tree2.get_file_text('bar'))
188
183
def test_rename_file_to_subdir(self):
189
184
tree = self.make_branch_and_memory_tree('branch')