24
24
import bzrlib.inventory as inventory
25
25
from bzrlib.osutils import has_symlinks, rename, pathjoin
26
26
from bzrlib.tests import TestCase, TestCaseWithTransport
27
from bzrlib.uncommit import uncommit
29
30
class TestInventory(TestCase):
139
140
self.wt = self.make_branch_and_tree('.')
140
141
self.branch = self.wt.branch
141
142
print >> open('file', 'wb'), 'foo'
143
print >> open('binfile', 'wb'), 'foo'
142
144
self.wt.add(['file'], ['fileid'])
145
self.wt.add(['binfile'], ['binfileid'])
143
146
if has_symlinks():
144
147
os.symlink('target1', 'symlink')
145
148
self.wt.add(['symlink'], ['linkid'])
146
149
self.wt.commit('message_1', rev_id = '1')
147
150
print >> open('file', 'wb'), 'bar'
151
print >> open('binfile', 'wb'), 'x' * 1023 + '\x00'
148
152
if has_symlinks():
149
153
os.unlink('symlink')
150
154
os.symlink('target2', 'symlink')
151
155
self.tree_1 = self.branch.repository.revision_tree('1')
152
156
self.inv_1 = self.branch.repository.get_inventory('1')
153
157
self.file_1 = self.inv_1['fileid']
158
self.file_1b = self.inv_1['binfileid']
154
159
self.tree_2 = self.wt
155
160
self.inv_2 = self.tree_2.read_working_inventory()
156
161
self.file_2 = self.inv_2['fileid']
162
self.file_2b = self.inv_2['binfileid']
157
163
if has_symlinks():
158
164
self.link_1 = self.inv_1['linkid']
159
165
self.link_2 = self.inv_2['linkid']
204
def test_file_diff_binary(self):
206
self.file_1.diff(internal_diff,
207
"/dev/null", self.tree_1,
208
"new_label", self.file_2b, self.tree_2,
210
self.assertEqual(output.getvalue(),
211
"Binary files /dev/null and new_label differ\n")
198
212
def test_link_diff_deleted(self):
199
213
if not has_symlinks():
339
353
self.wt.add(['file'], ['fileid'])
340
354
self.wt.commit('add file', rev_id='B')
341
355
self.inv_B = self.branch.repository.get_inventory('B')
342
self.branch.lock_write()
344
self.branch.control_files.put_utf8('revision-history', 'A\n')
356
uncommit(self.branch, tree=self.wt)
347
357
self.assertEqual(self.branch.revision_history(), ['A'])
348
358
self.wt.commit('another add of file', rev_id='C')
349
359
self.inv_C = self.branch.repository.get_inventory('C')
352
362
self.inv_D = self.branch.repository.get_inventory('D')
353
363
self.file_active = self.wt.inventory['fileid']
354
364
self.weave = self.branch.repository.weave_store.get_weave('fileid',
355
self.branch.get_transaction())
365
self.branch.repository.get_transaction())
357
367
def get_previous_heads(self, inventories):
358
return self.file_active.find_previous_heads(inventories, self.weave)
368
return self.file_active.find_previous_heads(
370
self.branch.repository.weave_store,
371
self.branch.repository.get_transaction())
360
373
def test_fileid_in_no_inventory(self):
361
374
self.assertEqual({}, self.get_previous_heads([self.inv_A]))
388
401
class TestExecutable(TestCaseWithTransport):
390
403
def test_stays_executable(self):
391
basic_inv = """<inventory format="5">
392
<file file_id="a-20051208024829-849e76f7968d7a86" name="a" executable="yes" />
393
<file file_id="b-20051208024829-849e76f7968d7a86" name="b" />
404
a_id = "a-20051208024829-849e76f7968d7a86"
405
b_id = "b-20051208024829-849e76f7968d7a86"
396
406
wt = self.make_branch_and_tree('b1')
398
408
open('b1/a', 'wb').write('a test\n')
399
409
open('b1/b', 'wb').write('b test\n')
400
410
os.chmod('b1/a', 0755)
401
411
os.chmod('b1/b', 0644)
402
# Manually writing the inventory, to ensure that
403
# the executable="yes" entry is set for 'a' and not for 'b'
404
open('b1/.bzr/inventory', 'wb').write(basic_inv)
412
wt.add(['a', 'b'], [a_id, b_id])
413
wt.inventory[a_id].executable = True
414
self.failUnless(wt.is_executable(a_id), "'a' lost the execute bit")
406
a_id = "a-20051208024829-849e76f7968d7a86"
407
b_id = "b-20051208024829-849e76f7968d7a86"
416
# reopen the tree and ensure it stuck.
408
417
wt = wt.bzrdir.open_workingtree()
409
418
self.assertEqual(['a', 'b'], [cn for cn,ie in wt.inventory.iter_entries()])