23
23
from bzrlib.inventory import Inventory, ROOT_ID
24
24
import bzrlib.inventory as inventory
25
25
from bzrlib.osutils import has_symlinks, rename, pathjoin
26
from bzrlib.tests import TestCase, TestCaseInTempDir
26
from bzrlib.tests import TestCase, TestCaseWithTransport
27
from bzrlib.workingtree import WorkingTree
29
30
class TestInventory(TestCase):
132
133
self.failIf(link.has_text())
135
class TestEntryDiffing(TestCaseInTempDir):
136
class TestEntryDiffing(TestCaseWithTransport):
138
139
super(TestEntryDiffing, self).setUp()
139
self.branch = Branch.initialize(u'.')
140
self.wt = self.branch.working_tree()
140
self.wt = self.make_branch_and_tree('.')
141
self.branch = self.wt.branch
141
142
print >> open('file', 'wb'), 'foo'
142
self.branch.working_tree().add(['file'], ['fileid'])
143
self.wt.add(['file'], ['fileid'])
143
144
if has_symlinks():
144
145
os.symlink('target1', 'symlink')
145
self.branch.working_tree().add(['symlink'], ['linkid'])
146
self.wt.add(['symlink'], ['linkid'])
146
147
self.wt.commit('message_1', rev_id = '1')
147
148
print >> open('file', 'wb'), 'bar'
148
149
if has_symlinks():
239
240
# to change, and then test merge patterns
240
241
# with fake parent entries.
241
242
super(TestSnapshot, self).setUp()
242
self.branch = Branch.initialize(u'.')
243
self.wt = self.make_branch_and_tree('.')
244
self.branch = self.wt.branch
243
245
self.build_tree(['subdir/', 'subdir/file'], line_endings='binary')
244
self.branch.working_tree().add(['subdir', 'subdir/file'],
246
self.wt.add(['subdir', 'subdir/file'],
245
247
['dirid', 'fileid'])
246
248
if has_symlinks():
248
self.wt = self.branch.working_tree()
249
250
self.wt.commit('message_1', rev_id = '1')
250
251
self.tree_1 = self.branch.repository.revision_tree('1')
251
252
self.inv_1 = self.branch.repository.get_inventory('1')
252
253
self.file_1 = self.inv_1['fileid']
253
self.work_tree = self.branch.working_tree()
254
self.file_active = self.work_tree.inventory['fileid']
254
self.file_active = self.wt.inventory['fileid']
256
256
def test_snapshot_new_revision(self):
257
257
# This tests that a simple commit with no parents makes a new
258
258
# revision value in the inventory entry
259
self.file_active.snapshot('2', 'subdir/file', {}, self.work_tree,
259
self.file_active.snapshot('2', 'subdir/file', {}, self.wt,
260
260
self.branch.repository.weave_store,
261
261
self.branch.get_transaction())
262
262
# expected outcome - file_1 has a revision id of '2', and we can get
272
272
#This tests that a simple commit does not make a new entry for
273
273
# an unchanged inventory entry
274
274
self.file_active.snapshot('2', 'subdir/file', {'1':self.file_1},
276
276
self.branch.repository.weave_store,
277
277
self.branch.get_transaction())
278
278
self.assertEqual(self.file_1.revision, '1')
297
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},
301
301
self.branch.repository.weave_store,
302
302
self.branch.get_transaction())
303
303
self.assertEqual(self.file_active.revision, '2')
308
308
self.file_active.name='newname'
309
309
rename('subdir/file', 'subdir/newname')
310
310
self.file_active.snapshot('2', 'subdir/newname', {'1':self.file_1},
312
312
self.branch.repository.weave_store,
313
313
self.branch.get_transaction())
314
314
# expected outcome - file_1 has a revision id of '2'
315
315
self.assertEqual(self.file_active.revision, '2')
318
class TestPreviousHeads(TestCaseInTempDir):
318
class TestPreviousHeads(TestCaseWithTransport):
321
321
# we want several inventories, that respectively
327
327
# D) fileid present in two inventories and one is
328
328
# a descendent of the other. (B, D)
329
329
super(TestPreviousHeads, self).setUp()
330
self.wt = self.make_branch_and_tree('.')
331
self.branch = self.wt.branch
330
332
self.build_tree(['file'])
331
self.branch = Branch.initialize(u'.')
332
self.wt = self.branch.working_tree()
333
333
self.wt.commit('new branch', allow_pointless=True, rev_id='A')
334
334
self.inv_A = self.branch.repository.get_inventory('A')
335
335
self.wt.add(['file'], ['fileid'])
381
381
# TODO: test two inventories with the same file revision
384
class TestExecutable(TestCaseInTempDir):
384
class TestExecutable(TestCaseWithTransport):
386
386
def test_stays_executable(self):
387
387
basic_inv = """<inventory format="5">
389
389
<file file_id="b-20051208024829-849e76f7968d7a86" name="b" />
393
b = Branch.initialize('b1')
392
wt = self.make_branch_and_tree('b1')
394
394
open('b1/a', 'wb').write('a test\n')
395
395
open('b1/b', 'wb').write('b test\n')
396
396
os.chmod('b1/a', 0755)
402
402
a_id = "a-20051208024829-849e76f7968d7a86"
403
403
b_id = "b-20051208024829-849e76f7968d7a86"
404
t = WorkingTree('b1', b)
405
405
self.assertEqual(['a', 'b'], [cn for cn,ie in t.inventory.iter_entries()])
407
407
self.failUnless(t.is_executable(a_id), "'a' lost the execute bit")