1
# Copyright (C) 2007 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Tests for interface conformance of 'WorkingTree.add'"""
26
from bzrlib.workingtree_4 import WorkingTreeFormat4
27
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
30
class TestAdd(TestCaseWithWorkingTree):
32
def get_tree_layout(self, tree):
33
"""Get the (path, file_id) pairs for the current tree."""
36
return [(path, ie.file_id) for path, ie
37
in tree.iter_entries_by_dir()]
41
def assertTreeLayout(self, expected, tree):
42
"""Check that the tree has the correct layout."""
43
actual = self.get_tree_layout(tree)
44
self.assertEqual(expected, actual)
46
def test_add_one(self):
47
tree = self.make_branch_and_tree('.')
48
self.build_tree(['one'])
49
tree.add('one', 'one-id')
50
root_id = tree.get_root_id()
52
self.assertTreeLayout([('', root_id), ('one', 'one-id')], tree)
54
def test_add_one_list(self):
55
tree = self.make_branch_and_tree('.')
56
self.build_tree(['one'])
57
tree.add(['one'], ['one-id'])
58
root_id = tree.get_root_id()
60
self.assertTreeLayout([('', root_id), ('one', 'one-id')], tree)
62
def test_add_one_new_id(self):
63
tree = self.make_branch_and_tree('.')
64
self.build_tree(['one'])
66
root_id = tree.get_root_id()
67
one_id = tree.path2id('one')
69
self.assertTreeLayout([('', root_id), ('one', one_id)], tree)
71
def test_add_unicode(self):
72
tree = self.make_branch_and_tree('.')
74
self.build_tree([u'f\xf6'])
76
raise tests.TestSkipped('Filesystem does not support filename.')
78
root_id = tree.get_root_id()
79
foo_id = tree.path2id(u'f\xf6')
81
self.assertTreeLayout([('', root_id), (u'f\xf6', foo_id)], tree)
83
def test_add_subdir(self):
84
tree = self.make_branch_and_tree('.')
85
self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
86
tree.add(['dir'], ['dir-id'])
87
tree.add(['dir/subdir'], ['subdir-id'])
88
tree.add(['dir/subdir/foo'], ['foo-id'])
89
root_id = tree.get_root_id()
91
self.assertTreeLayout([('', root_id), ('dir', 'dir-id'),
92
('dir/subdir', 'subdir-id'),
93
('dir/subdir/foo', 'foo-id')], tree)
95
def test_add_multiple(self):
96
tree = self.make_branch_and_tree('.')
97
self.build_tree(['a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo'])
98
tree.add(['a', 'b', 'dir', 'dir/subdir', 'dir/subdir/foo'],
99
['a-id', 'b-id', 'dir-id', 'subdir-id', 'foo-id'])
100
root_id = tree.get_root_id()
102
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
103
('dir', 'dir-id'), ('dir/subdir', 'subdir-id'),
104
('dir/subdir/foo', 'foo-id')], tree)
106
def test_add_invalid(self):
107
tree = self.make_branch_and_tree('.')
108
self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
109
root_id = tree.get_root_id()
111
self.assertRaises(errors.NotVersionedError,
112
tree.add, ['dir/subdir'])
113
self.assertTreeLayout([('', root_id)], tree)
115
def test_add_after_remove(self):
116
tree = self.make_branch_and_tree('.')
117
self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
118
root_id = tree.get_root_id()
119
tree.add(['dir'], ['dir-id'])
120
tree.commit('dir', rev_id='rev-1')
121
tree.unversion(['dir-id'])
122
self.assertRaises(errors.NotVersionedError,
123
tree.add, ['dir/subdir'])