33
33
"""Check that the tree has the correct layout."""
34
34
self.assertThat(tree, HasLayout(expected))
36
def assertPathRelations(self, previous_tree, tree, relations):
37
self.assertThat(tree, HasPathRelations(previous_tree, relations))
36
39
def test_add_one(self):
37
40
tree = self.make_branch_and_tree('.')
38
41
self.build_tree(['one'])
40
root_id = tree.get_root_id()
42
self.assertTreeLayout(
43
[('', root_id), ('one', tree.path2id('one'))], tree)
44
self.assertTreeLayout(['', 'one'], tree)
45
46
def test_add_existing_id(self):
46
47
"""Adding an entry with a pre-existing id raises DuplicateFileId"""
52
53
self.assertRaises(errors.DuplicateFileId,
53
54
tree.add, ['b'], [tree.path2id('a')])
54
root_id = tree.get_root_id()
55
55
# And the entry should not have been added.
56
self.assertTreeLayout([('', root_id), ('a', tree.path2id('a'))], tree)
56
self.assertTreeLayout(['', 'a'], tree)
58
58
def test_add_old_id(self):
59
59
"""We can add an old id, as long as it doesn't exist now."""
65
65
file_id = tree.path2id('a')
66
66
tree.commit('first')
67
root_id = tree.get_root_id()
68
67
# And the entry should not have been added.
69
68
tree.unversion(['a'])
70
69
tree.add(['b'], [file_id])
71
self.assertTreeLayout([('', root_id), ('b', file_id)], tree)
72
self.assertTreeLayout([('', root_id), ('a', file_id)],
70
self.assertPathRelations(
71
tree.basis_tree(), tree,
72
[('', ''), ('b', 'a')])
75
74
def test_add_one_list(self):
76
75
tree = self.make_branch_and_tree('.')
77
76
self.build_tree(['one'])
79
root_id = tree.get_root_id()
81
self.assertTreeLayout(
82
[('', root_id), ('one', tree.path2id('one'))], tree)
79
self.assertTreeLayout(['', 'one'], tree)
84
81
def test_add_one_new_id(self):
85
82
tree = self.make_branch_and_tree('.')
86
83
self.build_tree(['one'])
88
root_id = tree.get_root_id()
89
one_id = tree.path2id('one')
91
self.assertTreeLayout([('', root_id), ('one', one_id)], tree)
86
self.assertTreeLayout(['', 'one'], tree)
93
88
def test_add_unicode(self):
94
89
tree = self.make_branch_and_tree('.')
97
92
except UnicodeError:
98
93
raise tests.TestSkipped('Filesystem does not support filename.')
99
94
tree.add([u'f\xf6'])
100
root_id = tree.get_root_id()
101
foo_id = tree.path2id(u'f\xf6')
103
self.assertTreeLayout([('', root_id), (u'f\xf6', foo_id)], tree)
96
self.assertTreeLayout(['', u'f\xf6'], tree)
105
98
def test_add_subdir_with_ids(self):
106
99
tree = self.make_branch_and_tree('.')
122
115
tree.add(['dir'])
123
116
tree.add(['dir/subdir'])
124
117
tree.add(['dir/subdir/foo'])
125
root_id = tree.get_root_id()
127
self.assertTreeLayout([
129
('dir/', tree.path2id('dir')),
130
('dir/subdir/', tree.path2id('dir/subdir')),
131
('dir/subdir/foo', tree.path2id('dir/subdir/foo'))],
119
self.assertTreeLayout(
120
['', 'dir/', 'dir/subdir/', 'dir/subdir/foo'], tree)
134
122
def test_add_multiple(self):
135
123
tree = self.make_branch_and_tree('.')
136
124
self.build_tree(['a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo'])
137
125
tree.add(['a', 'b', 'dir', 'dir/subdir', 'dir/subdir/foo'])
138
root_id = tree.get_root_id()
140
self.assertTreeLayout([
142
for p in ['', 'a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo']],
127
self.assertTreeLayout(
128
['', 'a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo'],
145
131
def test_add_multiple_with_file_ids(self):
149
135
self.build_tree(['a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo'])
150
136
tree.add(['a', 'b', 'dir', 'dir/subdir', 'dir/subdir/foo'],
151
137
['a-id', 'b-id', 'dir-id', 'subdir-id', 'foo-id'])
152
root_id = tree.get_root_id()
154
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
139
self.assertTreeLayout([('', tree.get_root_id()), ('a', 'a-id'), ('b', 'b-id'),
155
140
('dir/', 'dir-id'), ('dir/subdir/', 'subdir-id'),
156
141
('dir/subdir/foo', 'foo-id')], tree)
158
143
def test_add_invalid(self):
159
144
tree = self.make_branch_and_tree('.')
145
if not tree._format.supports_versioned_directories:
146
raise tests.TestNotApplicable(
147
'format does not support versioned directories')
160
148
self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
161
root_id = tree.get_root_id()
163
150
self.assertRaises(errors.NotVersionedError,
164
151
tree.add, ['dir/subdir'])
165
self.assertTreeLayout([('', root_id)], tree)
152
self.assertTreeLayout([''], tree)
167
154
def test_add_after_remove(self):
168
155
tree = self.make_branch_and_tree('.')
156
if not tree._format.supports_versioned_directories:
157
raise tests.TestNotApplicable(
158
'format does not support versioned directories')
169
159
self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
170
root_id = tree.get_root_id()
171
160
tree.add(['dir'])
172
161
tree.commit('dir')
173
162
tree.unversion(['dir'])
174
163
self.assertRaises(errors.NotVersionedError,
175
tree.add, ['dir/subdir'])
164
tree.add, ['dir/subdir/foo'])
177
166
def test_add_root(self):
178
167
# adding the root should be a no-op, or at least not
179
168
# do anything whacky.
180
169
tree = self.make_branch_and_tree('.')
183
self.assertEqual([''], list(tree.all_versioned_paths()))
184
# the root should have been changed to be a new unique root.
185
self.assertNotEqual(inventory.ROOT_ID, tree.path2id(''))
170
with tree.lock_write():
172
self.assertEqual([''], list(tree.all_versioned_paths()))
173
# the root should have been changed to be a new unique root.
174
if tree._format.supports_setting_file_ids:
175
self.assertNotEqual(inventory.ROOT_ID, tree.path2id(''))
188
177
def test_add_previously_added(self):
189
178
# adding a path that was previously added should work