62
50
self.assertEqual('bar', creator.shelf_transform.final_name(
65
def test_shelve_rename(self):
66
creator = self.prepare_shelve_rename()
67
creator.shelve_rename('foo-id')
68
self.check_shelve_rename(creator)
70
def test_shelve_change_handles_rename(self):
71
creator = self.prepare_shelve_rename()
72
creator.shelve_change(('rename', 'foo-id', 'foo', 'bar'))
73
self.check_shelve_rename(creator)
75
def prepare_shelve_move(self):
53
def test_shelve_move(self):
76
54
tree = self.make_branch_and_tree('.')
77
55
self.build_tree(['foo/', 'bar/', 'foo/baz'])
78
56
tree.add(['foo', 'bar', 'foo/baz'], ['foo-id', 'bar-id', 'baz-id'])
80
58
tree.rename_one('foo/baz', 'bar/baz')
81
tree.lock_tree_write()
82
self.addCleanup(tree.unlock)
83
59
creator = shelf.ShelfCreator(tree, tree.basis_tree())
84
60
self.addCleanup(creator.finalize)
85
61
self.assertEqual([('rename', 'baz-id', 'foo/baz', 'bar/baz')],
86
62
list(creator.iter_shelvable()))
89
def check_shelve_move(self, creator, tree):
63
creator.shelve_rename('baz-id')
90
64
work_trans_id = creator.work_transform.trans_id_file_id('baz-id')
91
65
work_foo = creator.work_transform.trans_id_file_id('foo-id')
92
66
self.assertEqual(work_foo, creator.work_transform.final_parent(
98
72
creator.transform()
99
73
self.assertEqual('foo/baz', tree.id2path('baz-id'))
101
def test_shelve_move(self):
102
creator, tree = self.prepare_shelve_move()
103
creator.shelve_rename('baz-id')
104
self.check_shelve_move(creator, tree)
106
def test_shelve_change_handles_move(self):
107
creator, tree = self.prepare_shelve_move()
108
creator.shelve_change(('rename', 'baz-id', 'foo/baz', 'bar/baz'))
109
self.check_shelve_move(creator, tree)
111
def test_shelve_changed_root_id(self):
112
tree = self.make_branch_and_tree('.')
113
self.build_tree(['foo'])
114
tree.set_root_id('first-root-id')
115
tree.add(['foo'], ['foo-id'])
117
tree.set_root_id('second-root-id')
118
tree.lock_tree_write()
119
self.addCleanup(tree.unlock)
120
creator = shelf.ShelfCreator(tree, tree.basis_tree())
121
self.addCleanup(creator.finalize)
122
self.expectFailure('shelf doesn\'t support shelving root changes yet',
124
('delete file', 'first-root-id', 'directory', ''),
125
('add file', 'second-root-id', 'directory', ''),
126
('rename', 'foo-id', u'foo', u'foo'),
127
], list(creator.iter_shelvable()))
129
self.assertEqual([('delete file', 'first-root-id', 'directory', ''),
130
('add file', 'second-root-id', 'directory', ''),
131
('rename', 'foo-id', u'foo', u'foo'),
132
], list(creator.iter_shelvable()))
134
75
def assertShelvedFileEqual(self, expected_content, creator, file_id):
135
76
s_trans_id = creator.shelf_transform.trans_id_file_id(file_id)
136
77
shelf_file = creator.shelf_transform._limbo_name(s_trans_id)
137
78
self.assertFileEqual(expected_content, shelf_file)
139
def prepare_content_change(self):
80
def test_shelve_content_change(self):
140
81
tree = self.make_branch_and_tree('.')
142
83
self.addCleanup(tree.unlock)
198
121
self.assertEqual('directory',
199
122
creator.shelf_transform.final_kind(s_bar_trans_id))
201
def test_shelve_creation(self):
202
creator, tree = self.prepare_shelve_creation()
203
creator.shelve_creation('foo-id')
204
creator.shelve_creation('bar-id')
206
self.check_shelve_creation(creator, tree)
208
def test_shelve_change_handles_creation(self):
209
creator, tree = self.prepare_shelve_creation()
210
creator.shelve_change(('add file', 'foo-id', 'file', 'foo'))
211
creator.shelve_change(('add file', 'bar-id', 'directory', 'bar'))
213
self.check_shelve_creation(creator, tree)
215
def _test_shelve_symlink_creation(self, link_name, link_target,
216
shelve_change=False):
217
self.requireFeature(tests.SymlinkFeature)
218
tree = self.make_branch_and_tree('.')
220
self.addCleanup(tree.unlock)
221
tree.commit('Empty tree')
222
os.symlink(link_target, link_name)
223
tree.add(link_name, 'foo-id')
224
creator = shelf.ShelfCreator(tree, tree.basis_tree())
225
self.addCleanup(creator.finalize)
226
self.assertEqual([('add file', 'foo-id', 'symlink', link_name)],
227
list(creator.iter_shelvable()))
229
creator.shelve_change(('add file', 'foo-id', 'symlink', link_name))
231
creator.shelve_creation('foo-id')
233
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
234
self.failIfExists(link_name)
235
limbo_name = creator.shelf_transform._limbo_name(s_trans_id)
236
self.assertEqual(link_target, osutils.readlink(limbo_name))
237
ptree = creator.shelf_transform.get_preview_tree()
238
self.assertEqual(link_target, ptree.get_symlink_target('foo-id'))
240
124
def test_shelve_symlink_creation(self):
241
self._test_shelve_symlink_creation('foo', 'bar')
243
def test_shelve_unicode_symlink_creation(self):
244
self.requireFeature(tests.UnicodeFilenameFeature)
245
self._test_shelve_symlink_creation(u'fo\N{Euro Sign}o',
248
def test_shelve_change_handles_symlink_creation(self):
249
self._test_shelve_symlink_creation('foo', 'bar', shelve_change=True)
251
def _test_shelve_symlink_target_change(self, link_name,
252
old_target, new_target,
253
shelve_change=False):
254
self.requireFeature(tests.SymlinkFeature)
255
tree = self.make_branch_and_tree('.')
257
self.addCleanup(tree.unlock)
258
os.symlink(old_target, link_name)
259
tree.add(link_name, 'foo-id')
125
self.requireFeature(tests.SymlinkFeature)
126
tree = self.make_branch_and_tree('.')
128
self.addCleanup(tree.unlock)
129
tree.commit('Empty tree')
130
os.symlink('bar', 'foo')
131
tree.add('foo', 'foo-id')
132
creator = shelf.ShelfCreator(tree, tree.basis_tree())
133
self.addCleanup(creator.finalize)
134
self.assertEqual([('add file', 'foo-id', 'symlink', 'foo')],
135
list(creator.iter_shelvable()))
136
creator.shelve_creation('foo-id')
138
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
139
self.failIfExists('foo')
140
limbo_name = creator.shelf_transform._limbo_name(s_trans_id)
141
self.assertEqual('bar', os.readlink(limbo_name))
143
def test_shelve_symlink_target_change(self):
144
self.requireFeature(tests.SymlinkFeature)
145
tree = self.make_branch_and_tree('.')
147
self.addCleanup(tree.unlock)
148
os.symlink('bar', 'foo')
149
tree.add('foo', 'foo-id')
260
150
tree.commit("commit symlink")
262
os.symlink(new_target, link_name)
152
os.symlink('baz', 'foo')
263
153
creator = shelf.ShelfCreator(tree, tree.basis_tree())
264
154
self.addCleanup(creator.finalize)
265
self.assertEqual([('modify target', 'foo-id', link_name,
266
old_target, new_target)],
155
self.assertEqual([('modify target', 'foo-id', 'foo', 'bar', 'baz')],
267
156
list(creator.iter_shelvable()))
269
creator.shelve_change(('modify target', 'foo-id', link_name,
270
old_target, new_target))
272
creator.shelve_modify_target('foo-id')
157
creator.shelve_modify_target('foo-id')
273
158
creator.transform()
274
self.assertEqual(old_target, osutils.readlink(link_name))
159
self.assertEqual('bar', os.readlink('foo'))
275
160
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
276
161
limbo_name = creator.shelf_transform._limbo_name(s_trans_id)
277
self.assertEqual(new_target, osutils.readlink(limbo_name))
278
ptree = creator.shelf_transform.get_preview_tree()
279
self.assertEqual(new_target, ptree.get_symlink_target('foo-id'))
281
def test_shelve_symlink_target_change(self):
282
self._test_shelve_symlink_target_change('foo', 'bar', 'baz')
284
def test_shelve_unicode_symlink_target_change(self):
285
self.requireFeature(tests.UnicodeFilenameFeature)
286
self._test_shelve_symlink_target_change(
287
u'fo\N{Euro Sign}o', u'b\N{Euro Sign}ar', u'b\N{Euro Sign}az')
289
def test_shelve_change_handles_symlink_target_change(self):
290
self._test_shelve_symlink_target_change('foo', 'bar', 'baz',
162
self.assertEqual('baz', os.readlink(limbo_name))
293
164
def test_shelve_creation_no_contents(self):
294
165
tree = self.make_branch_and_tree('.')
327
198
self.assertEqual([('delete file', 'bar-id', 'file', 'foo/bar'),
328
199
('delete file', 'foo-id', 'directory', 'foo')],
329
200
sorted(list(creator.iter_shelvable())))
332
def check_shelve_deletion(self, tree):
201
creator.shelve_deletion('foo-id')
202
creator.shelve_deletion('bar-id')
333
204
self.assertTrue('foo-id' in tree)
334
205
self.assertTrue('bar-id' in tree)
335
206
self.assertFileEqual('baz', 'tree/foo/bar')
337
def test_shelve_deletion(self):
338
creator, tree = self.prepare_shelve_deletion()
339
creator.shelve_deletion('foo-id')
340
creator.shelve_deletion('bar-id')
342
self.check_shelve_deletion(tree)
344
def test_shelve_change_handles_deletion(self):
345
creator, tree = self.prepare_shelve_deletion()
346
creator.shelve_change(('delete file', 'foo-id', 'directory', 'foo'))
347
creator.shelve_change(('delete file', 'bar-id', 'file', 'foo/bar'))
349
self.check_shelve_deletion(tree)
351
208
def test_shelve_delete_contents(self):
352
209
tree = self.make_branch_and_tree('tree')
353
210
self.build_tree(['tree/foo',])
354
211
tree.add('foo', 'foo-id')
355
212
tree.commit('Added file and directory')
356
213
os.unlink('tree/foo')
357
tree.lock_tree_write()
358
self.addCleanup(tree.unlock)
359
214
creator = shelf.ShelfCreator(tree, tree.basis_tree())
360
215
self.addCleanup(creator.finalize)
361
216
self.assertEqual([('delete file', 'foo-id', 'file', 'foo')],
364
219
creator.transform()
365
220
self.failUnlessExists('tree/foo')
367
def prepare_shelve_change_kind(self):
222
def test_shelve_change_kind(self):
368
223
tree = self.make_branch_and_tree('tree')
369
224
self.build_tree_contents([('tree/foo', 'bar')])
370
225
tree.add('foo', 'foo-id')
371
226
tree.commit('Added file and directory')
372
227
os.unlink('tree/foo')
373
228
os.mkdir('tree/foo')
374
tree.lock_tree_write()
375
self.addCleanup(tree.unlock)
376
229
creator = shelf.ShelfCreator(tree, tree.basis_tree())
377
230
self.addCleanup(creator.finalize)
378
231
self.assertEqual([('change kind', 'foo-id', 'file', 'directory',
379
232
'foo')], sorted(list(creator.iter_shelvable())))
382
def check_shelve_change_kind(self, creator):
233
creator.shelve_content_change('foo-id')
383
235
self.assertFileEqual('bar', 'tree/foo')
384
236
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
385
237
self.assertEqual('directory',
386
238
creator.shelf_transform._new_contents[s_trans_id])
388
def test_shelve_change_kind(self):
389
creator = self.prepare_shelve_change_kind()
390
creator.shelve_content_change('foo-id')
392
self.check_shelve_change_kind(creator)
394
def test_shelve_change_handles_change_kind(self):
395
creator = self.prepare_shelve_change_kind()
396
creator.shelve_change(('change kind', 'foo-id', 'file', 'directory',
399
self.check_shelve_change_kind(creator)
401
def test_shelve_change_unknown_change(self):
402
tree = self.make_branch_and_tree('tree')
403
tree.lock_tree_write()
404
self.addCleanup(tree.unlock)
405
creator = shelf.ShelfCreator(tree, tree.basis_tree())
406
self.addCleanup(creator.finalize)
407
e = self.assertRaises(ValueError, creator.shelve_change, ('unknown',))
408
self.assertEqual('Unknown change kind: "unknown"', str(e))
410
240
def test_shelve_unversion(self):
411
241
tree = self.make_branch_and_tree('tree')
412
242
self.build_tree(['tree/foo',])
413
243
tree.add('foo', 'foo-id')
414
244
tree.commit('Added file and directory')
415
245
tree.unversion(['foo-id'])
416
tree.lock_tree_write()
417
self.addCleanup(tree.unlock)
418
246
creator = shelf.ShelfCreator(tree, tree.basis_tree())
419
247
self.addCleanup(creator.finalize)
420
248
self.assertEqual([('delete file', 'foo-id', 'file', 'foo')],
481
301
# And a second tentative should raise the same error (no
482
302
# limbo/pending_deletion leftovers).
483
tree.lock_tree_write()
485
self.assertRaises(errors.PathsNotVersionedError,
486
shelf.ShelfCreator, tree, tree.basis_tree(), ['foo'])
490
def test_shelve_skips_added_root(self):
491
"""Skip adds of the root when iterating through shelvable changes."""
492
tree = self.make_branch_and_tree('tree')
493
tree.lock_tree_write()
494
self.addCleanup(tree.unlock)
495
creator = shelf.ShelfCreator(tree, tree.basis_tree())
496
self.addCleanup(creator.finalize)
497
self.assertEqual([], list(creator.iter_shelvable()))
499
def test_shelve_skips_added_root(self):
500
"""Skip adds of the root when iterating through shelvable changes."""
501
tree = self.make_branch_and_tree('tree')
502
tree.lock_tree_write()
503
self.addCleanup(tree.unlock)
504
creator = shelf.ShelfCreator(tree, tree.basis_tree())
505
self.addCleanup(creator.finalize)
506
self.assertEqual([], list(creator.iter_shelvable()))
303
self.assertRaises(errors.PathsNotVersionedError,
304
shelf.ShelfCreator, tree, tree.basis_tree(), ['foo'])
509
307
class TestUnshelver(tests.TestCaseWithTransport):