194
191
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
195
192
self.assertEqual('foo-id',
196
193
creator.shelf_transform.final_file_id(s_trans_id))
197
self.assertPathDoesNotExist('foo')
198
self.assertPathDoesNotExist('bar')
194
self.failIfExists('foo')
195
self.failIfExists('bar')
199
196
self.assertShelvedFileEqual('a\n', creator, 'foo-id')
200
197
s_bar_trans_id = creator.shelf_transform.trans_id_file_id('bar-id')
201
198
self.assertEqual('directory',
218
215
def _test_shelve_symlink_creation(self, link_name, link_target,
219
216
shelve_change=False):
220
self.requireFeature(features.SymlinkFeature)
217
self.requireFeature(tests.SymlinkFeature)
221
218
tree = self.make_branch_and_tree('.')
222
219
tree.lock_write()
223
220
self.addCleanup(tree.unlock)
234
231
creator.shelve_creation('foo-id')
235
232
creator.transform()
236
233
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
237
self.assertPathDoesNotExist(link_name)
234
self.failIfExists(link_name)
238
235
limbo_name = creator.shelf_transform._limbo_name(s_trans_id)
239
236
self.assertEqual(link_target, osutils.readlink(limbo_name))
240
237
ptree = creator.shelf_transform.get_preview_tree()
244
241
self._test_shelve_symlink_creation('foo', 'bar')
246
243
def test_shelve_unicode_symlink_creation(self):
247
self.requireFeature(features.UnicodeFilenameFeature)
244
self.requireFeature(tests.UnicodeFilenameFeature)
248
245
self._test_shelve_symlink_creation(u'fo\N{Euro Sign}o',
249
246
u'b\N{Euro Sign}ar')
254
251
def _test_shelve_symlink_target_change(self, link_name,
255
252
old_target, new_target,
256
253
shelve_change=False):
257
self.requireFeature(features.SymlinkFeature)
254
self.requireFeature(tests.SymlinkFeature)
258
255
tree = self.make_branch_and_tree('.')
259
256
tree.lock_write()
260
257
self.addCleanup(tree.unlock)
285
282
self._test_shelve_symlink_target_change('foo', 'bar', 'baz')
287
284
def test_shelve_unicode_symlink_target_change(self):
288
self.requireFeature(features.UnicodeFilenameFeature)
285
self.requireFeature(tests.UnicodeFilenameFeature)
289
286
self._test_shelve_symlink_target_change(
290
287
u'fo\N{Euro Sign}o', u'b\N{Euro Sign}ar', u'b\N{Euro Sign}az')
313
310
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
314
311
self.assertEqual('foo-id',
315
312
creator.shelf_transform.final_file_id(s_trans_id))
316
self.assertPathDoesNotExist('foo')
313
self.failIfExists('foo')
318
315
def prepare_shelve_deletion(self):
319
316
tree = self.make_branch_and_tree('tree')
333
330
return creator, tree
335
332
def check_shelve_deletion(self, tree):
336
self.assertTrue(tree.has_id('foo-id'))
337
self.assertTrue(tree.has_id('bar-id'))
333
self.assertTrue('foo-id' in tree)
334
self.assertTrue('bar-id' in tree)
338
335
self.assertFileEqual('baz', 'tree/foo/bar')
340
337
def test_shelve_deletion(self):
365
362
sorted(list(creator.iter_shelvable())))
366
363
creator.shelve_deletion('foo-id')
367
364
creator.transform()
368
self.assertPathExists('tree/foo')
365
self.failUnlessExists('tree/foo')
370
367
def prepare_shelve_change_kind(self):
371
368
tree = self.make_branch_and_tree('tree')
424
421
sorted(list(creator.iter_shelvable())))
425
422
creator.shelve_deletion('foo-id')
426
423
creator.transform()
427
self.assertPathExists('tree/foo')
424
self.failUnlessExists('tree/foo')
429
426
def test_shelve_serialization(self):
430
427
tree = self.make_branch_and_tree('.')
571
568
list(creator.iter_shelvable())
572
569
creator.shelve_deletion('foo-id')
573
570
creator.shelve_deletion('bar-id')
574
with open('shelf', 'w+b') as shelf_file:
575
creator.write_shelf(shelf_file)
571
shelf_file = open('shelf', 'w+b')
572
self.addCleanup(shelf_file.close)
573
creator.write_shelf(shelf_file)
578
576
# validate the test setup
579
self.assertTrue(tree.has_id('foo-id'))
580
self.assertTrue(tree.has_id('bar-id'))
577
self.assertTrue('foo-id' in tree)
578
self.assertTrue('bar-id' in tree)
581
579
self.assertFileEqual('baz', 'tree/foo/bar')
582
with open('shelf', 'r+b') as shelf_file:
583
unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
584
self.addCleanup(unshelver.finalize)
585
unshelver.make_merger().do_merge()
586
self.assertFalse(tree.has_id('foo-id'))
587
self.assertFalse(tree.has_id('bar-id'))
581
unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
582
self.addCleanup(unshelver.finalize)
583
unshelver.make_merger().do_merge()
584
self.assertFalse('foo-id' in tree)
585
self.assertFalse('bar-id' in tree)
589
587
def test_unshelve_base(self):
590
588
tree = self.make_branch_and_tree('tree')
638
636
creator.shelve_change(change)
639
637
shelf_manager = tree.get_shelf_manager()
640
638
shelf_id = shelf_manager.shelve_changes(creator)
641
self.assertPathDoesNotExist('dir/subdir')
639
self.failIfExists('dir/subdir')
642
640
tree.remove(['dir'])
643
641
unshelver = shelf_manager.get_unshelver(shelf_id)
644
642
self.addCleanup(unshelver.finalize)
645
643
unshelver.make_merger().do_merge()
646
self.assertPathExists('dir/subdir/foo')
644
self.failUnlessExists('dir/subdir/foo')
647
645
self.assertEqual('dir-id', tree.path2id('dir'))
648
646
self.assertEqual('subdir-id', tree.path2id('dir/subdir'))
649
647
self.assertEqual('foo-id', tree.path2id('dir/subdir/foo'))
748
746
creator.shelve_creation('foo-id')
749
747
shelf_manager = tree.get_shelf_manager()
750
748
shelf_id = shelf_manager.shelve_changes(creator)
751
self.assertPathDoesNotExist('tree/foo')
749
self.failIfExists('tree/foo')
752
750
unshelver = shelf_manager.get_unshelver(shelf_id)
753
751
self.addCleanup(unshelver.finalize)
754
752
unshelver.make_merger().do_merge()