1
# Copyright (C) 2007 Canonical Ltd
1
# Copyright (C) 2007, 2008 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
26
26
from bzrlib.symbol_versioning import zero_ninetyone, one_zero
27
27
from bzrlib.tests import SymlinkFeature, TestSkipped
28
28
from bzrlib.tests.tree_implementations import TestCaseWithTree
29
from bzrlib.transform import _PreviewTree
29
30
from bzrlib.uncommit import uncommit
33
def get_entry(tree, file_id):
34
return tree.iter_entries_by_dir([file_id]).next()[1]
32
37
class TestEntryDiffing(TestCaseWithTree):
55
60
self.tree_2 = self.workingtree_to_test_tree(self.wt)
56
61
self.tree_2.lock_read()
57
62
self.addCleanup(self.tree_2.unlock)
58
self.inv_2 = self.tree_2.inventory
59
self.file_2 = self.inv_2['fileid']
60
self.file_2b = self.inv_2['binfileid']
63
self.file_2 = get_entry(self.tree_2, 'fileid')
64
self.file_2b = get_entry(self.tree_2, 'binfileid')
62
66
self.link_1 = self.inv_1['linkid']
63
self.link_2 = self.inv_2['linkid']
67
self.link_2 = get_entry(self.tree_2, 'linkid')
65
69
def test_file_diff_deleted(self):
66
70
output = StringIO()
113
117
"/dev/null", self.tree_1,
114
118
"new_label", self.file_2b, self.tree_2,
116
self.assertEqual(output.getvalue(),
120
self.assertEqual(output.getvalue(),
117
121
"Binary files /dev/null and new_label differ\n")
119
123
def test_link_diff_deleted(self):
182
186
self.tree = self.workingtree_to_test_tree(self.wt)
183
187
self.tree.lock_read()
184
188
self.addCleanup(self.tree.unlock)
185
self.file_active = self.tree.inventory['fileid']
189
self.file_active = get_entry(self.tree, 'fileid')
186
190
self.weave = self.branch.repository.weave_store.get_weave('fileid',
187
191
self.branch.repository.get_transaction())
189
193
def get_previous_heads(self, inventories):
190
194
return self.applyDeprecated(zero_ninetyone,
191
195
self.file_active.find_previous_heads,
193
197
self.branch.repository.weave_store,
194
198
self.branch.repository.get_transaction())
196
200
def test_fileid_in_no_inventory(self):
197
201
self.assertEqual({}, self.get_previous_heads([self.inv_A]))
218
222
self.assertEqual({'D':self.inv_D['fileid']},
219
223
self.get_previous_heads([self.inv_D, self.inv_B]))
221
# TODO: test two inventories with the same file revision
225
# TODO: test two inventories with the same file revision
224
228
class TestInventory(TestCaseWithTree):
227
231
self.tree = self.get_tree_with_subdirs_and_all_content_types()
228
232
self.tree.lock_read()
229
233
self.addCleanup(self.tree.unlock)
230
# Commenting out the following line still fails.
231
self.inv = self.tree.inventory
233
235
def test_symlink_target(self):
234
236
self.requireFeature(SymlinkFeature)
236
if isinstance(self.tree, MutableTree):
238
if isinstance(self.tree, (MutableTree, _PreviewTree)):
237
239
raise TestSkipped(
238
'symlinks not accurately represented in working trees')
239
entry = self.inv[self.inv.path2id('symlink')]
240
'symlinks not accurately represented in working trees and'
242
entry = get_entry(self.tree, self.tree.path2id('symlink'))
240
243
self.assertEqual(entry.symlink_target, 'link-target')
245
def test_symlink_target_tree(self):
246
self.requireFeature(SymlinkFeature)
248
self.assertEqual('link-target',
249
self.tree.get_symlink_target('symlink'))
251
def test_kind_symlink(self):
252
self.requireFeature(SymlinkFeature)
254
self.assertEqual('symlink', self.tree.kind('symlink'))
255
self.assertIs(None, self.tree.get_file_size('symlink'))
242
257
def test_symlink(self):
243
258
self.requireFeature(SymlinkFeature)
245
entry = self.inv[self.inv.path2id('symlink')]
260
entry = get_entry(self.tree, self.tree.path2id('symlink'))
246
261
self.assertEqual(entry.kind, 'symlink')
247
262
self.assertEqual(None, entry.text_size)