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')],
63
65
def test_shelve_rename(self):
64
self.thisFailsStrictLockCheck()
65
66
creator = self.prepare_shelve_rename()
66
67
creator.shelve_rename('foo-id')
67
68
self.check_shelve_rename(creator)
69
70
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)
81
83
creator = shelf.ShelfCreator(tree, tree.basis_tree())
82
84
self.addCleanup(creator.finalize)
83
85
self.assertEqual([('rename', 'baz-id', 'foo/baz', 'bar/baz')],
97
99
self.assertEqual('foo/baz', tree.id2path('baz-id'))
99
101
def test_shelve_move(self):
100
self.thisFailsStrictLockCheck()
101
102
creator, tree = self.prepare_shelve_move()
102
103
creator.shelve_rename('baz-id')
103
104
self.check_shelve_move(creator, tree)
105
106
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)
114
114
self.assertFileEqual(expected_content, shelf_file)
116
116
def prepare_content_change(self):
117
self.thisFailsStrictLockCheck()
118
117
tree = self.make_branch_and_tree('.')
119
118
tree.lock_write()
120
119
self.addCleanup(tree.unlock)
177
176
creator.shelf_transform.final_kind(s_bar_trans_id))
179
178
def test_shelve_creation(self):
180
self.thisFailsStrictLockCheck()
181
179
creator, tree = self.prepare_shelve_creation()
182
180
creator.shelve_creation('foo-id')
183
181
creator.shelve_creation('bar-id')
185
183
self.check_shelve_creation(creator, tree)
187
185
def test_shelve_change_handles_creation(self):
188
self.thisFailsStrictLockCheck()
189
186
creator, tree = self.prepare_shelve_creation()
190
187
creator.shelve_change(('add file', 'foo-id', 'file', 'foo'))
191
188
creator.shelve_change(('add file', 'bar-id', 'directory', 'bar'))
218
215
self.assertEqual(link_target, ptree.get_symlink_target('foo-id'))
220
217
def test_shelve_symlink_creation(self):
221
self.thisFailsStrictLockCheck()
222
218
self._test_shelve_symlink_creation('foo', 'bar')
224
220
def test_shelve_unicode_symlink_creation(self):
225
221
self.requireFeature(tests.UnicodeFilenameFeature)
226
self.thisFailsStrictLockCheck()
227
222
self._test_shelve_symlink_creation(u'fo\N{Euro Sign}o',
228
223
u'b\N{Euro Sign}ar')
230
225
def test_shelve_change_handles_symlink_creation(self):
231
self.thisFailsStrictLockCheck()
232
226
self._test_shelve_symlink_creation('foo', 'bar', shelve_change=True)
234
228
def _test_shelve_symlink_target_change(self, link_name,
262
256
self.assertEqual(new_target, ptree.get_symlink_target('foo-id'))
264
258
def test_shelve_symlink_target_change(self):
265
self.thisFailsStrictLockCheck()
266
259
self._test_shelve_symlink_target_change('foo', 'bar', 'baz')
268
261
def test_shelve_unicode_symlink_target_change(self):
269
self.thisFailsStrictLockCheck()
270
262
self.requireFeature(tests.UnicodeFilenameFeature)
271
263
self._test_shelve_symlink_target_change(
272
264
u'fo\N{Euro Sign}o', u'b\N{Euro Sign}ar', u'b\N{Euro Sign}az')
274
266
def test_shelve_change_handles_symlink_target_change(self):
275
self.thisFailsStrictLockCheck()
276
267
self._test_shelve_symlink_target_change('foo', 'bar', 'baz',
277
268
shelve_change=True)
279
270
def test_shelve_creation_no_contents(self):
280
self.thisFailsStrictLockCheck()
281
271
tree = self.make_branch_and_tree('.')
282
272
tree.lock_write()
283
273
self.addCleanup(tree.unlock)
322
312
self.assertFileEqual('baz', 'tree/foo/bar')
324
314
def test_shelve_deletion(self):
325
self.thisFailsStrictLockCheck()
326
315
creator, tree = self.prepare_shelve_deletion()
327
316
creator.shelve_deletion('foo-id')
328
317
creator.shelve_deletion('bar-id')
330
319
self.check_shelve_deletion(tree)
332
321
def test_shelve_change_handles_deletion(self):
333
self.thisFailsStrictLockCheck()
334
322
creator, tree = self.prepare_shelve_deletion()
335
323
creator.shelve_change(('delete file', 'foo-id', 'directory', 'foo'))
336
324
creator.shelve_change(('delete file', 'bar-id', 'file', 'foo/bar'))
338
326
self.check_shelve_deletion(tree)
340
328
def test_shelve_delete_contents(self):
341
self.thisFailsStrictLockCheck()
342
329
tree = self.make_branch_and_tree('tree')
343
330
self.build_tree(['tree/foo',])
344
331
tree.add('foo', 'foo-id')
345
332
tree.commit('Added file and directory')
346
333
os.unlink('tree/foo')
334
tree.lock_tree_write()
335
self.addCleanup(tree.unlock)
347
336
creator = shelf.ShelfCreator(tree, tree.basis_tree())
348
337
self.addCleanup(creator.finalize)
349
338
self.assertEqual([('delete file', 'foo-id', 'file', 'foo')],
359
348
tree.commit('Added file and directory')
360
349
os.unlink('tree/foo')
361
350
os.mkdir('tree/foo')
351
tree.lock_tree_write()
352
self.addCleanup(tree.unlock)
362
353
creator = shelf.ShelfCreator(tree, tree.basis_tree())
363
354
self.addCleanup(creator.finalize)
364
355
self.assertEqual([('change kind', 'foo-id', 'file', 'directory',
372
363
creator.shelf_transform._new_contents[s_trans_id])
374
365
def test_shelve_change_kind(self):
375
self.thisFailsStrictLockCheck()
376
366
creator = self.prepare_shelve_change_kind()
377
367
creator.shelve_content_change('foo-id')
378
368
creator.transform()
379
369
self.check_shelve_change_kind(creator)
381
371
def test_shelve_change_handles_change_kind(self):
382
self.thisFailsStrictLockCheck()
383
372
creator = self.prepare_shelve_change_kind()
384
373
creator.shelve_change(('change kind', 'foo-id', 'file', 'directory',
387
376
self.check_shelve_change_kind(creator)
389
378
def test_shelve_change_unknown_change(self):
390
self.thisFailsStrictLockCheck()
391
379
tree = self.make_branch_and_tree('tree')
380
tree.lock_tree_write()
381
self.addCleanup(tree.unlock)
392
382
creator = shelf.ShelfCreator(tree, tree.basis_tree())
393
383
self.addCleanup(creator.finalize)
394
384
e = self.assertRaises(ValueError, creator.shelve_change, ('unknown',))
395
385
self.assertEqual('Unknown change kind: "unknown"', str(e))
397
387
def test_shelve_unversion(self):
398
self.thisFailsStrictLockCheck()
399
388
tree = self.make_branch_and_tree('tree')
400
389
self.build_tree(['tree/foo',])
401
390
tree.add('foo', 'foo-id')
402
391
tree.commit('Added file and directory')
403
392
tree.unversion(['foo-id'])
393
tree.lock_tree_write()
394
self.addCleanup(tree.unlock)
404
395
creator = shelf.ShelfCreator(tree, tree.basis_tree())
405
396
self.addCleanup(creator.finalize)
406
397
self.assertEqual([('delete file', 'foo-id', 'file', 'foo')],
410
401
self.failUnlessExists('tree/foo')
412
403
def test_shelve_serialization(self):
413
self.thisFailsStrictLockCheck()
414
404
tree = self.make_branch_and_tree('.')
405
tree.lock_tree_write()
406
self.addCleanup(tree.unlock)
415
407
creator = shelf.ShelfCreator(tree, tree.basis_tree())
416
408
self.addCleanup(creator.finalize)
417
409
shelf_file = open('shelf', 'wb')
423
415
self.assertFileEqual(EMPTY_SHELF, 'shelf')
425
417
def test_write_shelf(self):
426
self.thisFailsStrictLockCheck()
427
418
tree = self.make_branch_and_tree('tree')
428
419
self.build_tree(['tree/foo'])
429
420
tree.add('foo', 'foo-id')
421
tree.lock_tree_write()
422
self.addCleanup(tree.unlock)
430
423
creator = shelf.ShelfCreator(tree, tree.basis_tree())
431
424
self.addCleanup(creator.finalize)
432
425
list(creator.iter_shelvable())
450
443
tt.deserialize(records)
452
445
def test_shelve_unversioned(self):
453
self.thisFailsStrictLockCheck()
454
446
tree = self.make_branch_and_tree('tree')
455
self.assertRaises(errors.PathsNotVersionedError,
456
shelf.ShelfCreator, tree, tree.basis_tree(), ['foo'])
447
tree.lock_tree_write()
449
self.assertRaises(errors.PathsNotVersionedError,
450
shelf.ShelfCreator, tree, tree.basis_tree(), ['foo'])
457
453
# We should be able to lock/unlock the tree if ShelfCreator cleaned
459
455
wt = workingtree.WorkingTree.open('tree')
462
458
# And a second tentative should raise the same error (no
463
459
# limbo/pending_deletion leftovers).
464
self.assertRaises(errors.PathsNotVersionedError,
465
shelf.ShelfCreator, tree, tree.basis_tree(), ['foo'])
460
tree.lock_tree_write()
462
self.assertRaises(errors.PathsNotVersionedError,
463
shelf.ShelfCreator, tree, tree.basis_tree(), ['foo'])
467
def test_shelve_skips_added_root(self):
468
"""Skip adds of the root when iterating through shelvable changes."""
469
tree = self.make_branch_and_tree('tree')
470
tree.lock_tree_write()
471
self.addCleanup(tree.unlock)
472
creator = shelf.ShelfCreator(tree, tree.basis_tree())
473
self.addCleanup(creator.finalize)
474
self.assertEqual([], list(creator.iter_shelvable()))
476
def test_shelve_skips_added_root(self):
477
"""Skip adds of the root when iterating through shelvable changes."""
478
tree = self.make_branch_and_tree('tree')
479
tree.lock_tree_write()
480
self.addCleanup(tree.unlock)
481
creator = shelf.ShelfCreator(tree, tree.basis_tree())
482
self.addCleanup(creator.finalize)
483
self.assertEqual([], list(creator.iter_shelvable()))
468
486
class TestUnshelver(tests.TestCaseWithTransport):
470
488
def test_make_merger(self):
471
self.thisFailsStrictLockCheck()
472
489
tree = self.make_branch_and_tree('tree')
473
490
tree.commit('first commit')
474
491
self.build_tree_contents([('tree/foo', 'bar')])
486
503
shelf_file.seek(0)
487
504
unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
488
505
unshelver.make_merger().do_merge()
506
self.addCleanup(unshelver.finalize)
489
507
self.assertFileEqual('bar', 'tree/foo')
491
509
shelf_file.close()
493
511
def test_unshelve_changed(self):
494
self.thisFailsStrictLockCheck()
495
512
tree = self.make_branch_and_tree('tree')
496
513
tree.lock_write()
497
514
self.addCleanup(tree.unlock)
510
527
self.build_tree_contents([('tree/foo', 'z\na\nb\nc\n')])
511
528
shelf_file.seek(0)
512
529
unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
530
self.addCleanup(unshelver.finalize)
513
531
unshelver.make_merger().do_merge()
514
532
self.assertFileEqual('z\na\nb\nd\n', 'tree/foo')
516
534
def test_unshelve_deleted(self):
517
self.thisFailsStrictLockCheck()
518
535
tree = self.make_branch_and_tree('tree')
519
536
tree.lock_write()
520
537
self.addCleanup(tree.unlock)
539
556
self.assertFileEqual('baz', 'tree/foo/bar')
540
557
shelf_file.seek(0)
541
558
unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
559
self.addCleanup(unshelver.finalize)
542
560
unshelver.make_merger().do_merge()
543
561
self.assertFalse('foo-id' in tree)
544
562
self.assertFalse('bar-id' in tree)
546
564
def test_unshelve_base(self):
547
self.thisFailsStrictLockCheck()
548
565
tree = self.make_branch_and_tree('tree')
549
566
tree.lock_write()
550
567
self.addCleanup(tree.unlock)
565
582
self.assertEqual('rev1', unshelver.base_tree.get_revision_id())
567
584
def test_unshelve_serialization(self):
568
self.thisFailsStrictLockCheck()
569
585
tree = self.make_branch_and_tree('.')
570
586
self.build_tree_contents([('shelf', EMPTY_SHELF)])
571
587
shelf_file = open('shelf', 'rb')
572
588
self.addCleanup(shelf_file.close)
573
589
unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
575
592
def test_corrupt_shelf(self):
576
self.thisFailsStrictLockCheck()
577
593
tree = self.make_branch_and_tree('.')
578
594
self.build_tree_contents([('shelf', EMPTY_SHELF.replace('metadata',
686
702
shelf_id = shelf_manager.shelve_changes(creator)
687
703
self.failIfExists('tree/foo')
688
704
unshelver = shelf_manager.get_unshelver(shelf_id)
705
self.addCleanup(unshelver.finalize)
689
706
unshelver.make_merger().do_merge()
690
707
self.assertFileEqual('bar', 'tree/foo')
692
709
def test_get_metadata(self):
693
710
tree = self.make_branch_and_tree('.')
711
tree.lock_tree_write()
712
self.addCleanup(tree.unlock)
694
713
creator = shelf.ShelfCreator(tree, tree.basis_tree())
714
self.addCleanup(creator.finalize)
695
715
shelf_manager = tree.get_shelf_manager()
696
716
shelf_id = shelf_manager.shelve_changes(creator, 'foo')
697
717
metadata = shelf_manager.get_metadata(shelf_id)