1
# Copyright (C) 2008-2011 Canonical Ltd
1
# Copyright (C) 2008 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
111
108
creator.shelve_change(('rename', 'baz-id', 'foo/baz', 'bar/baz'))
112
109
self.check_shelve_move(creator, tree)
114
def test_shelve_changed_root_id(self):
115
tree = self.make_branch_and_tree('.')
116
self.build_tree(['foo'])
117
tree.set_root_id('first-root-id')
118
tree.add(['foo'], ['foo-id'])
120
tree.set_root_id('second-root-id')
121
tree.lock_tree_write()
122
self.addCleanup(tree.unlock)
123
creator = shelf.ShelfCreator(tree, tree.basis_tree())
124
self.addCleanup(creator.finalize)
125
self.expectFailure('shelf doesn\'t support shelving root changes yet',
127
('delete file', 'first-root-id', 'directory', ''),
128
('add file', 'second-root-id', 'directory', ''),
129
('rename', 'foo-id', u'foo', u'foo'),
130
], list(creator.iter_shelvable()))
132
self.assertEqual([('delete file', 'first-root-id', 'directory', ''),
133
('add file', 'second-root-id', 'directory', ''),
134
('rename', 'foo-id', u'foo', u'foo'),
135
], list(creator.iter_shelvable()))
137
111
def assertShelvedFileEqual(self, expected_content, creator, file_id):
138
112
s_trans_id = creator.shelf_transform.trans_id_file_id(file_id)
139
113
shelf_file = creator.shelf_transform._limbo_name(s_trans_id)
194
168
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
195
169
self.assertEqual('foo-id',
196
170
creator.shelf_transform.final_file_id(s_trans_id))
197
self.assertPathDoesNotExist('foo')
198
self.assertPathDoesNotExist('bar')
171
self.failIfExists('foo')
172
self.failIfExists('bar')
199
173
self.assertShelvedFileEqual('a\n', creator, 'foo-id')
200
174
s_bar_trans_id = creator.shelf_transform.trans_id_file_id('bar-id')
201
175
self.assertEqual('directory',
218
192
def _test_shelve_symlink_creation(self, link_name, link_target,
219
193
shelve_change=False):
220
self.requireFeature(features.SymlinkFeature)
194
self.requireFeature(tests.SymlinkFeature)
221
195
tree = self.make_branch_and_tree('.')
222
196
tree.lock_write()
223
197
self.addCleanup(tree.unlock)
234
208
creator.shelve_creation('foo-id')
235
209
creator.transform()
236
210
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
237
self.assertPathDoesNotExist(link_name)
211
self.failIfExists(link_name)
238
212
limbo_name = creator.shelf_transform._limbo_name(s_trans_id)
239
213
self.assertEqual(link_target, osutils.readlink(limbo_name))
240
214
ptree = creator.shelf_transform.get_preview_tree()
244
218
self._test_shelve_symlink_creation('foo', 'bar')
246
220
def test_shelve_unicode_symlink_creation(self):
247
self.requireFeature(features.UnicodeFilenameFeature)
221
self.requireFeature(tests.UnicodeFilenameFeature)
248
222
self._test_shelve_symlink_creation(u'fo\N{Euro Sign}o',
249
223
u'b\N{Euro Sign}ar')
254
228
def _test_shelve_symlink_target_change(self, link_name,
255
229
old_target, new_target,
256
230
shelve_change=False):
257
self.requireFeature(features.SymlinkFeature)
231
self.requireFeature(tests.SymlinkFeature)
258
232
tree = self.make_branch_and_tree('.')
259
233
tree.lock_write()
260
234
self.addCleanup(tree.unlock)
285
259
self._test_shelve_symlink_target_change('foo', 'bar', 'baz')
287
261
def test_shelve_unicode_symlink_target_change(self):
288
self.requireFeature(features.UnicodeFilenameFeature)
262
self.requireFeature(tests.UnicodeFilenameFeature)
289
263
self._test_shelve_symlink_target_change(
290
264
u'fo\N{Euro Sign}o', u'b\N{Euro Sign}ar', u'b\N{Euro Sign}az')
313
287
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
314
288
self.assertEqual('foo-id',
315
289
creator.shelf_transform.final_file_id(s_trans_id))
316
self.assertPathDoesNotExist('foo')
290
self.failIfExists('foo')
318
292
def prepare_shelve_deletion(self):
319
293
tree = self.make_branch_and_tree('tree')
333
307
return creator, tree
335
309
def check_shelve_deletion(self, tree):
336
self.assertTrue(tree.has_id('foo-id'))
337
self.assertTrue(tree.has_id('bar-id'))
310
self.assertTrue('foo-id' in tree)
311
self.assertTrue('bar-id' in tree)
338
312
self.assertFileEqual('baz', 'tree/foo/bar')
340
314
def test_shelve_deletion(self):
365
339
sorted(list(creator.iter_shelvable())))
366
340
creator.shelve_deletion('foo-id')
367
341
creator.transform()
368
self.assertPathExists('tree/foo')
342
self.failUnlessExists('tree/foo')
370
344
def prepare_shelve_change_kind(self):
371
345
tree = self.make_branch_and_tree('tree')
424
398
sorted(list(creator.iter_shelvable())))
425
399
creator.shelve_deletion('foo-id')
426
400
creator.transform()
427
self.assertPathExists('tree/foo')
401
self.failUnlessExists('tree/foo')
429
403
def test_shelve_serialization(self):
430
404
tree = self.make_branch_and_tree('.')
502
476
def test_shelve_skips_added_root(self):
503
477
"""Skip adds of the root when iterating through shelvable changes."""
504
478
tree = self.make_branch_and_tree('tree')
505
tree.lock_tree_write()
506
self.addCleanup(tree.unlock)
507
479
creator = shelf.ShelfCreator(tree, tree.basis_tree())
508
480
self.addCleanup(creator.finalize)
509
481
self.assertEqual([], list(creator.iter_shelvable()))
529
501
shelf_file.seek(0)
530
502
unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
531
503
unshelver.make_merger().do_merge()
532
self.addCleanup(unshelver.finalize)
533
504
self.assertFileEqual('bar', 'tree/foo')
535
506
shelf_file.close()
553
524
self.build_tree_contents([('tree/foo', 'z\na\nb\nc\n')])
554
525
shelf_file.seek(0)
555
526
unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
556
self.addCleanup(unshelver.finalize)
557
527
unshelver.make_merger().do_merge()
558
528
self.assertFileEqual('z\na\nb\nd\n', 'tree/foo')
571
541
list(creator.iter_shelvable())
572
542
creator.shelve_deletion('foo-id')
573
543
creator.shelve_deletion('bar-id')
574
with open('shelf', 'w+b') as shelf_file:
575
creator.write_shelf(shelf_file)
544
shelf_file = open('shelf', 'w+b')
545
self.addCleanup(shelf_file.close)
546
creator.write_shelf(shelf_file)
578
549
# validate the test setup
579
self.assertTrue(tree.has_id('foo-id'))
580
self.assertTrue(tree.has_id('bar-id'))
550
self.assertTrue('foo-id' in tree)
551
self.assertTrue('bar-id' in tree)
581
552
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'))
554
unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
555
unshelver.make_merger().do_merge()
556
self.assertFalse('foo-id' in tree)
557
self.assertFalse('bar-id' in tree)
589
559
def test_unshelve_base(self):
590
560
tree = self.make_branch_and_tree('tree')
626
596
self.assertEqual('Shelf corrupt.', str(e))
628
def test_unshelve_subdir_in_now_removed_dir(self):
629
tree = self.make_branch_and_tree('.')
630
self.addCleanup(tree.lock_write().unlock)
631
self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
632
tree.add(['dir'], ['dir-id'])
633
tree.commit('versioned dir')
634
tree.add(['dir/subdir', 'dir/subdir/foo'], ['subdir-id', 'foo-id'])
635
creator = shelf.ShelfCreator(tree, tree.basis_tree())
636
self.addCleanup(creator.finalize)
637
for change in creator.iter_shelvable():
638
creator.shelve_change(change)
639
shelf_manager = tree.get_shelf_manager()
640
shelf_id = shelf_manager.shelve_changes(creator)
641
self.assertPathDoesNotExist('dir/subdir')
643
unshelver = shelf_manager.get_unshelver(shelf_id)
644
self.addCleanup(unshelver.finalize)
645
unshelver.make_merger().do_merge()
646
self.assertPathExists('dir/subdir/foo')
647
self.assertEqual('dir-id', tree.path2id('dir'))
648
self.assertEqual('subdir-id', tree.path2id('dir/subdir'))
649
self.assertEqual('foo-id', tree.path2id('dir/subdir/foo'))
652
599
class TestShelfManager(tests.TestCaseWithTransport):
748
695
creator.shelve_creation('foo-id')
749
696
shelf_manager = tree.get_shelf_manager()
750
697
shelf_id = shelf_manager.shelve_changes(creator)
751
self.assertPathDoesNotExist('tree/foo')
698
self.failIfExists('tree/foo')
752
699
unshelver = shelf_manager.get_unshelver(shelf_id)
753
self.addCleanup(unshelver.finalize)
754
700
unshelver.make_merger().do_merge()
755
701
self.assertFileEqual('bar', 'tree/foo')