41
41
class TestPrepareShelf(tests.TestCaseWithTransport):
43
def test_shelve_rename(self):
43
def prepare_shelve_rename(self):
44
44
tree = self.make_branch_and_tree('.')
45
45
self.build_tree(['foo'])
46
46
tree.add(['foo'], ['foo-id'])
50
50
self.addCleanup(creator.finalize)
51
51
self.assertEqual([('rename', 'foo-id', 'foo', 'bar')],
52
52
list(creator.iter_shelvable()))
53
creator.shelve_rename('foo-id')
55
def check_shelve_rename(self, creator):
54
56
work_trans_id = creator.work_transform.trans_id_file_id('foo-id')
55
57
self.assertEqual('foo', creator.work_transform.final_name(
58
60
self.assertEqual('bar', creator.shelf_transform.final_name(
61
def test_shelve_move(self):
63
def test_shelve_rename(self):
64
creator = self.prepare_shelve_rename()
65
creator.shelve_rename('foo-id')
66
self.check_shelve_rename(creator)
68
def test_shelve_change_handles_rename(self):
69
creator = self.prepare_shelve_rename()
70
creator.shelve_change(('rename', 'foo-id', 'foo', 'bar'))
71
self.check_shelve_rename(creator)
73
def prepare_shelve_move(self):
62
74
tree = self.make_branch_and_tree('.')
63
75
self.build_tree(['foo/', 'bar/', 'foo/baz'])
64
76
tree.add(['foo', 'bar', 'foo/baz'], ['foo-id', 'bar-id', 'baz-id'])
68
80
self.addCleanup(creator.finalize)
69
81
self.assertEqual([('rename', 'baz-id', 'foo/baz', 'bar/baz')],
70
82
list(creator.iter_shelvable()))
71
creator.shelve_rename('baz-id')
85
def check_shelve_move(self, creator, tree):
72
86
work_trans_id = creator.work_transform.trans_id_file_id('baz-id')
73
87
work_foo = creator.work_transform.trans_id_file_id('foo-id')
74
88
self.assertEqual(work_foo, creator.work_transform.final_parent(
80
94
creator.transform()
81
95
self.assertEqual('foo/baz', tree.id2path('baz-id'))
97
def test_shelve_move(self):
98
creator, tree = self.prepare_shelve_move()
99
creator.shelve_rename('baz-id')
100
self.check_shelve_move(creator, tree)
102
def test_shelve_change_handles_move(self):
103
creator, tree = self.prepare_shelve_move()
104
creator.shelve_change(('rename', 'baz-id', 'foo/baz', 'bar/baz'))
105
self.check_shelve_move(creator, tree)
83
107
def assertShelvedFileEqual(self, expected_content, creator, file_id):
84
108
s_trans_id = creator.shelf_transform.trans_id_file_id(file_id)
85
109
shelf_file = creator.shelf_transform._limbo_name(s_trans_id)
102
126
self.assertFileEqual('a\nc\n', 'foo')
103
127
self.assertShelvedFileEqual('b\na\n', creator, 'foo-id')
105
def test_shelve_creation(self):
130
def prepare_shelve_creation(self):
106
131
tree = self.make_branch_and_tree('.')
107
132
tree.lock_write()
108
133
self.addCleanup(tree.unlock)
114
139
self.assertEqual([('add file', 'bar-id', 'directory', 'bar'),
115
140
('add file', 'foo-id', 'file', 'foo')],
116
141
sorted(list(creator.iter_shelvable())))
117
creator.shelve_creation('foo-id')
118
creator.shelve_creation('bar-id')
144
def check_shelve_creation(self, creator, tree):
120
145
self.assertRaises(StopIteration,
121
146
tree.iter_entries_by_dir(['foo-id']).next)
122
147
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
129
154
self.assertEqual('directory',
130
155
creator.shelf_transform.final_kind(s_bar_trans_id))
132
def _test_shelve_symlink_creation(self, link_name, link_target):
157
def test_shelve_creation(self):
158
creator, tree = self.prepare_shelve_creation()
159
creator.shelve_creation('foo-id')
160
creator.shelve_creation('bar-id')
162
self.check_shelve_creation(creator, tree)
164
def test_shelve_change_handles_creation(self):
165
creator, tree = self.prepare_shelve_creation()
166
creator.shelve_change(('add file', 'foo-id', 'file', 'foo'))
167
creator.shelve_change(('add file', 'bar-id', 'directory', 'bar'))
169
self.check_shelve_creation(creator, tree)
171
def _test_shelve_symlink_creation(self, link_name, link_target,
172
shelve_change=False):
133
173
self.requireFeature(tests.SymlinkFeature)
134
174
tree = self.make_branch_and_tree('.')
135
175
tree.lock_write()
141
181
self.addCleanup(creator.finalize)
142
182
self.assertEqual([('add file', 'foo-id', 'symlink', link_name)],
143
183
list(creator.iter_shelvable()))
144
creator.shelve_creation('foo-id')
185
creator.shelve_change(('add file', 'foo-id', 'symlink', link_name))
187
creator.shelve_creation('foo-id')
145
188
creator.transform()
146
189
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
147
190
self.failIfExists(link_name)
158
201
self._test_shelve_symlink_creation(u'fo\N{Euro Sign}o',
159
202
u'b\N{Euro Sign}ar')
204
def test_shelve_change_handles_symlink_creation(self):
205
self._test_shelve_symlink_creation('foo', 'bar', shelve_change=True)
161
207
def _test_shelve_symlink_target_change(self, link_name,
162
old_target, new_target):
208
old_target, new_target,
209
shelve_change=False):
163
210
self.requireFeature(tests.SymlinkFeature)
164
211
tree = self.make_branch_and_tree('.')
165
212
tree.lock_write()
174
221
self.assertEqual([('modify target', 'foo-id', link_name,
175
222
old_target, new_target)],
176
223
list(creator.iter_shelvable()))
177
creator.shelve_modify_target('foo-id')
225
creator.shelve_change(('modify target', 'foo-id', link_name,
226
old_target, new_target))
228
creator.shelve_modify_target('foo-id')
178
229
creator.transform()
179
230
self.assertEqual(old_target, osutils.readlink(link_name))
180
231
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
191
242
self._test_shelve_symlink_target_change(
192
243
u'fo\N{Euro Sign}o', u'b\N{Euro Sign}ar', u'b\N{Euro Sign}az')
245
def test_shelve_change_handles_symlink_target_change(self):
246
self._test_shelve_symlink_target_change('foo', 'bar', 'baz',
194
249
def test_shelve_creation_no_contents(self):
195
250
tree = self.make_branch_and_tree('.')
196
251
tree.lock_write()
213
268
creator.shelf_transform.final_file_id(s_trans_id))
214
269
self.failIfExists('foo')
216
def test_shelve_deletion(self):
271
def prepare_shelve_deletion(self):
217
272
tree = self.make_branch_and_tree('tree')
218
273
tree.lock_write()
219
274
self.addCleanup(tree.unlock)
228
283
self.assertEqual([('delete file', 'bar-id', 'file', 'foo/bar'),
229
284
('delete file', 'foo-id', 'directory', 'foo')],
230
285
sorted(list(creator.iter_shelvable())))
231
creator.shelve_deletion('foo-id')
232
creator.shelve_deletion('bar-id')
288
def check_shelve_deletion(self, tree):
234
289
self.assertTrue('foo-id' in tree)
235
290
self.assertTrue('bar-id' in tree)
236
291
self.assertFileEqual('baz', 'tree/foo/bar')
293
def test_shelve_deletion(self):
294
creator, tree = self.prepare_shelve_deletion()
295
creator.shelve_deletion('foo-id')
296
creator.shelve_deletion('bar-id')
298
self.check_shelve_deletion(tree)
300
def test_shelve_change_handles_deletion(self):
301
creator, tree = self.prepare_shelve_deletion()
302
creator.shelve_change(('delete file', 'foo-id', 'directory', 'foo'))
303
creator.shelve_change(('delete file', 'bar-id', 'file', 'foo/bar'))
305
self.check_shelve_deletion(tree)
238
307
def test_shelve_delete_contents(self):
239
308
tree = self.make_branch_and_tree('tree')
240
309
self.build_tree(['tree/foo',])
249
318
creator.transform()
250
319
self.failUnlessExists('tree/foo')
252
def test_shelve_change_kind(self):
321
def prepare_shelve_change_kind(self):
253
322
tree = self.make_branch_and_tree('tree')
254
323
self.build_tree_contents([('tree/foo', 'bar')])
255
324
tree.add('foo', 'foo-id')
260
329
self.addCleanup(creator.finalize)
261
330
self.assertEqual([('change kind', 'foo-id', 'file', 'directory',
262
331
'foo')], sorted(list(creator.iter_shelvable())))
334
def check_shelve_change_kind(self, creator):
335
self.assertFileEqual('bar', 'tree/foo')
336
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
337
self.assertEqual('directory',
338
creator.shelf_transform._new_contents[s_trans_id])
340
def test_shelve_change_kind(self):
341
creator = self.prepare_shelve_change_kind()
263
342
creator.shelve_content_change('foo-id')
264
343
creator.transform()
265
self.assertFileEqual('bar', 'tree/foo')
266
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
267
self.assertEqual('directory',
268
creator.shelf_transform._new_contents[s_trans_id])
344
self.check_shelve_change_kind(creator)
346
def test_shelve_change_handles_change_kind(self):
347
creator = self.prepare_shelve_change_kind()
348
creator.shelve_change(('change kind', 'foo-id', 'file', 'directory',
351
self.check_shelve_change_kind(creator)
353
def test_shelve_change_unknown_change(self):
354
tree = self.make_branch_and_tree('tree')
355
creator = shelf.ShelfCreator(tree, tree.basis_tree())
356
self.addCleanup(creator.finalize)
357
e = self.assertRaises(ValueError, creator.shelve_change, ('unknown',))
358
self.assertEqual('Unknown change kind: "unknown"', str(e))
270
360
def test_shelve_unversion(self):
271
361
tree = self.make_branch_and_tree('tree')