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
24
24
from bzrlib.mutabletree import MutableTree
25
25
from bzrlib.osutils import has_symlinks
26
26
from bzrlib.symbol_versioning import zero_ninetyone, one_zero
27
from bzrlib.tests import SymlinkFeature, TestSkipped, TestNotApplicable
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
32
def get_inventory_if_applicable(tree):
35
except NotImplementedError:
36
raise TestNotApplicable('Tree does not implement inventory')
33
def get_entry(tree, file_id):
34
return tree.iter_entries_by_dir([file_id]).next()[1]
39
37
class TestEntryDiffing(TestCaseWithTree):
62
60
self.tree_2 = self.workingtree_to_test_tree(self.wt)
63
61
self.tree_2.lock_read()
64
62
self.addCleanup(self.tree_2.unlock)
65
self.inv_2 = get_inventory_if_applicable(self.tree_2)
66
self.file_2 = self.inv_2['fileid']
67
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')
69
66
self.link_1 = self.inv_1['linkid']
70
self.link_2 = self.inv_2['linkid']
67
self.link_2 = get_entry(self.tree_2, 'linkid')
72
69
def test_file_diff_deleted(self):
73
70
output = StringIO()
120
117
"/dev/null", self.tree_1,
121
118
"new_label", self.file_2b, self.tree_2,
123
self.assertEqual(output.getvalue(),
120
self.assertEqual(output.getvalue(),
124
121
"Binary files /dev/null and new_label differ\n")
126
123
def test_link_diff_deleted(self):
189
186
self.tree = self.workingtree_to_test_tree(self.wt)
190
187
self.tree.lock_read()
191
188
self.addCleanup(self.tree.unlock)
192
self.file_active = get_inventory_if_applicable(self.tree)['fileid']
189
self.file_active = get_entry(self.tree, 'fileid')
193
190
self.weave = self.branch.repository.weave_store.get_weave('fileid',
194
191
self.branch.repository.get_transaction())
196
193
def get_previous_heads(self, inventories):
197
194
return self.applyDeprecated(zero_ninetyone,
198
195
self.file_active.find_previous_heads,
200
197
self.branch.repository.weave_store,
201
198
self.branch.repository.get_transaction())
203
200
def test_fileid_in_no_inventory(self):
204
201
self.assertEqual({}, self.get_previous_heads([self.inv_A]))
225
222
self.assertEqual({'D':self.inv_D['fileid']},
226
223
self.get_previous_heads([self.inv_D, self.inv_B]))
228
# TODO: test two inventories with the same file revision
225
# TODO: test two inventories with the same file revision
231
228
class TestInventory(TestCaseWithTree):
234
231
self.tree = self.get_tree_with_subdirs_and_all_content_types()
235
232
self.tree.lock_read()
236
233
self.addCleanup(self.tree.unlock)
237
# Commenting out the following line still fails.
238
self.inv = get_inventory_if_applicable(self.tree)
240
235
def test_symlink_target(self):
241
236
self.requireFeature(SymlinkFeature)
243
if isinstance(self.tree, MutableTree):
238
if isinstance(self.tree, (MutableTree, _PreviewTree)):
244
239
raise TestSkipped(
245
'symlinks not accurately represented in working trees')
246
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'))
247
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'))
249
257
def test_symlink(self):
250
258
self.requireFeature(SymlinkFeature)
252
entry = self.inv[self.inv.path2id('symlink')]
260
entry = get_entry(self.tree, self.tree.path2id('symlink'))
253
261
self.assertEqual(entry.kind, 'symlink')
254
262
self.assertEqual(None, entry.text_size)