46
46
tree.add(['foo'], ['foo-id'])
48
48
tree.rename_one('foo', 'bar')
49
tree.lock_tree_write()
50
self.addCleanup(tree.unlock)
51
49
creator = shelf.ShelfCreator(tree, tree.basis_tree())
52
50
self.addCleanup(creator.finalize)
53
51
self.assertEqual([('rename', 'foo-id', 'foo', 'bar')],
65
63
def test_shelve_rename(self):
64
self.thisFailsStrictLockCheck()
66
65
creator = self.prepare_shelve_rename()
67
66
creator.shelve_rename('foo-id')
68
67
self.check_shelve_rename(creator)
70
69
def test_shelve_change_handles_rename(self):
70
self.thisFailsStrictLockCheck()
71
71
creator = self.prepare_shelve_rename()
72
72
creator.shelve_change(('rename', 'foo-id', 'foo', 'bar'))
73
73
self.check_shelve_rename(creator)
78
78
tree.add(['foo', 'bar', 'foo/baz'], ['foo-id', 'bar-id', 'baz-id'])
80
80
tree.rename_one('foo/baz', 'bar/baz')
81
tree.lock_tree_write()
82
self.addCleanup(tree.unlock)
83
81
creator = shelf.ShelfCreator(tree, tree.basis_tree())
84
82
self.addCleanup(creator.finalize)
85
83
self.assertEqual([('rename', 'baz-id', 'foo/baz', 'bar/baz')],
99
97
self.assertEqual('foo/baz', tree.id2path('baz-id'))
101
99
def test_shelve_move(self):
100
self.thisFailsStrictLockCheck()
102
101
creator, tree = self.prepare_shelve_move()
103
102
creator.shelve_rename('baz-id')
104
103
self.check_shelve_move(creator, tree)
106
105
def test_shelve_change_handles_move(self):
106
self.thisFailsStrictLockCheck()
107
107
creator, tree = self.prepare_shelve_move()
108
108
creator.shelve_change(('rename', 'baz-id', 'foo/baz', 'bar/baz'))
109
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
111
def assertShelvedFileEqual(self, expected_content, creator, file_id):
135
112
s_trans_id = creator.shelf_transform.trans_id_file_id(file_id)
136
113
shelf_file = creator.shelf_transform._limbo_name(s_trans_id)
137
114
self.assertFileEqual(expected_content, shelf_file)
139
def prepare_content_change(self):
116
def test_shelve_content_change(self):
117
self.thisFailsStrictLockCheck()
140
118
tree = self.make_branch_and_tree('.')
141
119
tree.lock_write()
142
120
self.addCleanup(tree.unlock)
146
124
self.build_tree_contents([('foo', 'b\na\nc\n')])
147
125
creator = shelf.ShelfCreator(tree, tree.basis_tree())
148
126
self.addCleanup(creator.finalize)
151
def test_shelve_content_change(self):
152
creator = self.prepare_content_change()
153
127
self.assertEqual([('modify text', 'foo-id')],
154
128
list(creator.iter_shelvable()))
155
129
creator.shelve_lines('foo-id', ['a\n', 'c\n'])
157
131
self.assertFileEqual('a\nc\n', 'foo')
158
132
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')
174
135
def prepare_shelve_creation(self):
175
136
tree = self.make_branch_and_tree('.')
206
168
self.check_shelve_creation(creator, tree)
208
170
def test_shelve_change_handles_creation(self):
171
self.thisFailsStrictLockCheck()
209
172
creator, tree = self.prepare_shelve_creation()
210
173
creator.shelve_change(('add file', 'foo-id', 'file', 'foo'))
211
174
creator.shelve_change(('add file', 'bar-id', 'directory', 'bar'))
238
201
self.assertEqual(link_target, ptree.get_symlink_target('foo-id'))
240
203
def test_shelve_symlink_creation(self):
204
self.thisFailsStrictLockCheck()
241
205
self._test_shelve_symlink_creation('foo', 'bar')
243
207
def test_shelve_unicode_symlink_creation(self):
244
208
self.requireFeature(tests.UnicodeFilenameFeature)
209
self.thisFailsStrictLockCheck()
245
210
self._test_shelve_symlink_creation(u'fo\N{Euro Sign}o',
246
211
u'b\N{Euro Sign}ar')
248
213
def test_shelve_change_handles_symlink_creation(self):
214
self.thisFailsStrictLockCheck()
249
215
self._test_shelve_symlink_creation('foo', 'bar', shelve_change=True)
251
217
def _test_shelve_symlink_target_change(self, link_name,
279
245
self.assertEqual(new_target, ptree.get_symlink_target('foo-id'))
281
247
def test_shelve_symlink_target_change(self):
248
self.thisFailsStrictLockCheck()
282
249
self._test_shelve_symlink_target_change('foo', 'bar', 'baz')
284
251
def test_shelve_unicode_symlink_target_change(self):
252
self.thisFailsStrictLockCheck()
285
253
self.requireFeature(tests.UnicodeFilenameFeature)
286
254
self._test_shelve_symlink_target_change(
287
255
u'fo\N{Euro Sign}o', u'b\N{Euro Sign}ar', u'b\N{Euro Sign}az')
289
257
def test_shelve_change_handles_symlink_target_change(self):
258
self.thisFailsStrictLockCheck()
290
259
self._test_shelve_symlink_target_change('foo', 'bar', 'baz',
291
260
shelve_change=True)
293
262
def test_shelve_creation_no_contents(self):
263
self.thisFailsStrictLockCheck()
294
264
tree = self.make_branch_and_tree('.')
295
265
tree.lock_write()
296
266
self.addCleanup(tree.unlock)
342
313
self.check_shelve_deletion(tree)
344
315
def test_shelve_change_handles_deletion(self):
316
self.thisFailsStrictLockCheck()
345
317
creator, tree = self.prepare_shelve_deletion()
346
318
creator.shelve_change(('delete file', 'foo-id', 'directory', 'foo'))
347
319
creator.shelve_change(('delete file', 'bar-id', 'file', 'foo/bar'))
349
321
self.check_shelve_deletion(tree)
351
323
def test_shelve_delete_contents(self):
324
self.thisFailsStrictLockCheck()
352
325
tree = self.make_branch_and_tree('tree')
353
326
self.build_tree(['tree/foo',])
354
327
tree.add('foo', 'foo-id')
355
328
tree.commit('Added file and directory')
356
329
os.unlink('tree/foo')
357
tree.lock_tree_write()
358
self.addCleanup(tree.unlock)
359
330
creator = shelf.ShelfCreator(tree, tree.basis_tree())
360
331
self.addCleanup(creator.finalize)
361
332
self.assertEqual([('delete file', 'foo-id', 'file', 'foo')],
386
355
creator.shelf_transform._new_contents[s_trans_id])
388
357
def test_shelve_change_kind(self):
358
self.thisFailsStrictLockCheck()
389
359
creator = self.prepare_shelve_change_kind()
390
360
creator.shelve_content_change('foo-id')
391
361
creator.transform()
392
362
self.check_shelve_change_kind(creator)
394
364
def test_shelve_change_handles_change_kind(self):
365
self.thisFailsStrictLockCheck()
395
366
creator = self.prepare_shelve_change_kind()
396
367
creator.shelve_change(('change kind', 'foo-id', 'file', 'directory',
399
370
self.check_shelve_change_kind(creator)
401
372
def test_shelve_change_unknown_change(self):
373
self.thisFailsStrictLockCheck()
402
374
tree = self.make_branch_and_tree('tree')
403
tree.lock_tree_write()
404
self.addCleanup(tree.unlock)
405
375
creator = shelf.ShelfCreator(tree, tree.basis_tree())
406
376
self.addCleanup(creator.finalize)
407
377
e = self.assertRaises(ValueError, creator.shelve_change, ('unknown',))
408
378
self.assertEqual('Unknown change kind: "unknown"', str(e))
410
380
def test_shelve_unversion(self):
381
self.thisFailsStrictLockCheck()
411
382
tree = self.make_branch_and_tree('tree')
412
383
self.build_tree(['tree/foo',])
413
384
tree.add('foo', 'foo-id')
414
385
tree.commit('Added file and directory')
415
386
tree.unversion(['foo-id'])
416
tree.lock_tree_write()
417
self.addCleanup(tree.unlock)
418
387
creator = shelf.ShelfCreator(tree, tree.basis_tree())
419
388
self.addCleanup(creator.finalize)
420
389
self.assertEqual([('delete file', 'foo-id', 'file', 'foo')],
424
393
self.failUnlessExists('tree/foo')
426
395
def test_shelve_serialization(self):
396
self.thisFailsStrictLockCheck()
427
397
tree = self.make_branch_and_tree('.')
428
tree.lock_tree_write()
429
self.addCleanup(tree.unlock)
430
398
creator = shelf.ShelfCreator(tree, tree.basis_tree())
431
399
self.addCleanup(creator.finalize)
432
400
shelf_file = open('shelf', 'wb')
438
406
self.assertFileEqual(EMPTY_SHELF, 'shelf')
440
408
def test_write_shelf(self):
409
self.thisFailsStrictLockCheck()
441
410
tree = self.make_branch_and_tree('tree')
442
411
self.build_tree(['tree/foo'])
443
412
tree.add('foo', 'foo-id')
444
tree.lock_tree_write()
445
self.addCleanup(tree.unlock)
446
413
creator = shelf.ShelfCreator(tree, tree.basis_tree())
447
414
self.addCleanup(creator.finalize)
448
415
list(creator.iter_shelvable())
466
433
tt.deserialize(records)
468
435
def test_shelve_unversioned(self):
436
self.thisFailsStrictLockCheck()
469
437
tree = self.make_branch_and_tree('tree')
470
tree.lock_tree_write()
472
self.assertRaises(errors.PathsNotVersionedError,
473
shelf.ShelfCreator, tree, tree.basis_tree(), ['foo'])
438
self.assertRaises(errors.PathsNotVersionedError,
439
shelf.ShelfCreator, tree, tree.basis_tree(), ['foo'])
476
440
# We should be able to lock/unlock the tree if ShelfCreator cleaned
478
442
wt = workingtree.WorkingTree.open('tree')
481
445
# And a second tentative should raise the same error (no
482
446
# 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()))
447
self.assertRaises(errors.PathsNotVersionedError,
448
shelf.ShelfCreator, tree, tree.basis_tree(), ['foo'])
509
451
class TestUnshelver(tests.TestCaseWithTransport):
511
453
def test_make_merger(self):
454
self.thisFailsStrictLockCheck()
512
455
tree = self.make_branch_and_tree('tree')
513
456
tree.commit('first commit')
514
457
self.build_tree_contents([('tree/foo', 'bar')])
526
469
shelf_file.seek(0)
527
470
unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
528
471
unshelver.make_merger().do_merge()
529
self.addCleanup(unshelver.finalize)
530
472
self.assertFileEqual('bar', 'tree/foo')
532
474
shelf_file.close()
534
476
def test_unshelve_changed(self):
477
self.thisFailsStrictLockCheck()
535
478
tree = self.make_branch_and_tree('tree')
536
479
tree.lock_write()
537
480
self.addCleanup(tree.unlock)
550
493
self.build_tree_contents([('tree/foo', 'z\na\nb\nc\n')])
551
494
shelf_file.seek(0)
552
495
unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
553
self.addCleanup(unshelver.finalize)
554
496
unshelver.make_merger().do_merge()
555
497
self.assertFileEqual('z\na\nb\nd\n', 'tree/foo')
557
499
def test_unshelve_deleted(self):
500
self.thisFailsStrictLockCheck()
558
501
tree = self.make_branch_and_tree('tree')
559
502
tree.lock_write()
560
503
self.addCleanup(tree.unlock)
579
522
self.assertFileEqual('baz', 'tree/foo/bar')
580
523
shelf_file.seek(0)
581
524
unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
582
self.addCleanup(unshelver.finalize)
583
525
unshelver.make_merger().do_merge()
584
526
self.assertFalse('foo-id' in tree)
585
527
self.assertFalse('bar-id' in tree)
587
529
def test_unshelve_base(self):
530
self.thisFailsStrictLockCheck()
588
531
tree = self.make_branch_and_tree('tree')
589
532
tree.lock_write()
590
533
self.addCleanup(tree.unlock)
605
548
self.assertEqual('rev1', unshelver.base_tree.get_revision_id())
607
550
def test_unshelve_serialization(self):
551
self.thisFailsStrictLockCheck()
608
552
tree = self.make_branch_and_tree('.')
609
553
self.build_tree_contents([('shelf', EMPTY_SHELF)])
610
554
shelf_file = open('shelf', 'rb')
611
555
self.addCleanup(shelf_file.close)
612
556
unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
615
558
def test_corrupt_shelf(self):
559
self.thisFailsStrictLockCheck()
616
560
tree = self.make_branch_and_tree('.')
617
561
self.build_tree_contents([('shelf', EMPTY_SHELF.replace('metadata',
725
669
shelf_id = shelf_manager.shelve_changes(creator)
726
670
self.failIfExists('tree/foo')
727
671
unshelver = shelf_manager.get_unshelver(shelf_id)
728
self.addCleanup(unshelver.finalize)
729
672
unshelver.make_merger().do_merge()
730
673
self.assertFileEqual('bar', 'tree/foo')
732
675
def test_get_metadata(self):
733
676
tree = self.make_branch_and_tree('.')
734
tree.lock_tree_write()
735
self.addCleanup(tree.unlock)
736
677
creator = shelf.ShelfCreator(tree, tree.basis_tree())
737
self.addCleanup(creator.finalize)
738
678
shelf_manager = tree.get_shelf_manager()
739
679
shelf_id = shelf_manager.shelve_changes(creator, 'foo')
740
680
metadata = shelf_manager.get_metadata(shelf_id)