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.transform import TreeTransform
28
from bzrlib.uncommit import uncommit
29
31
class TestInventory(TestCase):
139
141
self.wt = self.make_branch_and_tree('.')
140
142
self.branch = self.wt.branch
141
143
print >> open('file', 'wb'), 'foo'
144
print >> open('binfile', 'wb'), 'foo'
142
145
self.wt.add(['file'], ['fileid'])
146
self.wt.add(['binfile'], ['binfileid'])
143
147
if has_symlinks():
144
148
os.symlink('target1', 'symlink')
145
149
self.wt.add(['symlink'], ['linkid'])
146
150
self.wt.commit('message_1', rev_id = '1')
147
151
print >> open('file', 'wb'), 'bar'
152
print >> open('binfile', 'wb'), 'x' * 1023 + '\x00'
148
153
if has_symlinks():
149
154
os.unlink('symlink')
150
155
os.symlink('target2', 'symlink')
151
156
self.tree_1 = self.branch.repository.revision_tree('1')
152
157
self.inv_1 = self.branch.repository.get_inventory('1')
153
158
self.file_1 = self.inv_1['fileid']
159
self.file_1b = self.inv_1['binfileid']
154
160
self.tree_2 = self.wt
155
161
self.inv_2 = self.tree_2.read_working_inventory()
156
162
self.file_2 = self.inv_2['fileid']
163
self.file_2b = self.inv_2['binfileid']
157
164
if has_symlinks():
158
165
self.link_1 = self.inv_1['linkid']
159
166
self.link_2 = self.inv_2['linkid']
205
def test_file_diff_binary(self):
207
self.file_1.diff(internal_diff,
208
"/dev/null", self.tree_1,
209
"new_label", self.file_2b, self.tree_2,
211
self.assertEqual(output.getvalue(),
212
"Binary files /dev/null and new_label differ\n")
198
213
def test_link_diff_deleted(self):
199
214
if not has_symlinks():
339
354
self.wt.add(['file'], ['fileid'])
340
355
self.wt.commit('add file', rev_id='B')
341
356
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')
357
uncommit(self.branch, tree=self.wt)
347
358
self.assertEqual(self.branch.revision_history(), ['A'])
348
359
self.wt.commit('another add of file', rev_id='C')
349
360
self.inv_C = self.branch.repository.get_inventory('C')
391
402
class TestExecutable(TestCaseWithTransport):
393
404
def test_stays_executable(self):
394
basic_inv = """<inventory format="5">
395
<file file_id="a-20051208024829-849e76f7968d7a86" name="a" executable="yes" />
396
<file file_id="b-20051208024829-849e76f7968d7a86" name="b" />
399
wt = self.make_branch_and_tree('b1')
401
open('b1/a', 'wb').write('a test\n')
402
open('b1/b', 'wb').write('b test\n')
403
os.chmod('b1/a', 0755)
404
os.chmod('b1/b', 0644)
405
# Manually writing the inventory, to ensure that
406
# the executable="yes" entry is set for 'a' and not for 'b'
407
open('b1/.bzr/inventory', 'wb').write(basic_inv)
409
405
a_id = "a-20051208024829-849e76f7968d7a86"
410
406
b_id = "b-20051208024829-849e76f7968d7a86"
407
wt = self.make_branch_and_tree('b1')
409
tt = TreeTransform(wt)
410
tt.new_file('a', tt.root, 'a test\n', a_id, True)
411
tt.new_file('b', tt.root, 'b test\n', b_id, False)
414
self.failUnless(wt.is_executable(a_id), "'a' lost the execute bit")
416
# reopen the tree and ensure it stuck.
411
417
wt = wt.bzrdir.open_workingtree()
412
418
self.assertEqual(['a', 'b'], [cn for cn,ie in wt.inventory.iter_entries()])