173
159
transform.finalize()
174
160
transform.finalize()
176
def test_apply_informs_tree_of_observed_sha1(self):
177
trans, root, contents, sha1 = self.get_transform_for_sha1_test()
178
trans_id = trans.new_file('file1', root, contents, file_id='file1-id',
181
orig = self.wt._observed_sha1
182
def _observed_sha1(*args):
185
self.wt._observed_sha1 = _observed_sha1
187
self.assertEqual([(None, 'file1', trans._observed_sha1s[trans_id])],
190
def test_create_file_caches_sha1(self):
191
trans, root, contents, sha1 = self.get_transform_for_sha1_test()
192
trans_id = trans.create_path('file1', root)
193
trans.create_file(contents, trans_id, sha1=sha1)
194
st_val = osutils.lstat(trans._limbo_name(trans_id))
195
o_sha1, o_st_val = trans._observed_sha1s[trans_id]
196
self.assertEqual(o_sha1, sha1)
197
self.assertEqualStat(o_st_val, st_val)
199
def test__apply_insertions_updates_sha1(self):
200
trans, root, contents, sha1 = self.get_transform_for_sha1_test()
201
trans_id = trans.create_path('file1', root)
202
trans.create_file(contents, trans_id, sha1=sha1)
203
st_val = osutils.lstat(trans._limbo_name(trans_id))
204
o_sha1, o_st_val = trans._observed_sha1s[trans_id]
205
self.assertEqual(o_sha1, sha1)
206
self.assertEqualStat(o_st_val, st_val)
207
creation_mtime = trans._creation_mtime + 10.0
208
# We fake a time difference from when the file was created until now it
209
# is being renamed by using os.utime. Note that the change we actually
210
# want to see is the real ctime change from 'os.rename()', but as long
211
# as we observe a new stat value, we should be fine.
212
os.utime(trans._limbo_name(trans_id), (creation_mtime, creation_mtime))
214
new_st_val = osutils.lstat(self.wt.abspath('file1'))
215
o_sha1, o_st_val = trans._observed_sha1s[trans_id]
216
self.assertEqual(o_sha1, sha1)
217
self.assertEqualStat(o_st_val, new_st_val)
218
self.assertNotEqual(st_val.st_mtime, new_st_val.st_mtime)
220
def test_new_file_caches_sha1(self):
221
trans, root, contents, sha1 = self.get_transform_for_sha1_test()
222
trans_id = trans.new_file('file1', root, contents, file_id='file1-id',
224
st_val = osutils.lstat(trans._limbo_name(trans_id))
225
o_sha1, o_st_val = trans._observed_sha1s[trans_id]
226
self.assertEqual(o_sha1, sha1)
227
self.assertEqualStat(o_st_val, st_val)
229
def test_cancel_creation_removes_observed_sha1(self):
230
trans, root, contents, sha1 = self.get_transform_for_sha1_test()
231
trans_id = trans.new_file('file1', root, contents, file_id='file1-id',
233
self.assertTrue(trans_id in trans._observed_sha1s)
234
trans.cancel_creation(trans_id)
235
self.assertFalse(trans_id in trans._observed_sha1s)
237
162
def test_create_files_same_timestamp(self):
238
163
transform, root = self.get_transform()
239
164
self.wt.lock_tree_write()
287
212
new_trans_id = transform.new_directory('', ROOT_PARENT, 'alt-root-id')
288
213
self.assertRaises(ValueError, transform.fixup_new_roots)
290
def test_retain_existing_root(self):
291
tt, root = self.get_transform()
293
tt.new_directory('', ROOT_PARENT, 'new-root-id')
295
self.assertNotEqual('new-root-id', tt.final_file_id(tt.root))
297
def test_retain_existing_root_added_file(self):
298
tt, root = self.get_transform()
299
new_trans_id = tt.new_directory('', ROOT_PARENT, 'new-root-id')
300
child = tt.new_directory('child', new_trans_id, 'child-id')
302
self.assertEqual(tt.root, tt.final_parent(child))
304
def test_add_unversioned_root(self):
305
transform, root = self.get_transform()
306
new_trans_id = transform.new_directory('', ROOT_PARENT, None)
307
transform.delete_contents(transform.root)
308
transform.fixup_new_roots()
309
self.assertNotIn(transform.root, transform._new_id)
311
def test_remove_root_fixup(self):
312
transform, root = self.get_transform()
313
old_root_id = self.wt.get_root_id()
314
self.assertNotEqual('new-root-id', old_root_id)
315
transform.delete_contents(root)
316
transform.unversion_file(root)
317
transform.fixup_new_roots()
319
self.assertEqual(old_root_id, self.wt.get_root_id())
321
transform, root = self.get_transform()
322
new_trans_id = transform.new_directory('', ROOT_PARENT, 'new-root-id')
323
new_trans_id = transform.new_directory('', ROOT_PARENT, 'alt-root-id')
324
self.assertRaises(ValueError, transform.fixup_new_roots)
326
def test_fixup_new_roots_permits_empty_tree(self):
327
transform, root = self.get_transform()
328
transform.delete_contents(root)
329
transform.unversion_file(root)
330
transform.fixup_new_roots()
331
self.assertIs(None, transform.final_kind(root))
332
self.assertIs(None, transform.final_file_id(root))
334
def test_apply_retains_root_directory(self):
335
# Do not attempt to delete the physical root directory, because that
337
transform, root = self.get_transform()
339
transform.delete_contents(root)
340
e = self.assertRaises(AssertionError, self.assertRaises,
341
errors.TransformRenameFailed,
343
self.assertContainsRe('TransformRenameFailed not raised', str(e))
345
def test_apply_retains_file_id(self):
346
transform, root = self.get_transform()
347
old_root_id = transform.tree_file_id(root)
348
transform.unversion_file(root)
350
self.assertEqual(old_root_id, self.wt.get_root_id())
352
215
def test_hardlink(self):
353
216
self.requireFeature(HardlinkFeature)
354
217
transform, root = self.get_transform()
1663
1499
return template % ('<' * 7, tree, '=' * 7, merge, '>' * 7)
1666
class TestInventoryAltered(tests.TestCaseWithTransport):
1668
def test_inventory_altered_unchanged(self):
1669
tree = self.make_branch_and_tree('tree')
1670
self.build_tree(['tree/foo'])
1671
tree.add('foo', 'foo-id')
1672
with TransformPreview(tree) as tt:
1673
self.assertEqual([], tt._inventory_altered())
1675
def test_inventory_altered_changed_parent_id(self):
1676
tree = self.make_branch_and_tree('tree')
1677
self.build_tree(['tree/foo'])
1678
tree.add('foo', 'foo-id')
1679
with TransformPreview(tree) as tt:
1680
tt.unversion_file(tt.root)
1681
tt.version_file('new-id', tt.root)
1682
foo_trans_id = tt.trans_id_tree_file_id('foo-id')
1683
foo_tuple = ('foo', foo_trans_id)
1684
root_tuple = ('', tt.root)
1685
self.assertEqual([root_tuple, foo_tuple], tt._inventory_altered())
1687
def test_inventory_altered_noop_changed_parent_id(self):
1688
tree = self.make_branch_and_tree('tree')
1689
self.build_tree(['tree/foo'])
1690
tree.add('foo', 'foo-id')
1691
with TransformPreview(tree) as tt:
1692
tt.unversion_file(tt.root)
1693
tt.version_file(tree.get_root_id(), tt.root)
1694
foo_trans_id = tt.trans_id_tree_file_id('foo-id')
1695
self.assertEqual([], tt._inventory_altered())
1698
1502
class TestTransformMerge(TestCaseInTempDir):
1700
1504
def test_text_merge(self):
2241
2033
self.assertEqual('file.moved', target.id2path('lower-id'))
2242
2034
self.assertEqual('FILE', target.id2path('upper-id'))
2244
def test_build_tree_observes_sha(self):
2245
source = self.make_branch_and_tree('source')
2246
self.build_tree(['source/file1', 'source/dir/', 'source/dir/file2'])
2247
source.add(['file1', 'dir', 'dir/file2'],
2248
['file1-id', 'dir-id', 'file2-id'])
2249
source.commit('new files')
2250
target = self.make_branch_and_tree('target')
2252
self.addCleanup(target.unlock)
2253
# We make use of the fact that DirState caches its cutoff time. So we
2254
# set the 'safe' time to one minute in the future.
2255
state = target.current_dirstate()
2256
state._cutoff_time = time.time() + 60
2257
build_tree(source.basis_tree(), target)
2258
entry1_sha = osutils.sha_file_by_name('source/file1')
2259
entry2_sha = osutils.sha_file_by_name('source/dir/file2')
2260
# entry[1] is the state information, entry[1][0] is the state of the
2261
# working tree, entry[1][0][1] is the sha value for the current working
2263
entry1 = state._get_entry(0, path_utf8='file1')
2264
self.assertEqual(entry1_sha, entry1[1][0][1])
2265
# The 'size' field must also be set.
2266
self.assertEqual(25, entry1[1][0][2])
2267
entry1_state = entry1[1][0]
2268
entry2 = state._get_entry(0, path_utf8='dir/file2')
2269
self.assertEqual(entry2_sha, entry2[1][0][1])
2270
self.assertEqual(29, entry2[1][0][2])
2271
entry2_state = entry2[1][0]
2272
# Now, make sure that we don't have to re-read the content. The
2273
# packed_stat should match exactly.
2274
self.assertEqual(entry1_sha, target.get_file_sha1('file1-id', 'file1'))
2275
self.assertEqual(entry2_sha,
2276
target.get_file_sha1('file2-id', 'dir/file2'))
2277
self.assertEqual(entry1_state, entry1[1][0])
2278
self.assertEqual(entry2_state, entry2[1][0])
2281
2037
class TestCommitTransform(tests.TestCaseWithTransport):
2416
2172
self.assertEqual('tree', revision.properties['branch-nick'])
2419
class TestBackupName(tests.TestCase):
2421
def test_deprecations(self):
2422
class MockTransform(object):
2424
def has_named_child(self, by_parent, parent_id, name):
2425
return name in by_parent.get(parent_id, [])
2427
class MockEntry(object):
2430
object.__init__(self)
2175
class MockTransform(object):
2177
def has_named_child(self, by_parent, parent_id, name):
2178
for child_id in by_parent[parent_id]:
2182
elif name == "name.~%s~" % child_id:
2187
class MockEntry(object):
2189
object.__init__(self)
2193
class TestGetBackupName(TestCase):
2194
def test_get_backup_name(self):
2433
2195
tt = MockTransform()
2434
name1 = self.applyDeprecated(
2435
symbol_versioning.deprecated_in((2, 3, 0)),
2436
transform.get_backup_name, MockEntry(), {'a':[]}, 'a', tt)
2437
self.assertEqual('name.~1~', name1)
2438
name2 = self.applyDeprecated(
2439
symbol_versioning.deprecated_in((2, 3, 0)),
2440
transform._get_backup_name, 'name', {'a':['name.~1~']}, 'a', tt)
2441
self.assertEqual('name.~2~', name2)
2196
name = get_backup_name(MockEntry(), {'a':[]}, 'a', tt)
2197
self.assertEqual(name, 'name.~1~')
2198
name = get_backup_name(MockEntry(), {'a':['1']}, 'a', tt)
2199
self.assertEqual(name, 'name.~2~')
2200
name = get_backup_name(MockEntry(), {'a':['2']}, 'a', tt)
2201
self.assertEqual(name, 'name.~1~')
2202
name = get_backup_name(MockEntry(), {'a':['2'], 'b':[]}, 'b', tt)
2203
self.assertEqual(name, 'name.~1~')
2204
name = get_backup_name(MockEntry(), {'a':['1', '2', '3']}, 'a', tt)
2205
self.assertEqual(name, 'name.~4~')
2444
2208
class TestFileMover(tests.TestCaseWithTransport):
2447
2211
self.build_tree(['a/', 'a/b', 'c/', 'c/d'])
2448
2212
mover = _FileMover()
2449
2213
mover.rename('a', 'q')
2450
self.assertPathExists('q')
2451
self.assertPathDoesNotExist('a')
2452
self.assertPathExists('q/b')
2453
self.assertPathExists('c')
2454
self.assertPathExists('c/d')
2214
self.failUnlessExists('q')
2215
self.failIfExists('a')
2216
self.failUnlessExists('q/b')
2217
self.failUnlessExists('c')
2218
self.failUnlessExists('c/d')
2456
2220
def test_pre_delete_rollback(self):
2457
2221
self.build_tree(['a/'])
2458
2222
mover = _FileMover()
2459
2223
mover.pre_delete('a', 'q')
2460
self.assertPathExists('q')
2461
self.assertPathDoesNotExist('a')
2224
self.failUnlessExists('q')
2225
self.failIfExists('a')
2462
2226
mover.rollback()
2463
self.assertPathDoesNotExist('q')
2464
self.assertPathExists('a')
2227
self.failIfExists('q')
2228
self.failUnlessExists('a')
2466
2230
def test_apply_deletions(self):
2467
2231
self.build_tree(['a/', 'b/'])
2468
2232
mover = _FileMover()
2469
2233
mover.pre_delete('a', 'q')
2470
2234
mover.pre_delete('b', 'r')
2471
self.assertPathExists('q')
2472
self.assertPathExists('r')
2473
self.assertPathDoesNotExist('a')
2474
self.assertPathDoesNotExist('b')
2235
self.failUnlessExists('q')
2236
self.failUnlessExists('r')
2237
self.failIfExists('a')
2238
self.failIfExists('b')
2475
2239
mover.apply_deletions()
2476
self.assertPathDoesNotExist('q')
2477
self.assertPathDoesNotExist('r')
2478
self.assertPathDoesNotExist('a')
2479
self.assertPathDoesNotExist('b')
2240
self.failIfExists('q')
2241
self.failIfExists('r')
2242
self.failIfExists('a')
2243
self.failIfExists('b')
2481
2245
def test_file_mover_rollback(self):
2482
2246
self.build_tree(['a/', 'a/b', 'c/', 'c/d/', 'c/e/'])
2556
2320
tt.adjust_path('d', tt.root, tt.trans_id_tree_path('a/b'))
2557
2321
self.assertRaises(Bogus, tt.apply,
2558
2322
_mover=self.ExceptionFileMover(bad_target='d'))
2559
self.assertPathExists('a')
2560
self.assertPathExists('a/b')
2563
class TestFinalizeRobustness(tests.TestCaseWithTransport):
2564
"""Ensure treetransform creation errors can be safely cleaned up after"""
2566
def _override_globals_in_method(self, instance, method_name, globals):
2567
"""Replace method on instance with one with updated globals"""
2569
func = getattr(instance, method_name).im_func
2570
new_globals = dict(func.func_globals)
2571
new_globals.update(globals)
2572
new_func = types.FunctionType(func.func_code, new_globals,
2573
func.func_name, func.func_defaults)
2574
setattr(instance, method_name,
2575
types.MethodType(new_func, instance, instance.__class__))
2576
self.addCleanup(delattr, instance, method_name)
2579
def _fake_open_raises_before(name, mode):
2580
"""Like open() but raises before doing anything"""
2584
def _fake_open_raises_after(name, mode):
2585
"""Like open() but raises after creating file without returning"""
2586
open(name, mode).close()
2589
def create_transform_and_root_trans_id(self):
2590
"""Setup a transform creating a file in limbo"""
2591
tree = self.make_branch_and_tree('.')
2592
tt = TreeTransform(tree)
2593
return tt, tt.create_path("a", tt.root)
2595
def create_transform_and_subdir_trans_id(self):
2596
"""Setup a transform creating a directory containing a file in limbo"""
2597
tree = self.make_branch_and_tree('.')
2598
tt = TreeTransform(tree)
2599
d_trans_id = tt.create_path("d", tt.root)
2600
tt.create_directory(d_trans_id)
2601
f_trans_id = tt.create_path("a", d_trans_id)
2602
tt.adjust_path("a", d_trans_id, f_trans_id)
2603
return tt, f_trans_id
2605
def test_root_create_file_open_raises_before_creation(self):
2606
tt, trans_id = self.create_transform_and_root_trans_id()
2607
self._override_globals_in_method(tt, "create_file",
2608
{"open": self._fake_open_raises_before})
2609
self.assertRaises(RuntimeError, tt.create_file, ["contents"], trans_id)
2610
path = tt._limbo_name(trans_id)
2611
self.assertPathDoesNotExist(path)
2613
self.assertPathDoesNotExist(tt._limbodir)
2615
def test_root_create_file_open_raises_after_creation(self):
2616
tt, trans_id = self.create_transform_and_root_trans_id()
2617
self._override_globals_in_method(tt, "create_file",
2618
{"open": self._fake_open_raises_after})
2619
self.assertRaises(RuntimeError, tt.create_file, ["contents"], trans_id)
2620
path = tt._limbo_name(trans_id)
2621
self.assertPathExists(path)
2623
self.assertPathDoesNotExist(path)
2624
self.assertPathDoesNotExist(tt._limbodir)
2626
def test_subdir_create_file_open_raises_before_creation(self):
2627
tt, trans_id = self.create_transform_and_subdir_trans_id()
2628
self._override_globals_in_method(tt, "create_file",
2629
{"open": self._fake_open_raises_before})
2630
self.assertRaises(RuntimeError, tt.create_file, ["contents"], trans_id)
2631
path = tt._limbo_name(trans_id)
2632
self.assertPathDoesNotExist(path)
2634
self.assertPathDoesNotExist(tt._limbodir)
2636
def test_subdir_create_file_open_raises_after_creation(self):
2637
tt, trans_id = self.create_transform_and_subdir_trans_id()
2638
self._override_globals_in_method(tt, "create_file",
2639
{"open": self._fake_open_raises_after})
2640
self.assertRaises(RuntimeError, tt.create_file, ["contents"], trans_id)
2641
path = tt._limbo_name(trans_id)
2642
self.assertPathExists(path)
2644
self.assertPathDoesNotExist(path)
2645
self.assertPathDoesNotExist(tt._limbodir)
2647
def test_rename_in_limbo_rename_raises_after_rename(self):
2648
tt, trans_id = self.create_transform_and_root_trans_id()
2649
parent1 = tt.new_directory('parent1', tt.root)
2650
child1 = tt.new_file('child1', parent1, 'contents')
2651
parent2 = tt.new_directory('parent2', tt.root)
2653
class FakeOSModule(object):
2654
def rename(self, old, new):
2657
self._override_globals_in_method(tt, "_rename_in_limbo",
2658
{"os": FakeOSModule()})
2660
RuntimeError, tt.adjust_path, "child1", parent2, child1)
2661
path = osutils.pathjoin(tt._limbo_name(parent2), "child1")
2662
self.assertPathExists(path)
2664
self.assertPathDoesNotExist(path)
2665
self.assertPathDoesNotExist(tt._limbodir)
2667
def test_rename_in_limbo_rename_raises_before_rename(self):
2668
tt, trans_id = self.create_transform_and_root_trans_id()
2669
parent1 = tt.new_directory('parent1', tt.root)
2670
child1 = tt.new_file('child1', parent1, 'contents')
2671
parent2 = tt.new_directory('parent2', tt.root)
2673
class FakeOSModule(object):
2674
def rename(self, old, new):
2676
self._override_globals_in_method(tt, "_rename_in_limbo",
2677
{"os": FakeOSModule()})
2679
RuntimeError, tt.adjust_path, "child1", parent2, child1)
2680
path = osutils.pathjoin(tt._limbo_name(parent1), "child1")
2681
self.assertPathExists(path)
2683
self.assertPathDoesNotExist(path)
2684
self.assertPathDoesNotExist(tt._limbodir)
2687
class TestTransformMissingParent(tests.TestCaseWithTransport):
2689
def make_tt_with_versioned_dir(self):
2323
self.failUnlessExists('a')
2324
self.failUnlessExists('a/b')
2326
def test_resolve_no_parent(self):
2690
2327
wt = self.make_branch_and_tree('.')
2691
self.build_tree(['dir/',])
2692
wt.add(['dir'], ['dir-id'])
2693
wt.commit('Create dir')
2694
2328
tt = TreeTransform(wt)
2695
2329
self.addCleanup(tt.finalize)
2698
def test_resolve_create_parent_for_versioned_file(self):
2699
wt, tt = self.make_tt_with_versioned_dir()
2700
dir_tid = tt.trans_id_tree_file_id('dir-id')
2701
file_tid = tt.new_file('file', dir_tid, 'Contents', file_id='file-id')
2702
tt.delete_contents(dir_tid)
2703
tt.unversion_file(dir_tid)
2704
conflicts = resolve_conflicts(tt)
2705
# one conflict for the missing directory, one for the unversioned
2707
self.assertLength(2, conflicts)
2709
def test_non_versioned_file_create_conflict(self):
2710
wt, tt = self.make_tt_with_versioned_dir()
2711
dir_tid = tt.trans_id_tree_file_id('dir-id')
2712
tt.new_file('file', dir_tid, 'Contents')
2713
tt.delete_contents(dir_tid)
2714
tt.unversion_file(dir_tid)
2715
conflicts = resolve_conflicts(tt)
2716
# no conflicts or rather: orphaning 'file' resolve the 'dir' conflict
2717
self.assertLength(1, conflicts)
2718
self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
2330
parent = tt.trans_id_file_id('parent-id')
2331
tt.new_file('file', parent, 'Contents')
2332
resolve_conflicts(tt)
2722
2335
A_ENTRY = ('a-id', ('a', 'a'), True, (True, True),
2723
2336
('TREE_ROOT', 'TREE_ROOT'), ('a', 'a'), ('file', 'file'),
2724
2337
(False, False))
2725
2338
ROOT_ENTRY = ('TREE_ROOT', ('', ''), False, (True, True), (None, None),
2726
('', ''), ('directory', 'directory'), (False, False))
2339
('', ''), ('directory', 'directory'), (False, None))
2729
2342
class TestTransformPreview(tests.TestCaseWithTransport):
3629
3212
trans_id = tt.trans_id_tree_path('file')
3630
3213
self.assertEqual((LINES_ONE,),
3631
3214
tt._get_parents_texts(trans_id))
3634
class TestOrphan(tests.TestCaseWithTransport):
3636
def test_no_orphan_for_transform_preview(self):
3637
tree = self.make_branch_and_tree('tree')
3638
tt = transform.TransformPreview(tree)
3639
self.addCleanup(tt.finalize)
3640
self.assertRaises(NotImplementedError, tt.new_orphan, 'foo', 'bar')
3642
def _set_orphan_policy(self, wt, policy):
3643
wt.branch.get_config().set_user_option('bzr.transform.orphan_policy',
3646
def _prepare_orphan(self, wt):
3647
self.build_tree(['dir/', 'dir/file', 'dir/foo'])
3648
wt.add(['dir', 'dir/file'], ['dir-id', 'file-id'])
3649
wt.commit('add dir and file ignoring foo')
3650
tt = transform.TreeTransform(wt)
3651
self.addCleanup(tt.finalize)
3652
# dir and bar are deleted
3653
dir_tid = tt.trans_id_tree_path('dir')
3654
file_tid = tt.trans_id_tree_path('dir/file')
3655
orphan_tid = tt.trans_id_tree_path('dir/foo')
3656
tt.delete_contents(file_tid)
3657
tt.unversion_file(file_tid)
3658
tt.delete_contents(dir_tid)
3659
tt.unversion_file(dir_tid)
3660
# There should be a conflict because dir still contain foo
3661
raw_conflicts = tt.find_conflicts()
3662
self.assertLength(1, raw_conflicts)
3663
self.assertEqual(('missing parent', 'new-1'), raw_conflicts[0])
3664
return tt, orphan_tid
3666
def test_new_orphan_created(self):
3667
wt = self.make_branch_and_tree('.')
3668
self._set_orphan_policy(wt, 'move')
3669
tt, orphan_tid = self._prepare_orphan(wt)
3672
warnings.append(args[0] % args[1:])
3673
self.overrideAttr(trace, 'warning', warning)
3674
remaining_conflicts = resolve_conflicts(tt)
3675
self.assertEquals(['dir/foo has been orphaned in bzr-orphans'],
3677
# Yeah for resolved conflicts !
3678
self.assertLength(0, remaining_conflicts)
3679
# We have a new orphan
3680
self.assertEquals('foo.~1~', tt.final_name(orphan_tid))
3681
self.assertEquals('bzr-orphans',
3682
tt.final_name(tt.final_parent(orphan_tid)))
3684
def test_never_orphan(self):
3685
wt = self.make_branch_and_tree('.')
3686
self._set_orphan_policy(wt, 'conflict')
3687
tt, orphan_tid = self._prepare_orphan(wt)
3688
remaining_conflicts = resolve_conflicts(tt)
3689
self.assertLength(1, remaining_conflicts)
3690
self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
3691
remaining_conflicts.pop())
3693
def test_orphan_error(self):
3694
def bogus_orphan(tt, orphan_id, parent_id):
3695
raise transform.OrphaningError(tt.final_name(orphan_id),
3696
tt.final_name(parent_id))
3697
transform.orphaning_registry.register('bogus', bogus_orphan,
3698
'Raise an error when orphaning')
3699
wt = self.make_branch_and_tree('.')
3700
self._set_orphan_policy(wt, 'bogus')
3701
tt, orphan_tid = self._prepare_orphan(wt)
3702
remaining_conflicts = resolve_conflicts(tt)
3703
self.assertLength(1, remaining_conflicts)
3704
self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
3705
remaining_conflicts.pop())
3707
def test_unknown_orphan_policy(self):
3708
wt = self.make_branch_and_tree('.')
3709
# Set a fictional policy nobody ever implemented
3710
self._set_orphan_policy(wt, 'donttouchmypreciouuus')
3711
tt, orphan_tid = self._prepare_orphan(wt)
3714
warnings.append(args[0] % args[1:])
3715
self.overrideAttr(trace, 'warning', warning)
3716
remaining_conflicts = resolve_conflicts(tt)
3717
# We fallback to the default policy which create a conflict
3718
self.assertLength(1, remaining_conflicts)
3719
self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
3720
remaining_conflicts.pop())
3721
self.assertLength(1, warnings)
3722
self.assertStartsWith(warnings[0], 'donttouchmypreciouuus')