159
174
transform.finalize()
160
175
transform.finalize()
177
def test_apply_informs_tree_of_observed_sha1(self):
178
trans, root, contents, sha1 = self.get_transform_for_sha1_test()
179
trans_id = trans.new_file('file1', root, contents, file_id='file1-id',
182
orig = self.wt._observed_sha1
183
def _observed_sha1(*args):
186
self.wt._observed_sha1 = _observed_sha1
188
self.assertEqual([(None, 'file1', trans._observed_sha1s[trans_id])],
191
def test_create_file_caches_sha1(self):
192
trans, root, contents, sha1 = self.get_transform_for_sha1_test()
193
trans_id = trans.create_path('file1', root)
194
trans.create_file(contents, trans_id, sha1=sha1)
195
st_val = osutils.lstat(trans._limbo_name(trans_id))
196
o_sha1, o_st_val = trans._observed_sha1s[trans_id]
197
self.assertEqual(o_sha1, sha1)
198
self.assertEqualStat(o_st_val, st_val)
200
def test__apply_insertions_updates_sha1(self):
201
trans, root, contents, sha1 = self.get_transform_for_sha1_test()
202
trans_id = trans.create_path('file1', root)
203
trans.create_file(contents, trans_id, sha1=sha1)
204
st_val = osutils.lstat(trans._limbo_name(trans_id))
205
o_sha1, o_st_val = trans._observed_sha1s[trans_id]
206
self.assertEqual(o_sha1, sha1)
207
self.assertEqualStat(o_st_val, st_val)
208
creation_mtime = trans._creation_mtime + 10.0
209
# We fake a time difference from when the file was created until now it
210
# is being renamed by using os.utime. Note that the change we actually
211
# want to see is the real ctime change from 'os.rename()', but as long
212
# as we observe a new stat value, we should be fine.
213
os.utime(trans._limbo_name(trans_id), (creation_mtime, creation_mtime))
215
new_st_val = osutils.lstat(self.wt.abspath('file1'))
216
o_sha1, o_st_val = trans._observed_sha1s[trans_id]
217
self.assertEqual(o_sha1, sha1)
218
self.assertEqualStat(o_st_val, new_st_val)
219
self.assertNotEqual(st_val.st_mtime, new_st_val.st_mtime)
221
def test_new_file_caches_sha1(self):
222
trans, root, contents, sha1 = self.get_transform_for_sha1_test()
223
trans_id = trans.new_file('file1', root, contents, file_id='file1-id',
225
st_val = osutils.lstat(trans._limbo_name(trans_id))
226
o_sha1, o_st_val = trans._observed_sha1s[trans_id]
227
self.assertEqual(o_sha1, sha1)
228
self.assertEqualStat(o_st_val, st_val)
230
def test_cancel_creation_removes_observed_sha1(self):
231
trans, root, contents, sha1 = self.get_transform_for_sha1_test()
232
trans_id = trans.new_file('file1', root, contents, file_id='file1-id',
234
self.assertTrue(trans_id in trans._observed_sha1s)
235
trans.cancel_creation(trans_id)
236
self.assertFalse(trans_id in trans._observed_sha1s)
162
238
def test_create_files_same_timestamp(self):
163
239
transform, root = self.get_transform()
164
240
self.wt.lock_tree_write()
212
288
new_trans_id = transform.new_directory('', ROOT_PARENT, 'alt-root-id')
213
289
self.assertRaises(ValueError, transform.fixup_new_roots)
291
def test_retain_existing_root(self):
292
tt, root = self.get_transform()
294
tt.new_directory('', ROOT_PARENT, 'new-root-id')
296
self.assertNotEqual('new-root-id', tt.final_file_id(tt.root))
298
def test_retain_existing_root_added_file(self):
299
tt, root = self.get_transform()
300
new_trans_id = tt.new_directory('', ROOT_PARENT, 'new-root-id')
301
child = tt.new_directory('child', new_trans_id, 'child-id')
303
self.assertEqual(tt.root, tt.final_parent(child))
305
def test_add_unversioned_root(self):
306
transform, root = self.get_transform()
307
new_trans_id = transform.new_directory('', ROOT_PARENT, None)
308
transform.delete_contents(transform.root)
309
transform.fixup_new_roots()
310
self.assertNotIn(transform.root, transform._new_id)
312
def test_remove_root_fixup(self):
313
transform, root = self.get_transform()
314
old_root_id = self.wt.get_root_id()
315
self.assertNotEqual('new-root-id', old_root_id)
316
transform.delete_contents(root)
317
transform.unversion_file(root)
318
transform.fixup_new_roots()
320
self.assertEqual(old_root_id, self.wt.get_root_id())
322
transform, root = self.get_transform()
323
new_trans_id = transform.new_directory('', ROOT_PARENT, 'new-root-id')
324
new_trans_id = transform.new_directory('', ROOT_PARENT, 'alt-root-id')
325
self.assertRaises(ValueError, transform.fixup_new_roots)
327
def test_fixup_new_roots_permits_empty_tree(self):
328
transform, root = self.get_transform()
329
transform.delete_contents(root)
330
transform.unversion_file(root)
331
transform.fixup_new_roots()
332
self.assertIs(None, transform.final_kind(root))
333
self.assertIs(None, transform.final_file_id(root))
335
def test_apply_retains_root_directory(self):
336
# Do not attempt to delete the physical root directory, because that
338
transform, root = self.get_transform()
340
transform.delete_contents(root)
341
e = self.assertRaises(AssertionError, self.assertRaises,
342
errors.TransformRenameFailed,
344
self.assertContainsRe('TransformRenameFailed not raised', str(e))
346
def test_apply_retains_file_id(self):
347
transform, root = self.get_transform()
348
old_root_id = transform.tree_file_id(root)
349
transform.unversion_file(root)
351
self.assertEqual(old_root_id, self.wt.get_root_id())
215
353
def test_hardlink(self):
216
354
self.requireFeature(HardlinkFeature)
217
355
transform, root = self.get_transform()
1505
1661
return template % ('<' * 7, tree, '=' * 7, merge, '>' * 7)
1664
class TestInventoryAltered(tests.TestCaseWithTransport):
1666
def test_inventory_altered_unchanged(self):
1667
tree = self.make_branch_and_tree('tree')
1668
self.build_tree(['tree/foo'])
1669
tree.add('foo', 'foo-id')
1670
with TransformPreview(tree) as tt:
1671
self.assertEqual([], tt._inventory_altered())
1673
def test_inventory_altered_changed_parent_id(self):
1674
tree = self.make_branch_and_tree('tree')
1675
self.build_tree(['tree/foo'])
1676
tree.add('foo', 'foo-id')
1677
with TransformPreview(tree) as tt:
1678
tt.unversion_file(tt.root)
1679
tt.version_file('new-id', tt.root)
1680
foo_trans_id = tt.trans_id_tree_file_id('foo-id')
1681
foo_tuple = ('foo', foo_trans_id)
1682
root_tuple = ('', tt.root)
1683
self.assertEqual([root_tuple, foo_tuple], tt._inventory_altered())
1685
def test_inventory_altered_noop_changed_parent_id(self):
1686
tree = self.make_branch_and_tree('tree')
1687
self.build_tree(['tree/foo'])
1688
tree.add('foo', 'foo-id')
1689
with TransformPreview(tree) as tt:
1690
tt.unversion_file(tt.root)
1691
tt.version_file(tree.get_root_id(), tt.root)
1692
foo_trans_id = tt.trans_id_tree_file_id('foo-id')
1693
self.assertEqual([], tt._inventory_altered())
1508
1696
class TestTransformMerge(TestCaseInTempDir):
1510
1698
def test_text_merge(self):
2039
2239
self.assertEqual('file.moved', target.id2path('lower-id'))
2040
2240
self.assertEqual('FILE', target.id2path('upper-id'))
2242
def test_build_tree_observes_sha(self):
2243
source = self.make_branch_and_tree('source')
2244
self.build_tree(['source/file1', 'source/dir/', 'source/dir/file2'])
2245
source.add(['file1', 'dir', 'dir/file2'],
2246
['file1-id', 'dir-id', 'file2-id'])
2247
source.commit('new files')
2248
target = self.make_branch_and_tree('target')
2250
self.addCleanup(target.unlock)
2251
# We make use of the fact that DirState caches its cutoff time. So we
2252
# set the 'safe' time to one minute in the future.
2253
state = target.current_dirstate()
2254
state._cutoff_time = time.time() + 60
2255
build_tree(source.basis_tree(), target)
2256
entry1_sha = osutils.sha_file_by_name('source/file1')
2257
entry2_sha = osutils.sha_file_by_name('source/dir/file2')
2258
# entry[1] is the state information, entry[1][0] is the state of the
2259
# working tree, entry[1][0][1] is the sha value for the current working
2261
entry1 = state._get_entry(0, path_utf8='file1')
2262
self.assertEqual(entry1_sha, entry1[1][0][1])
2263
# The 'size' field must also be set.
2264
self.assertEqual(25, entry1[1][0][2])
2265
entry1_state = entry1[1][0]
2266
entry2 = state._get_entry(0, path_utf8='dir/file2')
2267
self.assertEqual(entry2_sha, entry2[1][0][1])
2268
self.assertEqual(29, entry2[1][0][2])
2269
entry2_state = entry2[1][0]
2270
# Now, make sure that we don't have to re-read the content. The
2271
# packed_stat should match exactly.
2272
self.assertEqual(entry1_sha, target.get_file_sha1('file1-id', 'file1'))
2273
self.assertEqual(entry2_sha,
2274
target.get_file_sha1('file2-id', 'dir/file2'))
2275
self.assertEqual(entry1_state, entry1[1][0])
2276
self.assertEqual(entry2_state, entry2[1][0])
2043
2279
class TestCommitTransform(tests.TestCaseWithTransport):
2178
2414
self.assertEqual('tree', revision.properties['branch-nick'])
2181
class MockTransform(object):
2183
def has_named_child(self, by_parent, parent_id, name):
2184
for child_id in by_parent[parent_id]:
2188
elif name == "name.~%s~" % child_id:
2193
class MockEntry(object):
2195
object.__init__(self)
2199
class TestGetBackupName(TestCase):
2200
def test_get_backup_name(self):
2417
class TestBackupName(tests.TestCase):
2419
def test_deprecations(self):
2420
class MockTransform(object):
2422
def has_named_child(self, by_parent, parent_id, name):
2423
return name in by_parent.get(parent_id, [])
2425
class MockEntry(object):
2428
object.__init__(self)
2201
2431
tt = MockTransform()
2202
name = get_backup_name(MockEntry(), {'a':[]}, 'a', tt)
2203
self.assertEqual(name, 'name.~1~')
2204
name = get_backup_name(MockEntry(), {'a':['1']}, 'a', tt)
2205
self.assertEqual(name, 'name.~2~')
2206
name = get_backup_name(MockEntry(), {'a':['2']}, 'a', tt)
2207
self.assertEqual(name, 'name.~1~')
2208
name = get_backup_name(MockEntry(), {'a':['2'], 'b':[]}, 'b', tt)
2209
self.assertEqual(name, 'name.~1~')
2210
name = get_backup_name(MockEntry(), {'a':['1', '2', '3']}, 'a', tt)
2211
self.assertEqual(name, 'name.~4~')
2432
name1 = self.applyDeprecated(
2433
symbol_versioning.deprecated_in((2, 3, 0)),
2434
transform.get_backup_name, MockEntry(), {'a':[]}, 'a', tt)
2435
self.assertEqual('name.~1~', name1)
2436
name2 = self.applyDeprecated(
2437
symbol_versioning.deprecated_in((2, 3, 0)),
2438
transform._get_backup_name, 'name', {'a':['name.~1~']}, 'a', tt)
2439
self.assertEqual('name.~2~', name2)
2214
2442
class TestFileMover(tests.TestCaseWithTransport):
2217
2445
self.build_tree(['a/', 'a/b', 'c/', 'c/d'])
2218
2446
mover = _FileMover()
2219
2447
mover.rename('a', 'q')
2220
self.failUnlessExists('q')
2221
self.failIfExists('a')
2222
self.failUnlessExists('q/b')
2223
self.failUnlessExists('c')
2224
self.failUnlessExists('c/d')
2448
self.assertPathExists('q')
2449
self.assertPathDoesNotExist('a')
2450
self.assertPathExists('q/b')
2451
self.assertPathExists('c')
2452
self.assertPathExists('c/d')
2226
2454
def test_pre_delete_rollback(self):
2227
2455
self.build_tree(['a/'])
2228
2456
mover = _FileMover()
2229
2457
mover.pre_delete('a', 'q')
2230
self.failUnlessExists('q')
2231
self.failIfExists('a')
2458
self.assertPathExists('q')
2459
self.assertPathDoesNotExist('a')
2232
2460
mover.rollback()
2233
self.failIfExists('q')
2234
self.failUnlessExists('a')
2461
self.assertPathDoesNotExist('q')
2462
self.assertPathExists('a')
2236
2464
def test_apply_deletions(self):
2237
2465
self.build_tree(['a/', 'b/'])
2238
2466
mover = _FileMover()
2239
2467
mover.pre_delete('a', 'q')
2240
2468
mover.pre_delete('b', 'r')
2241
self.failUnlessExists('q')
2242
self.failUnlessExists('r')
2243
self.failIfExists('a')
2244
self.failIfExists('b')
2469
self.assertPathExists('q')
2470
self.assertPathExists('r')
2471
self.assertPathDoesNotExist('a')
2472
self.assertPathDoesNotExist('b')
2245
2473
mover.apply_deletions()
2246
self.failIfExists('q')
2247
self.failIfExists('r')
2248
self.failIfExists('a')
2249
self.failIfExists('b')
2474
self.assertPathDoesNotExist('q')
2475
self.assertPathDoesNotExist('r')
2476
self.assertPathDoesNotExist('a')
2477
self.assertPathDoesNotExist('b')
2251
2479
def test_file_mover_rollback(self):
2252
2480
self.build_tree(['a/', 'a/b', 'c/', 'c/d/', 'c/e/'])
2326
2554
tt.adjust_path('d', tt.root, tt.trans_id_tree_path('a/b'))
2327
2555
self.assertRaises(Bogus, tt.apply,
2328
2556
_mover=self.ExceptionFileMover(bad_target='d'))
2329
self.failUnlessExists('a')
2330
self.failUnlessExists('a/b')
2332
def test_resolve_no_parent(self):
2557
self.assertPathExists('a')
2558
self.assertPathExists('a/b')
2561
class TestFinalizeRobustness(tests.TestCaseWithTransport):
2562
"""Ensure treetransform creation errors can be safely cleaned up after"""
2564
def _override_globals_in_method(self, instance, method_name, globals):
2565
"""Replace method on instance with one with updated globals"""
2567
func = getattr(instance, method_name).im_func
2568
new_globals = dict(func.func_globals)
2569
new_globals.update(globals)
2570
new_func = types.FunctionType(func.func_code, new_globals,
2571
func.func_name, func.func_defaults)
2572
setattr(instance, method_name,
2573
types.MethodType(new_func, instance, instance.__class__))
2574
self.addCleanup(delattr, instance, method_name)
2577
def _fake_open_raises_before(name, mode):
2578
"""Like open() but raises before doing anything"""
2582
def _fake_open_raises_after(name, mode):
2583
"""Like open() but raises after creating file without returning"""
2584
open(name, mode).close()
2587
def create_transform_and_root_trans_id(self):
2588
"""Setup a transform creating a file in limbo"""
2589
tree = self.make_branch_and_tree('.')
2590
tt = TreeTransform(tree)
2591
return tt, tt.create_path("a", tt.root)
2593
def create_transform_and_subdir_trans_id(self):
2594
"""Setup a transform creating a directory containing a file in limbo"""
2595
tree = self.make_branch_and_tree('.')
2596
tt = TreeTransform(tree)
2597
d_trans_id = tt.create_path("d", tt.root)
2598
tt.create_directory(d_trans_id)
2599
f_trans_id = tt.create_path("a", d_trans_id)
2600
tt.adjust_path("a", d_trans_id, f_trans_id)
2601
return tt, f_trans_id
2603
def test_root_create_file_open_raises_before_creation(self):
2604
tt, trans_id = self.create_transform_and_root_trans_id()
2605
self._override_globals_in_method(tt, "create_file",
2606
{"open": self._fake_open_raises_before})
2607
self.assertRaises(RuntimeError, tt.create_file, ["contents"], trans_id)
2608
path = tt._limbo_name(trans_id)
2609
self.assertPathDoesNotExist(path)
2611
self.assertPathDoesNotExist(tt._limbodir)
2613
def test_root_create_file_open_raises_after_creation(self):
2614
tt, trans_id = self.create_transform_and_root_trans_id()
2615
self._override_globals_in_method(tt, "create_file",
2616
{"open": self._fake_open_raises_after})
2617
self.assertRaises(RuntimeError, tt.create_file, ["contents"], trans_id)
2618
path = tt._limbo_name(trans_id)
2619
self.assertPathExists(path)
2621
self.assertPathDoesNotExist(path)
2622
self.assertPathDoesNotExist(tt._limbodir)
2624
def test_subdir_create_file_open_raises_before_creation(self):
2625
tt, trans_id = self.create_transform_and_subdir_trans_id()
2626
self._override_globals_in_method(tt, "create_file",
2627
{"open": self._fake_open_raises_before})
2628
self.assertRaises(RuntimeError, tt.create_file, ["contents"], trans_id)
2629
path = tt._limbo_name(trans_id)
2630
self.assertPathDoesNotExist(path)
2632
self.assertPathDoesNotExist(tt._limbodir)
2634
def test_subdir_create_file_open_raises_after_creation(self):
2635
tt, trans_id = self.create_transform_and_subdir_trans_id()
2636
self._override_globals_in_method(tt, "create_file",
2637
{"open": self._fake_open_raises_after})
2638
self.assertRaises(RuntimeError, tt.create_file, ["contents"], trans_id)
2639
path = tt._limbo_name(trans_id)
2640
self.assertPathExists(path)
2642
self.assertPathDoesNotExist(path)
2643
self.assertPathDoesNotExist(tt._limbodir)
2645
def test_rename_in_limbo_rename_raises_after_rename(self):
2646
tt, trans_id = self.create_transform_and_root_trans_id()
2647
parent1 = tt.new_directory('parent1', tt.root)
2648
child1 = tt.new_file('child1', parent1, 'contents')
2649
parent2 = tt.new_directory('parent2', tt.root)
2651
class FakeOSModule(object):
2652
def rename(self, old, new):
2655
self._override_globals_in_method(tt, "_rename_in_limbo",
2656
{"os": FakeOSModule()})
2658
RuntimeError, tt.adjust_path, "child1", parent2, child1)
2659
path = osutils.pathjoin(tt._limbo_name(parent2), "child1")
2660
self.assertPathExists(path)
2662
self.assertPathDoesNotExist(path)
2663
self.assertPathDoesNotExist(tt._limbodir)
2665
def test_rename_in_limbo_rename_raises_before_rename(self):
2666
tt, trans_id = self.create_transform_and_root_trans_id()
2667
parent1 = tt.new_directory('parent1', tt.root)
2668
child1 = tt.new_file('child1', parent1, 'contents')
2669
parent2 = tt.new_directory('parent2', tt.root)
2671
class FakeOSModule(object):
2672
def rename(self, old, new):
2674
self._override_globals_in_method(tt, "_rename_in_limbo",
2675
{"os": FakeOSModule()})
2677
RuntimeError, tt.adjust_path, "child1", parent2, child1)
2678
path = osutils.pathjoin(tt._limbo_name(parent1), "child1")
2679
self.assertPathExists(path)
2681
self.assertPathDoesNotExist(path)
2682
self.assertPathDoesNotExist(tt._limbodir)
2685
class TestTransformMissingParent(tests.TestCaseWithTransport):
2687
def make_tt_with_versioned_dir(self):
2333
2688
wt = self.make_branch_and_tree('.')
2689
self.build_tree(['dir/',])
2690
wt.add(['dir'], ['dir-id'])
2691
wt.commit('Create dir')
2334
2692
tt = TreeTransform(wt)
2335
2693
self.addCleanup(tt.finalize)
2336
parent = tt.trans_id_file_id('parent-id')
2337
tt.new_file('file', parent, 'Contents')
2338
resolve_conflicts(tt)
2696
def test_resolve_create_parent_for_versioned_file(self):
2697
wt, tt = self.make_tt_with_versioned_dir()
2698
dir_tid = tt.trans_id_tree_file_id('dir-id')
2699
file_tid = tt.new_file('file', dir_tid, 'Contents', file_id='file-id')
2700
tt.delete_contents(dir_tid)
2701
tt.unversion_file(dir_tid)
2702
conflicts = resolve_conflicts(tt)
2703
# one conflict for the missing directory, one for the unversioned
2705
self.assertLength(2, conflicts)
2707
def test_non_versioned_file_create_conflict(self):
2708
wt, tt = self.make_tt_with_versioned_dir()
2709
dir_tid = tt.trans_id_tree_file_id('dir-id')
2710
tt.new_file('file', dir_tid, 'Contents')
2711
tt.delete_contents(dir_tid)
2712
tt.unversion_file(dir_tid)
2713
conflicts = resolve_conflicts(tt)
2714
# no conflicts or rather: orphaning 'file' resolve the 'dir' conflict
2715
self.assertLength(1, conflicts)
2716
self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
2341
2720
A_ENTRY = ('a-id', ('a', 'a'), True, (True, True),
2342
2721
('TREE_ROOT', 'TREE_ROOT'), ('a', 'a'), ('file', 'file'),
2343
2722
(False, False))
2344
2723
ROOT_ENTRY = ('TREE_ROOT', ('', ''), False, (True, True), (None, None),
2345
('', ''), ('directory', 'directory'), (False, None))
2724
('', ''), ('directory', 'directory'), (False, False))
2348
2727
class TestTransformPreview(tests.TestCaseWithTransport):
3218
3627
trans_id = tt.trans_id_tree_path('file')
3219
3628
self.assertEqual((LINES_ONE,),
3220
3629
tt._get_parents_texts(trans_id))
3632
class TestOrphan(tests.TestCaseWithTransport):
3634
def test_no_orphan_for_transform_preview(self):
3635
tree = self.make_branch_and_tree('tree')
3636
tt = transform.TransformPreview(tree)
3637
self.addCleanup(tt.finalize)
3638
self.assertRaises(NotImplementedError, tt.new_orphan, 'foo', 'bar')
3640
def _set_orphan_policy(self, wt, policy):
3641
wt.branch.get_config().set_user_option('bzr.transform.orphan_policy',
3644
def _prepare_orphan(self, wt):
3645
self.build_tree(['dir/', 'dir/file', 'dir/foo'])
3646
wt.add(['dir', 'dir/file'], ['dir-id', 'file-id'])
3647
wt.commit('add dir and file ignoring foo')
3648
tt = transform.TreeTransform(wt)
3649
self.addCleanup(tt.finalize)
3650
# dir and bar are deleted
3651
dir_tid = tt.trans_id_tree_path('dir')
3652
file_tid = tt.trans_id_tree_path('dir/file')
3653
orphan_tid = tt.trans_id_tree_path('dir/foo')
3654
tt.delete_contents(file_tid)
3655
tt.unversion_file(file_tid)
3656
tt.delete_contents(dir_tid)
3657
tt.unversion_file(dir_tid)
3658
# There should be a conflict because dir still contain foo
3659
raw_conflicts = tt.find_conflicts()
3660
self.assertLength(1, raw_conflicts)
3661
self.assertEqual(('missing parent', 'new-1'), raw_conflicts[0])
3662
return tt, orphan_tid
3664
def test_new_orphan_created(self):
3665
wt = self.make_branch_and_tree('.')
3666
self._set_orphan_policy(wt, 'move')
3667
tt, orphan_tid = self._prepare_orphan(wt)
3670
warnings.append(args[0] % args[1:])
3671
self.overrideAttr(trace, 'warning', warning)
3672
remaining_conflicts = resolve_conflicts(tt)
3673
self.assertEquals(['dir/foo has been orphaned in bzr-orphans'],
3675
# Yeah for resolved conflicts !
3676
self.assertLength(0, remaining_conflicts)
3677
# We have a new orphan
3678
self.assertEquals('foo.~1~', tt.final_name(orphan_tid))
3679
self.assertEquals('bzr-orphans',
3680
tt.final_name(tt.final_parent(orphan_tid)))
3682
def test_never_orphan(self):
3683
wt = self.make_branch_and_tree('.')
3684
self._set_orphan_policy(wt, 'conflict')
3685
tt, orphan_tid = self._prepare_orphan(wt)
3686
remaining_conflicts = resolve_conflicts(tt)
3687
self.assertLength(1, remaining_conflicts)
3688
self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
3689
remaining_conflicts.pop())
3691
def test_orphan_error(self):
3692
def bogus_orphan(tt, orphan_id, parent_id):
3693
raise transform.OrphaningError(tt.final_name(orphan_id),
3694
tt.final_name(parent_id))
3695
transform.orphaning_registry.register('bogus', bogus_orphan,
3696
'Raise an error when orphaning')
3697
wt = self.make_branch_and_tree('.')
3698
self._set_orphan_policy(wt, 'bogus')
3699
tt, orphan_tid = self._prepare_orphan(wt)
3700
remaining_conflicts = resolve_conflicts(tt)
3701
self.assertLength(1, remaining_conflicts)
3702
self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
3703
remaining_conflicts.pop())
3705
def test_unknown_orphan_policy(self):
3706
wt = self.make_branch_and_tree('.')
3707
# Set a fictional policy nobody ever implemented
3708
self._set_orphan_policy(wt, 'donttouchmypreciouuus')
3709
tt, orphan_tid = self._prepare_orphan(wt)
3712
warnings.append(args[0] % args[1:])
3713
self.overrideAttr(trace, 'warning', warning)
3714
remaining_conflicts = resolve_conflicts(tt)
3715
# We fallback to the default policy which create a conflict
3716
self.assertLength(1, remaining_conflicts)
3717
self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
3718
remaining_conflicts.pop())
3719
self.assertLength(1, warnings)
3720
self.assertStartsWith(warnings[0], 'donttouchmypreciouuus')
3723
class TestTransformHooks(tests.TestCaseWithTransport):
3726
super(TestTransformHooks, self).setUp()
3727
self.wt = self.make_branch_and_tree('.')
3730
def get_transform(self):
3731
transform = TreeTransform(self.wt)
3732
self.addCleanup(transform.finalize)
3733
return transform, transform.root
3735
def test_pre_commit_hooks(self):
3737
def record_pre_transform(tree, tt):
3738
calls.append((tree, tt))
3739
MutableTree.hooks.install_named_hook('pre_transform',
3740
record_pre_transform, "Pre transform")
3741
transform, root = self.get_transform()
3742
old_root_id = transform.tree_file_id(root)
3744
self.assertEqual(old_root_id, self.wt.get_root_id())
3745
self.assertEquals([(self.wt, transform)], calls)
3747
def test_post_commit_hooks(self):
3749
def record_post_transform(tree, tt):
3750
calls.append((tree, tt))
3751
MutableTree.hooks.install_named_hook('post_transform',
3752
record_post_transform, "Post transform")
3753
transform, root = self.get_transform()
3754
old_root_id = transform.tree_file_id(root)
3756
self.assertEqual(old_root_id, self.wt.get_root_id())
3757
self.assertEquals([(self.wt, transform)], calls)