24
24
from bzrlib.inventory import Inventory, ROOT_ID
25
25
import bzrlib.inventory as inventory
26
26
from bzrlib.osutils import has_symlinks, rename
27
from bzrlib.selftest import TestCase, TestCaseInTempDir
27
from bzrlib.tests import TestCase, TestCaseInTempDir
30
30
class TestInventory(TestCase):
139
139
super(TestEntryDiffing, self).setUp()
140
self.branch = Branch.initialize('.')
140
self.branch = Branch.initialize(u'.')
141
self.wt = self.branch.working_tree()
141
142
print >> open('file', 'wb'), 'foo'
142
self.branch.add(['file'], ['fileid'])
143
self.branch.working_tree().add(['file'], ['fileid'])
143
144
if has_symlinks():
144
145
os.symlink('target1', 'symlink')
145
self.branch.add(['symlink'], ['linkid'])
146
self.branch.commit('message_1', rev_id = '1')
146
self.branch.working_tree().add(['symlink'], ['linkid'])
147
self.wt.commit('message_1', rev_id = '1')
147
148
print >> open('file', 'wb'), 'bar'
148
149
if has_symlinks():
149
150
os.unlink('symlink')
152
153
self.inv_1 = self.branch.get_inventory('1')
153
154
self.file_1 = self.inv_1['fileid']
154
155
self.tree_2 = self.branch.working_tree()
155
self.inv_2 = self.branch.inventory
156
self.inv_2 = self.tree_2.read_working_inventory()
156
157
self.file_2 = self.inv_2['fileid']
157
158
if has_symlinks():
158
159
self.link_1 = self.inv_1['linkid']
164
165
"old_label", self.tree_1,
165
166
"/dev/null", None, None,
167
self.assertEqual(output.getvalue(), "--- old_label\n"
168
self.assertEqual(output.getvalue(), "--- old_label\t\n"
169
170
"@@ -1,1 +0,0 @@\n"
176
177
"new_label", self.tree_1,
177
178
"/dev/null", None, None,
178
179
output, reverse=True)
179
self.assertEqual(output.getvalue(), "--- /dev/null\n"
180
self.assertEqual(output.getvalue(), "--- /dev/null\t\n"
181
182
"@@ -0,0 +1,1 @@\n"
188
189
"/dev/null", self.tree_1,
189
190
"new_label", self.file_2, self.tree_2,
191
self.assertEqual(output.getvalue(), "--- /dev/null\n"
192
self.assertEqual(output.getvalue(), "--- /dev/null\t\n"
193
194
"@@ -1,1 +1,1 @@\n"
198
199
def test_link_diff_deleted(self):
200
if not has_symlinks():
199
202
output = StringIO()
200
203
self.link_1.diff(internal_diff,
201
204
"old_label", self.tree_1,
205
208
"=== target was 'target1'\n")
207
210
def test_link_diff_added(self):
211
if not has_symlinks():
208
213
output = StringIO()
209
214
self.link_1.diff(internal_diff,
210
215
"new_label", self.tree_1,
214
219
"=== target is 'target1'\n")
216
221
def test_link_diff_changed(self):
222
if not has_symlinks():
217
224
output = StringIO()
218
225
self.link_1.diff(internal_diff,
219
226
"/dev/null", self.tree_1,
233
240
# to change, and then test merge patterns
234
241
# with fake parent entries.
235
242
super(TestSnapshot, self).setUp()
236
self.branch = Branch.initialize('.')
237
self.build_tree(['subdir/', 'subdir/file'])
238
self.branch.add(['subdir', 'subdir/file'], ['dirid', 'fileid'])
243
self.branch = Branch.initialize(u'.')
244
self.build_tree(['subdir/', 'subdir/file'], line_endings='binary')
245
self.branch.working_tree().add(['subdir', 'subdir/file'],
239
247
if has_symlinks():
241
self.branch.commit('message_1', rev_id = '1')
249
self.wt = self.branch.working_tree()
250
self.wt.commit('message_1', rev_id = '1')
242
251
self.tree_1 = self.branch.revision_tree('1')
243
252
self.inv_1 = self.branch.get_inventory('1')
244
253
self.file_1 = self.inv_1['fileid']
249
258
# This tests that a simple commit with no parents makes a new
250
259
# revision value in the inventory entry
251
260
self.file_active.snapshot('2', 'subdir/file', {}, self.work_tree,
252
self.branch.weave_store)
261
self.branch.weave_store,
262
self.branch.get_transaction())
253
263
# expected outcome - file_1 has a revision id of '2', and we can get
254
264
# its text of 'file contents' out of the weave.
255
265
self.assertEqual(self.file_1.revision, '1')
256
266
self.assertEqual(self.file_active.revision, '2')
257
267
# this should be a separate test probably, but lets check it once..
258
lines = self.branch.weave_store.get_lines('fileid','2')
268
lines = self.branch.weave_store.get_lines('fileid','2',
269
self.branch.get_transaction())
259
270
self.assertEqual(lines, ['contents of subdir/file\n'])
261
272
def test_snapshot_unchanged(self):
262
273
#This tests that a simple commit does not make a new entry for
263
274
# an unchanged inventory entry
264
275
self.file_active.snapshot('2', 'subdir/file', {'1':self.file_1},
265
self.work_tree, self.branch.weave_store)
276
self.work_tree, self.branch.weave_store,
277
self.branch.get_transaction())
266
278
self.assertEqual(self.file_1.revision, '1')
267
279
self.assertEqual(self.file_active.revision, '1')
268
280
self.assertRaises(errors.WeaveError,
269
self.branch.weave_store.get_lines, 'fileid', '2')
281
self.branch.weave_store.get_lines, 'fileid', '2',
282
self.branch.get_transaction())
271
284
def test_snapshot_merge_identical_different_revid(self):
272
285
# This tests that a commit with two identical parents, one of which has
280
293
self.assertEqual(self.file_1, other_ie)
281
294
other_ie.revision = 'other'
282
295
self.assertNotEqual(self.file_1, other_ie)
283
self.branch.weave_store.add_identical_text('fileid', '1', 'other', ['1'])
296
self.branch.weave_store.add_identical_text('fileid', '1', 'other', ['1'],
297
self.branch.get_transaction())
284
298
self.file_active.snapshot('2', 'subdir/file',
285
299
{'1':self.file_1, 'other':other_ie},
286
self.work_tree, self.branch.weave_store)
300
self.work_tree, self.branch.weave_store,
301
self.branch.get_transaction())
287
302
self.assertEqual(self.file_active.revision, '2')
289
304
def test_snapshot_changed(self):
293
308
rename('subdir/file', 'subdir/newname')
294
309
self.file_active.snapshot('2', 'subdir/newname', {'1':self.file_1},
296
self.branch.weave_store)
311
self.branch.weave_store,
312
self.branch.get_transaction())
297
313
# expected outcome - file_1 has a revision id of '2'
298
314
self.assertEqual(self.file_active.revision, '2')
311
327
# a descendent of the other. (B, D)
312
328
super(TestPreviousHeads, self).setUp()
313
329
self.build_tree(['file'])
314
self.branch = Branch.initialize('.')
315
self.branch.commit('new branch', allow_pointless=True, rev_id='A')
330
self.branch = Branch.initialize(u'.')
331
self.wt = self.branch.working_tree()
332
self.wt.commit('new branch', allow_pointless=True, rev_id='A')
316
333
self.inv_A = self.branch.get_inventory('A')
317
self.branch.add(['file'], ['fileid'])
318
self.branch.commit('add file', rev_id='B')
334
self.branch.working_tree().add(['file'], ['fileid'])
335
self.wt.commit('add file', rev_id='B')
319
336
self.inv_B = self.branch.get_inventory('B')
320
337
self.branch.put_controlfile('revision-history', 'A\n')
321
338
self.assertEqual(self.branch.revision_history(), ['A'])
322
self.branch.commit('another add of file', rev_id='C')
339
self.wt.commit('another add of file', rev_id='C')
323
340
self.inv_C = self.branch.get_inventory('C')
324
self.branch.add_pending_merge('B')
325
self.branch.commit('merge in B', rev_id='D')
341
self.wt.add_pending_merge('B')
342
self.wt.commit('merge in B', rev_id='D')
326
343
self.inv_D = self.branch.get_inventory('D')
327
self.file_active = self.branch.working_tree().inventory['fileid']
328
self.weave = self.branch.weave_store.get_weave('fileid')
344
self.file_active = self.wt.inventory['fileid']
345
self.weave = self.branch.weave_store.get_weave('fileid',
346
self.branch.get_transaction())
330
348
def get_previous_heads(self, inventories):
331
349
return self.file_active.find_previous_heads(inventories, self.weave)