/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_shelf.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-08-15 09:15:03 UTC
  • mfrom: (4595.7.4 409137-lsb-release)
  • Revision ID: pqm@pqm.ubuntu.com-20090815091503-qwbm6glvv31rnujw
(mbp) show platform in selftest, version and backtrace

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2008 Canonical Ltd
2
2
#
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
46
46
        tree.add(['foo'], ['foo-id'])
47
47
        tree.commit('foo')
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')],
63
61
                         shelf_trans_id))
64
62
 
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)
69
68
 
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'])
79
79
        tree.commit('foo')
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'))
100
98
 
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)
105
104
 
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)
110
110
 
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'])
116
 
        tree.commit('foo')
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',
123
 
            self.assertEqual, [
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()))
128
 
 
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()))
133
 
 
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)
138
115
 
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)
149
 
        return creator
150
 
 
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')
159
133
 
160
 
    def test_shelve_change_handles_modify_text(self):
161
 
        creator = self.prepare_content_change()
162
 
        creator.shelve_change(('modify text', 'foo-id'))
163
 
        creator.transform()
164
 
        self.assertFileEqual('a\n', 'foo')
165
 
        self.assertShelvedFileEqual('b\na\nc\n', creator, 'foo-id')
166
 
 
167
 
    def test_shelve_all(self):
168
 
        creator = self.prepare_content_change()
169
 
        creator.shelve_all()
170
 
        creator.transform()
171
 
        self.assertFileEqual('a\n', 'foo')
172
 
        self.assertShelvedFileEqual('b\na\nc\n', creator, 'foo-id')
173
134
 
174
135
    def prepare_shelve_creation(self):
175
136
        tree = self.make_branch_and_tree('.')
199
160
            creator.shelf_transform.final_kind(s_bar_trans_id))
200
161
 
201
162
    def test_shelve_creation(self):
 
163
        self.thisFailsStrictLockCheck()
202
164
        creator, tree = self.prepare_shelve_creation()
203
165
        creator.shelve_creation('foo-id')
204
166
        creator.shelve_creation('bar-id')
206
168
        self.check_shelve_creation(creator, tree)
207
169
 
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'))
239
202
 
240
203
    def test_shelve_symlink_creation(self):
 
204
        self.thisFailsStrictLockCheck()
241
205
        self._test_shelve_symlink_creation('foo', 'bar')
242
206
 
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')
247
212
 
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)
250
216
 
251
217
    def _test_shelve_symlink_target_change(self, link_name,
279
245
        self.assertEqual(new_target, ptree.get_symlink_target('foo-id'))
280
246
 
281
247
    def test_shelve_symlink_target_change(self):
 
248
        self.thisFailsStrictLockCheck()
282
249
        self._test_shelve_symlink_target_change('foo', 'bar', 'baz')
283
250
 
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')
288
256
 
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)
292
261
 
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)
335
305
        self.assertFileEqual('baz', 'tree/foo/bar')
336
306
 
337
307
    def test_shelve_deletion(self):
 
308
        self.thisFailsStrictLockCheck()
338
309
        creator, tree = self.prepare_shelve_deletion()
339
310
        creator.shelve_deletion('foo-id')
340
311
        creator.shelve_deletion('bar-id')
342
313
        self.check_shelve_deletion(tree)
343
314
 
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)
350
322
 
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')],
371
342
        tree.commit('Added file and directory')
372
343
        os.unlink('tree/foo')
373
344
        os.mkdir('tree/foo')
374
 
        tree.lock_tree_write()
375
 
        self.addCleanup(tree.unlock)
376
345
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
377
346
        self.addCleanup(creator.finalize)
378
347
        self.assertEqual([('change kind', 'foo-id', 'file', 'directory',
386
355
                         creator.shelf_transform._new_contents[s_trans_id])
387
356
 
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)
393
363
 
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',
397
368
                               'foo'))
399
370
        self.check_shelve_change_kind(creator)
400
371
 
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))
409
379
 
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')
425
394
 
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')
439
407
 
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)
467
434
 
468
435
    def test_shelve_unversioned(self):
 
436
        self.thisFailsStrictLockCheck()
469
437
        tree = self.make_branch_and_tree('tree')
470
 
        tree.lock_tree_write()
471
 
        try:
472
 
            self.assertRaises(errors.PathsNotVersionedError,
473
 
                              shelf.ShelfCreator, tree, tree.basis_tree(), ['foo'])
474
 
        finally:
475
 
            tree.unlock()
 
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
477
441
        # after itself.
478
442
        wt = workingtree.WorkingTree.open('tree')
480
444
        wt.unlock()
481
445
        # And a second tentative should raise the same error (no
482
446
        # limbo/pending_deletion leftovers).
483
 
        tree.lock_tree_write()
484
 
        try:
485
 
            self.assertRaises(errors.PathsNotVersionedError,
486
 
                              shelf.ShelfCreator, tree, tree.basis_tree(), ['foo'])
487
 
        finally:
488
 
            tree.unlock()
489
 
 
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()))
498
 
 
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'])
507
449
 
508
450
 
509
451
class TestUnshelver(tests.TestCaseWithTransport):
510
452
 
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')
531
473
        finally:
532
474
            shelf_file.close()
533
475
 
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')
556
498
 
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)
586
528
 
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())
606
549
 
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)
613
 
        unshelver.finalize()
614
557
 
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',
618
562
                                                                'foo'))])
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')
731
674
 
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)