~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

  • Committer: Vincent Ladeuil
  • Date: 2010-09-16 16:13:18 UTC
  • mto: (5502.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 5504.
  • Revision ID: v.ladeuil+lp@free.fr-20100916161318-c9k41sne1m12rxl9
Add ``bzrlib.transform.orphan_policy`` and allows ``never`` to restore the previous behaviour.

* bzrlib/transform.py:
(TreeTransformBase._get_potential_orphans): Simplified.
(DiskTreeTransform.new_orphan): Use the orphaning_registry.
(refuse_orphan): Implement the previous behaviour (never orphan).
(conflict_pass): Clarify orphan creation and fallback on error.

* bzrlib/tests/test_transform.py:
(TestOrphan.test_never_orphan): Add more tests to cover no
orphaning and orphaning errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3256
3256
 
3257
3257
class TestOrphan(tests.TestCaseWithTransport):
3258
3258
 
3259
 
    # Alternative implementations may want to test:
3260
 
    # - can't create orphan dir
3261
 
    # - orphaning forbidden
3262
 
    # - can't create orphan
3263
 
 
3264
3259
    def test_no_orphan_for_transform_preview(self):
3265
3260
        tree = self.make_branch_and_tree('tree')
3266
3261
        tt = transform.TransformPreview(tree)
3267
3262
        self.addCleanup(tt.finalize)
3268
3263
        self.assertRaises(NotImplementedError, tt.new_orphan, 'foo', 'bar')
3269
3264
 
3270
 
    def test_new_orphan_created(self):
3271
 
        wt = self.make_branch_and_tree('.')
 
3265
    def _set_orphan_policy(self, wt, policy):
 
3266
        wt.branch.get_config().set_user_option('bzrlib.transform.orphan_policy',
 
3267
                                               policy)
 
3268
 
 
3269
    def _prepare_orphan(self, wt):
3272
3270
        self.build_tree(['dir/', 'dir/foo'])
3273
3271
        wt.add(['dir'], ['dir-id'])
3274
3272
        wt.commit('add dir')
3275
3273
        tt = transform.TreeTransform(wt)
3276
3274
        self.addCleanup(tt.finalize)
3277
3275
        dir_tid = tt.trans_id_tree_path('dir')
3278
 
        foo_tid = tt.trans_id_tree_path('dir/foo')
 
3276
        orphan_tid = tt.trans_id_tree_path('dir/foo')
3279
3277
        tt.delete_contents(dir_tid)
3280
3278
        tt.unversion_file(dir_tid)
3281
3279
        raw_conflicts = tt.find_conflicts()
3282
3280
        self.assertLength(1, raw_conflicts)
3283
3281
        self.assertEqual(('missing parent', 'new-1'), raw_conflicts[0])
 
3282
        return tt, orphan_tid
 
3283
 
 
3284
    def test_new_orphan_created(self):
 
3285
        wt = self.make_branch_and_tree('.')
 
3286
        tt, orphan_tid = self._prepare_orphan(wt)
3284
3287
        remaining_conflicts = resolve_conflicts(tt)
3285
3288
        # Yeah for resolved conflicts !
3286
3289
        self.assertLength(0, remaining_conflicts)
3287
3290
        # We have a new orphan
3288
 
        self.assertEquals('foo.~1~', tt.final_name(foo_tid))
 
3291
        self.assertEquals('foo.~1~', tt.final_name(orphan_tid))
3289
3292
        self.assertEquals('bzr-orphans',
3290
 
                          tt.final_name(tt.final_parent(foo_tid)))
 
3293
                          tt.final_name(tt.final_parent(orphan_tid)))
 
3294
 
 
3295
    def test_never_orphan(self):
 
3296
        wt = self.make_branch_and_tree('.')
 
3297
        self._set_orphan_policy(wt, 'never')
 
3298
        tt, orphan_tid = self._prepare_orphan(wt)
 
3299
        remaining_conflicts = resolve_conflicts(tt)
 
3300
        self.assertLength(1, remaining_conflicts)
 
3301
        self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
 
3302
                         remaining_conflicts.pop())
 
3303
 
 
3304
    def test_orphan_error(self):
 
3305
        def bogus_orphan(tt, orphan_id, parent_id):
 
3306
            raise transform.OrphaningError(tt.final_name(orphan_id),
 
3307
                                           tt.final_name(parent_id))
 
3308
        transform.orphaning_registry.register('bogus', bogus_orphan,
 
3309
                                              'Raise an error when orphaning')
 
3310
        wt = self.make_branch_and_tree('.')
 
3311
        self._set_orphan_policy(wt, 'bogus')
 
3312
        tt, orphan_tid = self._prepare_orphan(wt)
 
3313
        remaining_conflicts = resolve_conflicts(tt)
 
3314
        self.assertLength(1, remaining_conflicts)
 
3315
        self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
 
3316
                         remaining_conflicts.pop())