124
124
self.wt, self.builder)
125
125
# expected outcome - file_1 has a revision id of '2'
126
126
self.assertEqual(self.file_active.revision, '2')
129
class TestApplyInventoryDelta(TestCaseWithWorkingTree):
132
wt = self.make_branch_and_tree('.')
134
self.addCleanup(wt.unlock)
135
root_id = wt.get_root_id()
136
wt.apply_inventory_delta([(None, 'bar/foo', 'foo-id',
137
inventory.InventoryFile('foo-id', 'foo', parent_id='bar-id')),
138
(None, 'bar', 'bar-id', inventory.InventoryDirectory('bar-id',
139
'bar', parent_id=root_id))])
140
self.assertEqual('bar/foo', wt.inventory.id2path('foo-id'))
141
self.assertEqual('bar', wt.inventory.id2path('bar-id'))
143
def test_remove(self):
144
wt = self.make_branch_and_tree('.')
146
self.addCleanup(wt.unlock)
147
self.build_tree(['foo/', 'foo/bar'])
148
wt.add(['foo', 'foo/bar'], ['foo-id', 'bar-id'])
149
wt.apply_inventory_delta([('foo', None, 'foo-id', None),
150
('foo/bar', None, 'bar-id', None)])
151
self.assertIs(None, wt.path2id('foo'))
153
def test_rename_file(self):
154
wt = self.make_branch_and_tree('.')
156
root_id = wt.get_root_id()
157
self.addCleanup(wt.unlock)
158
self.build_tree(['foo/', 'foo/bar', 'baz/'])
159
wt.add(['foo', 'foo/bar', 'baz'],
160
['foo-id', 'bar-id', 'baz-id'])
161
wt.apply_inventory_delta([('foo/bar', 'baz/bar', 'bar-id',
162
inventory.InventoryFile('bar-id', 'bar', 'baz-id'))])
163
self.assertEqual('baz/bar', wt.id2path('bar-id'))
165
def test_rename_swap(self):
166
"""Test the swap-names edge case.
168
foo and bar should swap names, but retain their children. If this
169
works, any simpler rename ought to work.
171
wt = self.make_branch_and_tree('.')
173
root_id = wt.get_root_id()
174
self.addCleanup(wt.unlock)
175
self.build_tree(['foo/', 'foo/bar', 'baz/', 'baz/qux'])
176
wt.add(['foo', 'foo/bar', 'baz', 'baz/qux'],
177
['foo-id', 'bar-id', 'baz-id', 'qux-id'])
178
wt.apply_inventory_delta([('foo', 'baz', 'foo-id',
179
inventory.InventoryDirectory('foo-id', 'baz', root_id)),
180
('baz', 'foo', 'baz-id',
181
inventory.InventoryDirectory('baz-id', 'foo', root_id))])
182
self.assertEqual('baz/bar', wt.id2path('bar-id'))
183
self.assertEqual('foo/qux', wt.id2path('qux-id'))
185
def test_child_rename_ordering(self):
186
"""Test the rename-parent, move child edge case.
188
(A naive implementation may move the parent first, and then be
189
unable to find the child.)
191
wt = self.make_branch_and_tree('.')
192
root_id = wt.get_root_id()
193
self.build_tree(['dir/', 'dir/child', 'other/'])
194
wt.add(['dir', 'dir/child', 'other'],
195
['dir-id', 'child-id', 'other-id'])
196
wt.apply_inventory_delta([('dir', 'dir2', 'dir-id',
197
inventory.InventoryDirectory('dir-id', 'dir2', root_id)),
198
('dir/child', 'other/child', 'child-id',
199
inventory.InventoryFile('child-id', 'child', 'other-id'))])
200
self.assertEqual('dir2', wt.id2path('dir-id'))
201
self.assertEqual('other/child', wt.id2path('child-id'))
203
def test_replace_root(self):
204
wt = self.make_branch_and_tree('.')
206
self.addCleanup(wt.unlock)
208
root_id = wt.get_root_id()
209
wt.apply_inventory_delta([('', None, root_id, None),
210
(None, '', 'root-id',
211
inventory.InventoryDirectory('root-id', '', None))])