46
46
tree.add(['foo'], ['foo-id'])
48
48
tree.rename_one('foo', 'bar')
49
tree.lock_tree_write()
50
self.addCleanup(tree.unlock)
49
51
creator = shelf.ShelfCreator(tree, tree.basis_tree())
50
52
self.addCleanup(creator.finalize)
51
53
self.assertEqual([('rename', 'foo-id', 'foo', 'bar')],
76
78
tree.add(['foo', 'bar', 'foo/baz'], ['foo-id', 'bar-id', 'baz-id'])
78
80
tree.rename_one('foo/baz', 'bar/baz')
81
tree.lock_tree_write()
82
self.addCleanup(tree.unlock)
79
83
creator = shelf.ShelfCreator(tree, tree.basis_tree())
80
84
self.addCleanup(creator.finalize)
81
85
self.assertEqual([('rename', 'baz-id', 'foo/baz', 'bar/baz')],
104
108
creator.shelve_change(('rename', 'baz-id', 'foo/baz', 'bar/baz'))
105
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()))
107
134
def assertShelvedFileEqual(self, expected_content, creator, file_id):
108
135
s_trans_id = creator.shelf_transform.trans_id_file_id(file_id)
109
136
shelf_file = creator.shelf_transform._limbo_name(s_trans_id)
110
137
self.assertFileEqual(expected_content, shelf_file)
112
def test_shelve_content_change(self):
139
def prepare_content_change(self):
113
140
tree = self.make_branch_and_tree('.')
114
141
tree.lock_write()
115
142
self.addCleanup(tree.unlock)
119
146
self.build_tree_contents([('foo', 'b\na\nc\n')])
120
147
creator = shelf.ShelfCreator(tree, tree.basis_tree())
121
148
self.addCleanup(creator.finalize)
151
def test_shelve_content_change(self):
152
creator = self.prepare_content_change()
122
153
self.assertEqual([('modify text', 'foo-id')],
123
154
list(creator.iter_shelvable()))
124
155
creator.shelve_lines('foo-id', ['a\n', 'c\n'])
126
157
self.assertFileEqual('a\nc\n', 'foo')
127
158
self.assertShelvedFileEqual('b\na\n', creator, 'foo-id')
160
def test_shelve_change_handles_modify_text(self):
161
creator = self.prepare_content_change()
162
creator.shelve_change(('modify text', 'foo-id'))
164
self.assertFileEqual('a\n', 'foo')
165
self.assertShelvedFileEqual('b\na\nc\n', creator, 'foo-id')
167
def test_shelve_all(self):
168
creator = self.prepare_content_change()
171
self.assertFileEqual('a\n', 'foo')
172
self.assertShelvedFileEqual('b\na\nc\n', creator, 'foo-id')
130
174
def prepare_shelve_creation(self):
131
175
tree = self.make_branch_and_tree('.')
310
354
tree.add('foo', 'foo-id')
311
355
tree.commit('Added file and directory')
312
356
os.unlink('tree/foo')
357
tree.lock_tree_write()
358
self.addCleanup(tree.unlock)
313
359
creator = shelf.ShelfCreator(tree, tree.basis_tree())
314
360
self.addCleanup(creator.finalize)
315
361
self.assertEqual([('delete file', 'foo-id', 'file', 'foo')],
325
371
tree.commit('Added file and directory')
326
372
os.unlink('tree/foo')
327
373
os.mkdir('tree/foo')
374
tree.lock_tree_write()
375
self.addCleanup(tree.unlock)
328
376
creator = shelf.ShelfCreator(tree, tree.basis_tree())
329
377
self.addCleanup(creator.finalize)
330
378
self.assertEqual([('change kind', 'foo-id', 'file', 'directory',
353
401
def test_shelve_change_unknown_change(self):
354
402
tree = self.make_branch_and_tree('tree')
403
tree.lock_tree_write()
404
self.addCleanup(tree.unlock)
355
405
creator = shelf.ShelfCreator(tree, tree.basis_tree())
356
406
self.addCleanup(creator.finalize)
357
407
e = self.assertRaises(ValueError, creator.shelve_change, ('unknown',))
363
413
tree.add('foo', 'foo-id')
364
414
tree.commit('Added file and directory')
365
415
tree.unversion(['foo-id'])
416
tree.lock_tree_write()
417
self.addCleanup(tree.unlock)
366
418
creator = shelf.ShelfCreator(tree, tree.basis_tree())
367
419
self.addCleanup(creator.finalize)
368
420
self.assertEqual([('delete file', 'foo-id', 'file', 'foo')],
374
426
def test_shelve_serialization(self):
375
427
tree = self.make_branch_and_tree('.')
428
tree.lock_tree_write()
429
self.addCleanup(tree.unlock)
376
430
creator = shelf.ShelfCreator(tree, tree.basis_tree())
377
431
self.addCleanup(creator.finalize)
378
432
shelf_file = open('shelf', 'wb')
387
441
tree = self.make_branch_and_tree('tree')
388
442
self.build_tree(['tree/foo'])
389
443
tree.add('foo', 'foo-id')
444
tree.lock_tree_write()
445
self.addCleanup(tree.unlock)
390
446
creator = shelf.ShelfCreator(tree, tree.basis_tree())
391
447
self.addCleanup(creator.finalize)
392
448
list(creator.iter_shelvable())
412
468
def test_shelve_unversioned(self):
413
469
tree = self.make_branch_and_tree('tree')
414
self.assertRaises(errors.PathsNotVersionedError,
415
shelf.ShelfCreator, tree, tree.basis_tree(), ['foo'])
470
tree.lock_tree_write()
472
self.assertRaises(errors.PathsNotVersionedError,
473
shelf.ShelfCreator, tree, tree.basis_tree(), ['foo'])
416
476
# We should be able to lock/unlock the tree if ShelfCreator cleaned
418
478
wt = workingtree.WorkingTree.open('tree')
421
481
# And a second tentative should raise the same error (no
422
482
# limbo/pending_deletion leftovers).
423
self.assertRaises(errors.PathsNotVersionedError,
424
shelf.ShelfCreator, tree, tree.basis_tree(), ['foo'])
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()))
427
509
class TestUnshelver(tests.TestCaseWithTransport):
467
550
self.build_tree_contents([('tree/foo', 'z\na\nb\nc\n')])
468
551
shelf_file.seek(0)
469
552
unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
553
self.addCleanup(unshelver.finalize)
470
554
unshelver.make_merger().do_merge()
471
555
self.assertFileEqual('z\na\nb\nd\n', 'tree/foo')
495
579
self.assertFileEqual('baz', 'tree/foo/bar')
496
580
shelf_file.seek(0)
497
581
unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
582
self.addCleanup(unshelver.finalize)
498
583
unshelver.make_merger().do_merge()
499
584
self.assertFalse('foo-id' in tree)
500
585
self.assertFalse('bar-id' in tree)
525
610
shelf_file = open('shelf', 'rb')
526
611
self.addCleanup(shelf_file.close)
527
612
unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
529
615
def test_corrupt_shelf(self):
530
616
tree = self.make_branch_and_tree('.')
639
725
shelf_id = shelf_manager.shelve_changes(creator)
640
726
self.failIfExists('tree/foo')
641
727
unshelver = shelf_manager.get_unshelver(shelf_id)
728
self.addCleanup(unshelver.finalize)
642
729
unshelver.make_merger().do_merge()
643
730
self.assertFileEqual('bar', 'tree/foo')
645
732
def test_get_metadata(self):
646
733
tree = self.make_branch_and_tree('.')
734
tree.lock_tree_write()
735
self.addCleanup(tree.unlock)
647
736
creator = shelf.ShelfCreator(tree, tree.basis_tree())
737
self.addCleanup(creator.finalize)
648
738
shelf_manager = tree.get_shelf_manager()
649
739
shelf_id = shelf_manager.shelve_changes(creator, 'foo')
650
740
metadata = shelf_manager.get_metadata(shelf_id)