20
20
from bzrlib.branch import Branch
21
from bzrlib.clone import copy_branch
22
21
import bzrlib.errors as errors
23
22
from bzrlib.diff import internal_diff
24
23
from bzrlib.inventory import Inventory, ROOT_ID
25
24
import bzrlib.inventory as inventory
26
25
from bzrlib.osutils import has_symlinks, rename, pathjoin
27
from bzrlib.tests import TestCase, TestCaseInTempDir
26
from bzrlib.tests import TestCase, TestCaseWithTransport
27
from bzrlib.workingtree import WorkingTree
30
30
class TestInventory(TestCase):
133
133
self.failIf(link.has_text())
136
class TestEntryDiffing(TestCaseInTempDir):
136
class TestEntryDiffing(TestCaseWithTransport):
139
139
super(TestEntryDiffing, self).setUp()
140
self.branch = Branch.initialize(u'.')
141
self.wt = self.branch.working_tree()
140
self.wt = self.make_branch_and_tree('.')
141
self.branch = self.wt.branch
142
142
print >> open('file', 'wb'), 'foo'
143
self.branch.working_tree().add(['file'], ['fileid'])
143
self.wt.add(['file'], ['fileid'])
144
144
if has_symlinks():
145
145
os.symlink('target1', 'symlink')
146
self.branch.working_tree().add(['symlink'], ['linkid'])
146
self.wt.add(['symlink'], ['linkid'])
147
147
self.wt.commit('message_1', rev_id = '1')
148
148
print >> open('file', 'wb'), 'bar'
149
149
if has_symlinks():
150
150
os.unlink('symlink')
151
151
os.symlink('target2', 'symlink')
152
self.tree_1 = self.branch.revision_tree('1')
153
self.inv_1 = self.branch.get_inventory('1')
152
self.tree_1 = self.branch.repository.revision_tree('1')
153
self.inv_1 = self.branch.repository.get_inventory('1')
154
154
self.file_1 = self.inv_1['fileid']
155
155
self.tree_2 = self.branch.working_tree()
156
156
self.inv_2 = self.tree_2.read_working_inventory()
240
240
# to change, and then test merge patterns
241
241
# with fake parent entries.
242
242
super(TestSnapshot, self).setUp()
243
self.branch = Branch.initialize(u'.')
243
self.wt = self.make_branch_and_tree('.')
244
self.branch = self.wt.branch
244
245
self.build_tree(['subdir/', 'subdir/file'], line_endings='binary')
245
self.branch.working_tree().add(['subdir', 'subdir/file'],
246
self.wt.add(['subdir', 'subdir/file'],
246
247
['dirid', 'fileid'])
247
248
if has_symlinks():
249
self.wt = self.branch.working_tree()
250
250
self.wt.commit('message_1', rev_id = '1')
251
self.tree_1 = self.branch.revision_tree('1')
252
self.inv_1 = self.branch.get_inventory('1')
251
self.tree_1 = self.branch.repository.revision_tree('1')
252
self.inv_1 = self.branch.repository.get_inventory('1')
253
253
self.file_1 = self.inv_1['fileid']
254
self.work_tree = self.branch.working_tree()
255
self.file_active = self.work_tree.inventory['fileid']
254
self.file_active = self.wt.inventory['fileid']
257
256
def test_snapshot_new_revision(self):
258
257
# This tests that a simple commit with no parents makes a new
259
258
# revision value in the inventory entry
260
self.file_active.snapshot('2', 'subdir/file', {}, self.work_tree,
261
self.branch.weave_store,
259
self.file_active.snapshot('2', 'subdir/file', {}, self.wt,
260
self.branch.repository.weave_store,
262
261
self.branch.get_transaction())
263
262
# expected outcome - file_1 has a revision id of '2', and we can get
264
263
# its text of 'file contents' out of the weave.
265
264
self.assertEqual(self.file_1.revision, '1')
266
265
self.assertEqual(self.file_active.revision, '2')
267
266
# this should be a separate test probably, but lets check it once..
268
lines = self.branch.weave_store.get_lines('fileid','2',
267
lines = self.branch.repository.weave_store.get_lines('fileid','2',
269
268
self.branch.get_transaction())
270
269
self.assertEqual(lines, ['contents of subdir/file\n'])
273
272
#This tests that a simple commit does not make a new entry for
274
273
# an unchanged inventory entry
275
274
self.file_active.snapshot('2', 'subdir/file', {'1':self.file_1},
276
self.work_tree, self.branch.weave_store,
276
self.branch.repository.weave_store,
277
277
self.branch.get_transaction())
278
278
self.assertEqual(self.file_1.revision, '1')
279
279
self.assertEqual(self.file_active.revision, '1')
280
280
self.assertRaises(errors.WeaveError,
281
self.branch.weave_store.get_lines, 'fileid', '2',
282
self.branch.get_transaction())
281
self.branch.repository.weave_store.get_lines,
282
'fileid', '2', self.branch.get_transaction())
284
284
def test_snapshot_merge_identical_different_revid(self):
285
285
# This tests that a commit with two identical parents, one of which has
293
293
self.assertEqual(self.file_1, other_ie)
294
294
other_ie.revision = 'other'
295
295
self.assertNotEqual(self.file_1, other_ie)
296
self.branch.weave_store.add_identical_text('fileid', '1', 'other', ['1'],
297
self.branch.get_transaction())
296
self.branch.repository.weave_store.add_identical_text('fileid', '1',
297
'other', ['1'], self.branch.get_transaction())
298
298
self.file_active.snapshot('2', 'subdir/file',
299
299
{'1':self.file_1, 'other':other_ie},
300
self.work_tree, self.branch.weave_store,
301
self.branch.repository.weave_store,
301
302
self.branch.get_transaction())
302
303
self.assertEqual(self.file_active.revision, '2')
307
308
self.file_active.name='newname'
308
309
rename('subdir/file', 'subdir/newname')
309
310
self.file_active.snapshot('2', 'subdir/newname', {'1':self.file_1},
311
self.branch.weave_store,
312
self.branch.repository.weave_store,
312
313
self.branch.get_transaction())
313
314
# expected outcome - file_1 has a revision id of '2'
314
315
self.assertEqual(self.file_active.revision, '2')
317
class TestPreviousHeads(TestCaseInTempDir):
318
class TestPreviousHeads(TestCaseWithTransport):
320
321
# we want several inventories, that respectively
326
327
# D) fileid present in two inventories and one is
327
328
# a descendent of the other. (B, D)
328
329
super(TestPreviousHeads, self).setUp()
330
self.wt = self.make_branch_and_tree('.')
331
self.branch = self.wt.branch
329
332
self.build_tree(['file'])
330
self.branch = Branch.initialize(u'.')
331
self.wt = self.branch.working_tree()
332
333
self.wt.commit('new branch', allow_pointless=True, rev_id='A')
333
self.inv_A = self.branch.get_inventory('A')
334
self.branch.working_tree().add(['file'], ['fileid'])
334
self.inv_A = self.branch.repository.get_inventory('A')
335
self.wt.add(['file'], ['fileid'])
335
336
self.wt.commit('add file', rev_id='B')
336
self.inv_B = self.branch.get_inventory('B')
337
self.branch.put_controlfile('revision-history', 'A\n')
337
self.inv_B = self.branch.repository.get_inventory('B')
338
self.branch.lock_write()
340
self.branch.control_files.put_utf8('revision-history', 'A\n')
338
343
self.assertEqual(self.branch.revision_history(), ['A'])
339
344
self.wt.commit('another add of file', rev_id='C')
340
self.inv_C = self.branch.get_inventory('C')
345
self.inv_C = self.branch.repository.get_inventory('C')
341
346
self.wt.add_pending_merge('B')
342
347
self.wt.commit('merge in B', rev_id='D')
343
self.inv_D = self.branch.get_inventory('D')
344
self.file_active = self.wt.inventory['fileid']
345
self.weave = self.branch.weave_store.get_weave('fileid',
348
self.inv_D = self.branch.repository.get_inventory('D')
349
self.file_active = self.branch.working_tree().inventory['fileid']
350
self.weave = self.branch.repository.weave_store.get_weave('fileid',
346
351
self.branch.get_transaction())
348
353
def get_previous_heads(self, inventories):
405
410
t.commit('adding a,b', rev_id='r1')
407
rev_tree = b.revision_tree('r1')
412
rev_tree = b.repository.revision_tree('r1')
408
413
self.failUnless(rev_tree.is_executable(a_id), "'a' lost the execute bit")
409
414
self.failIf(rev_tree.is_executable(b_id), "'b' gained an execute bit")
422
427
# Make sure that revert is able to bring them back,
423
428
# and sets 'a' back to being executable
425
t.revert(['b1/a', 'b1/b'], rev_tree, backups=False)
430
t.revert(['a', 'b'], rev_tree, backups=False)
426
431
self.assertEqual(['a', 'b'], [cn for cn,ie in t.inventory.iter_entries()])
428
433
self.failUnless(t.is_executable(a_id), "'a' lost the execute bit")
458
463
# Now make sure that 'bzr branch' also preserves the
460
465
# TODO: Maybe this should be a blackbox test
461
from bzrlib.clone import copy_branch
462
copy_branch(b, 'b2', revision='r1')
466
b.clone('b2', revision='r1')
463
467
b2 = Branch.open('b2')
464
468
self.assertEquals('r1', b2.last_revision())
465
469
t2 = b2.working_tree()