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
1657
return template % ('<' * 7, tree, '=' * 7, merge, '>' * 7)
1660
class TestInventoryAltered(tests.TestCaseWithTransport):
1662
def test_inventory_altered_unchanged(self):
1663
tree = self.make_branch_and_tree('tree')
1664
self.build_tree(['tree/foo'])
1665
tree.add('foo', 'foo-id')
1666
with TransformPreview(tree) as tt:
1667
self.assertEqual([], tt._inventory_altered())
1669
def test_inventory_altered_changed_parent_id(self):
1670
tree = self.make_branch_and_tree('tree')
1671
self.build_tree(['tree/foo'])
1672
tree.add('foo', 'foo-id')
1673
with TransformPreview(tree) as tt:
1674
tt.unversion_file(tt.root)
1675
tt.version_file('new-id', tt.root)
1676
foo_trans_id = tt.trans_id_tree_file_id('foo-id')
1677
foo_tuple = ('foo', foo_trans_id)
1678
root_tuple = ('', tt.root)
1679
self.assertEqual([root_tuple, foo_tuple], tt._inventory_altered())
1681
def test_inventory_altered_noop_changed_parent_id(self):
1682
tree = self.make_branch_and_tree('tree')
1683
self.build_tree(['tree/foo'])
1684
tree.add('foo', 'foo-id')
1685
with TransformPreview(tree) as tt:
1686
tt.unversion_file(tt.root)
1687
tt.version_file(tree.get_root_id(), tt.root)
1688
foo_trans_id = tt.trans_id_tree_file_id('foo-id')
1689
self.assertEqual([], tt._inventory_altered())
1508
1692
class TestTransformMerge(TestCaseInTempDir):
1510
1694
def test_text_merge(self):
2039
2236
self.assertEqual('file.moved', target.id2path('lower-id'))
2040
2237
self.assertEqual('FILE', target.id2path('upper-id'))
2239
def test_build_tree_observes_sha(self):
2240
source = self.make_branch_and_tree('source')
2241
self.build_tree(['source/file1', 'source/dir/', 'source/dir/file2'])
2242
source.add(['file1', 'dir', 'dir/file2'],
2243
['file1-id', 'dir-id', 'file2-id'])
2244
source.commit('new files')
2245
target = self.make_branch_and_tree('target')
2247
self.addCleanup(target.unlock)
2248
# We make use of the fact that DirState caches its cutoff time. So we
2249
# set the 'safe' time to one minute in the future.
2250
state = target.current_dirstate()
2251
state._cutoff_time = time.time() + 60
2252
build_tree(source.basis_tree(), target)
2253
entry1_sha = osutils.sha_file_by_name('source/file1')
2254
entry2_sha = osutils.sha_file_by_name('source/dir/file2')
2255
# entry[1] is the state information, entry[1][0] is the state of the
2256
# working tree, entry[1][0][1] is the sha value for the current working
2258
entry1 = state._get_entry(0, path_utf8='file1')
2259
self.assertEqual(entry1_sha, entry1[1][0][1])
2260
# The 'size' field must also be set.
2261
self.assertEqual(25, entry1[1][0][2])
2262
entry1_state = entry1[1][0]
2263
entry2 = state._get_entry(0, path_utf8='dir/file2')
2264
self.assertEqual(entry2_sha, entry2[1][0][1])
2265
self.assertEqual(29, entry2[1][0][2])
2266
entry2_state = entry2[1][0]
2267
# Now, make sure that we don't have to re-read the content. The
2268
# packed_stat should match exactly.
2269
self.assertEqual(entry1_sha, target.get_file_sha1('file1-id', 'file1'))
2270
self.assertEqual(entry2_sha,
2271
target.get_file_sha1('file2-id', 'dir/file2'))
2272
self.assertEqual(entry1_state, entry1[1][0])
2273
self.assertEqual(entry2_state, entry2[1][0])
2043
2276
class TestCommitTransform(tests.TestCaseWithTransport):
2178
2411
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):
2201
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~')
2214
2414
class TestFileMover(tests.TestCaseWithTransport):
2216
2416
def test_file_mover(self):
2217
2417
self.build_tree(['a/', 'a/b', 'c/', 'c/d'])
2218
2418
mover = _FileMover()
2219
2419
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')
2420
self.assertPathExists('q')
2421
self.assertPathDoesNotExist('a')
2422
self.assertPathExists('q/b')
2423
self.assertPathExists('c')
2424
self.assertPathExists('c/d')
2226
2426
def test_pre_delete_rollback(self):
2227
2427
self.build_tree(['a/'])
2228
2428
mover = _FileMover()
2229
2429
mover.pre_delete('a', 'q')
2230
self.failUnlessExists('q')
2231
self.failIfExists('a')
2430
self.assertPathExists('q')
2431
self.assertPathDoesNotExist('a')
2232
2432
mover.rollback()
2233
self.failIfExists('q')
2234
self.failUnlessExists('a')
2433
self.assertPathDoesNotExist('q')
2434
self.assertPathExists('a')
2236
2436
def test_apply_deletions(self):
2237
2437
self.build_tree(['a/', 'b/'])
2238
2438
mover = _FileMover()
2239
2439
mover.pre_delete('a', 'q')
2240
2440
mover.pre_delete('b', 'r')
2241
self.failUnlessExists('q')
2242
self.failUnlessExists('r')
2243
self.failIfExists('a')
2244
self.failIfExists('b')
2441
self.assertPathExists('q')
2442
self.assertPathExists('r')
2443
self.assertPathDoesNotExist('a')
2444
self.assertPathDoesNotExist('b')
2245
2445
mover.apply_deletions()
2246
self.failIfExists('q')
2247
self.failIfExists('r')
2248
self.failIfExists('a')
2249
self.failIfExists('b')
2446
self.assertPathDoesNotExist('q')
2447
self.assertPathDoesNotExist('r')
2448
self.assertPathDoesNotExist('a')
2449
self.assertPathDoesNotExist('b')
2251
2451
def test_file_mover_rollback(self):
2252
2452
self.build_tree(['a/', 'a/b', 'c/', 'c/d/', 'c/e/'])
2326
2526
tt.adjust_path('d', tt.root, tt.trans_id_tree_path('a/b'))
2327
2527
self.assertRaises(Bogus, tt.apply,
2328
2528
_mover=self.ExceptionFileMover(bad_target='d'))
2329
self.failUnlessExists('a')
2330
self.failUnlessExists('a/b')
2332
def test_resolve_no_parent(self):
2529
self.assertPathExists('a')
2530
self.assertPathExists('a/b')
2533
class TestFinalizeRobustness(tests.TestCaseWithTransport):
2534
"""Ensure treetransform creation errors can be safely cleaned up after"""
2536
def _override_globals_in_method(self, instance, method_name, globals):
2537
"""Replace method on instance with one with updated globals"""
2539
func = getattr(instance, method_name).im_func
2540
new_globals = dict(func.func_globals)
2541
new_globals.update(globals)
2542
new_func = types.FunctionType(func.func_code, new_globals,
2543
func.func_name, func.func_defaults)
2544
setattr(instance, method_name,
2545
types.MethodType(new_func, instance, instance.__class__))
2546
self.addCleanup(delattr, instance, method_name)
2549
def _fake_open_raises_before(name, mode):
2550
"""Like open() but raises before doing anything"""
2554
def _fake_open_raises_after(name, mode):
2555
"""Like open() but raises after creating file without returning"""
2556
open(name, mode).close()
2559
def create_transform_and_root_trans_id(self):
2560
"""Setup a transform creating a file in limbo"""
2561
tree = self.make_branch_and_tree('.')
2562
tt = TreeTransform(tree)
2563
return tt, tt.create_path("a", tt.root)
2565
def create_transform_and_subdir_trans_id(self):
2566
"""Setup a transform creating a directory containing a file in limbo"""
2567
tree = self.make_branch_and_tree('.')
2568
tt = TreeTransform(tree)
2569
d_trans_id = tt.create_path("d", tt.root)
2570
tt.create_directory(d_trans_id)
2571
f_trans_id = tt.create_path("a", d_trans_id)
2572
tt.adjust_path("a", d_trans_id, f_trans_id)
2573
return tt, f_trans_id
2575
def test_root_create_file_open_raises_before_creation(self):
2576
tt, trans_id = self.create_transform_and_root_trans_id()
2577
self._override_globals_in_method(tt, "create_file",
2578
{"open": self._fake_open_raises_before})
2579
self.assertRaises(RuntimeError, tt.create_file, ["contents"], trans_id)
2580
path = tt._limbo_name(trans_id)
2581
self.assertPathDoesNotExist(path)
2583
self.assertPathDoesNotExist(tt._limbodir)
2585
def test_root_create_file_open_raises_after_creation(self):
2586
tt, trans_id = self.create_transform_and_root_trans_id()
2587
self._override_globals_in_method(tt, "create_file",
2588
{"open": self._fake_open_raises_after})
2589
self.assertRaises(RuntimeError, tt.create_file, ["contents"], trans_id)
2590
path = tt._limbo_name(trans_id)
2591
self.assertPathExists(path)
2593
self.assertPathDoesNotExist(path)
2594
self.assertPathDoesNotExist(tt._limbodir)
2596
def test_subdir_create_file_open_raises_before_creation(self):
2597
tt, trans_id = self.create_transform_and_subdir_trans_id()
2598
self._override_globals_in_method(tt, "create_file",
2599
{"open": self._fake_open_raises_before})
2600
self.assertRaises(RuntimeError, tt.create_file, ["contents"], trans_id)
2601
path = tt._limbo_name(trans_id)
2602
self.assertPathDoesNotExist(path)
2604
self.assertPathDoesNotExist(tt._limbodir)
2606
def test_subdir_create_file_open_raises_after_creation(self):
2607
tt, trans_id = self.create_transform_and_subdir_trans_id()
2608
self._override_globals_in_method(tt, "create_file",
2609
{"open": self._fake_open_raises_after})
2610
self.assertRaises(RuntimeError, tt.create_file, ["contents"], trans_id)
2611
path = tt._limbo_name(trans_id)
2612
self.assertPathExists(path)
2614
self.assertPathDoesNotExist(path)
2615
self.assertPathDoesNotExist(tt._limbodir)
2617
def test_rename_in_limbo_rename_raises_after_rename(self):
2618
tt, trans_id = self.create_transform_and_root_trans_id()
2619
parent1 = tt.new_directory('parent1', tt.root)
2620
child1 = tt.new_file('child1', parent1, 'contents')
2621
parent2 = tt.new_directory('parent2', tt.root)
2623
class FakeOSModule(object):
2624
def rename(self, old, new):
2627
self._override_globals_in_method(tt, "_rename_in_limbo",
2628
{"os": FakeOSModule()})
2630
RuntimeError, tt.adjust_path, "child1", parent2, child1)
2631
path = osutils.pathjoin(tt._limbo_name(parent2), "child1")
2632
self.assertPathExists(path)
2634
self.assertPathDoesNotExist(path)
2635
self.assertPathDoesNotExist(tt._limbodir)
2637
def test_rename_in_limbo_rename_raises_before_rename(self):
2638
tt, trans_id = self.create_transform_and_root_trans_id()
2639
parent1 = tt.new_directory('parent1', tt.root)
2640
child1 = tt.new_file('child1', parent1, 'contents')
2641
parent2 = tt.new_directory('parent2', tt.root)
2643
class FakeOSModule(object):
2644
def rename(self, old, new):
2646
self._override_globals_in_method(tt, "_rename_in_limbo",
2647
{"os": FakeOSModule()})
2649
RuntimeError, tt.adjust_path, "child1", parent2, child1)
2650
path = osutils.pathjoin(tt._limbo_name(parent1), "child1")
2651
self.assertPathExists(path)
2653
self.assertPathDoesNotExist(path)
2654
self.assertPathDoesNotExist(tt._limbodir)
2657
class TestTransformMissingParent(tests.TestCaseWithTransport):
2659
def make_tt_with_versioned_dir(self):
2333
2660
wt = self.make_branch_and_tree('.')
2661
self.build_tree(['dir/',])
2662
wt.add(['dir'], ['dir-id'])
2663
wt.commit('Create dir')
2334
2664
tt = TreeTransform(wt)
2335
2665
self.addCleanup(tt.finalize)
2336
parent = tt.trans_id_file_id('parent-id')
2337
tt.new_file('file', parent, 'Contents')
2338
resolve_conflicts(tt)
2668
def test_resolve_create_parent_for_versioned_file(self):
2669
wt, tt = self.make_tt_with_versioned_dir()
2670
dir_tid = tt.trans_id_tree_file_id('dir-id')
2671
file_tid = tt.new_file('file', dir_tid, 'Contents', file_id='file-id')
2672
tt.delete_contents(dir_tid)
2673
tt.unversion_file(dir_tid)
2674
conflicts = resolve_conflicts(tt)
2675
# one conflict for the missing directory, one for the unversioned
2677
self.assertLength(2, conflicts)
2679
def test_non_versioned_file_create_conflict(self):
2680
wt, tt = self.make_tt_with_versioned_dir()
2681
dir_tid = tt.trans_id_tree_file_id('dir-id')
2682
tt.new_file('file', dir_tid, 'Contents')
2683
tt.delete_contents(dir_tid)
2684
tt.unversion_file(dir_tid)
2685
conflicts = resolve_conflicts(tt)
2686
# no conflicts or rather: orphaning 'file' resolve the 'dir' conflict
2687
self.assertLength(1, conflicts)
2688
self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
2341
2692
A_ENTRY = ('a-id', ('a', 'a'), True, (True, True),
2342
2693
('TREE_ROOT', 'TREE_ROOT'), ('a', 'a'), ('file', 'file'),
2343
2694
(False, False))
2344
2695
ROOT_ENTRY = ('TREE_ROOT', ('', ''), False, (True, True), (None, None),
2345
('', ''), ('directory', 'directory'), (False, None))
2696
('', ''), ('directory', 'directory'), (False, False))
2348
2699
class TestTransformPreview(tests.TestCaseWithTransport):
3218
3599
trans_id = tt.trans_id_tree_path('file')
3219
3600
self.assertEqual((LINES_ONE,),
3220
3601
tt._get_parents_texts(trans_id))
3604
class TestOrphan(tests.TestCaseWithTransport):
3606
def test_no_orphan_for_transform_preview(self):
3607
tree = self.make_branch_and_tree('tree')
3608
tt = transform.TransformPreview(tree)
3609
self.addCleanup(tt.finalize)
3610
self.assertRaises(NotImplementedError, tt.new_orphan, 'foo', 'bar')
3612
def _set_orphan_policy(self, wt, policy):
3613
wt.branch.get_config_stack().set('bzr.transform.orphan_policy',
3616
def _prepare_orphan(self, wt):
3617
self.build_tree(['dir/', 'dir/file', 'dir/foo'])
3618
wt.add(['dir', 'dir/file'], ['dir-id', 'file-id'])
3619
wt.commit('add dir and file ignoring foo')
3620
tt = transform.TreeTransform(wt)
3621
self.addCleanup(tt.finalize)
3622
# dir and bar are deleted
3623
dir_tid = tt.trans_id_tree_path('dir')
3624
file_tid = tt.trans_id_tree_path('dir/file')
3625
orphan_tid = tt.trans_id_tree_path('dir/foo')
3626
tt.delete_contents(file_tid)
3627
tt.unversion_file(file_tid)
3628
tt.delete_contents(dir_tid)
3629
tt.unversion_file(dir_tid)
3630
# There should be a conflict because dir still contain foo
3631
raw_conflicts = tt.find_conflicts()
3632
self.assertLength(1, raw_conflicts)
3633
self.assertEqual(('missing parent', 'new-1'), raw_conflicts[0])
3634
return tt, orphan_tid
3636
def test_new_orphan_created(self):
3637
wt = self.make_branch_and_tree('.')
3638
self._set_orphan_policy(wt, 'move')
3639
tt, orphan_tid = self._prepare_orphan(wt)
3642
warnings.append(args[0] % args[1:])
3643
self.overrideAttr(trace, 'warning', warning)
3644
remaining_conflicts = resolve_conflicts(tt)
3645
self.assertEquals(['dir/foo has been orphaned in bzr-orphans'],
3647
# Yeah for resolved conflicts !
3648
self.assertLength(0, remaining_conflicts)
3649
# We have a new orphan
3650
self.assertEquals('foo.~1~', tt.final_name(orphan_tid))
3651
self.assertEquals('bzr-orphans',
3652
tt.final_name(tt.final_parent(orphan_tid)))
3654
def test_never_orphan(self):
3655
wt = self.make_branch_and_tree('.')
3656
self._set_orphan_policy(wt, 'conflict')
3657
tt, orphan_tid = self._prepare_orphan(wt)
3658
remaining_conflicts = resolve_conflicts(tt)
3659
self.assertLength(1, remaining_conflicts)
3660
self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
3661
remaining_conflicts.pop())
3663
def test_orphan_error(self):
3664
def bogus_orphan(tt, orphan_id, parent_id):
3665
raise transform.OrphaningError(tt.final_name(orphan_id),
3666
tt.final_name(parent_id))
3667
transform.orphaning_registry.register('bogus', bogus_orphan,
3668
'Raise an error when orphaning')
3669
wt = self.make_branch_and_tree('.')
3670
self._set_orphan_policy(wt, 'bogus')
3671
tt, orphan_tid = self._prepare_orphan(wt)
3672
remaining_conflicts = resolve_conflicts(tt)
3673
self.assertLength(1, remaining_conflicts)
3674
self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
3675
remaining_conflicts.pop())
3677
def test_unknown_orphan_policy(self):
3678
wt = self.make_branch_and_tree('.')
3679
# Set a fictional policy nobody ever implemented
3680
self._set_orphan_policy(wt, 'donttouchmypreciouuus')
3681
tt, orphan_tid = self._prepare_orphan(wt)
3684
warnings.append(args[0] % args[1:])
3685
self.overrideAttr(trace, 'warning', warning)
3686
remaining_conflicts = resolve_conflicts(tt)
3687
# We fallback to the default policy which create a conflict
3688
self.assertLength(1, remaining_conflicts)
3689
self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
3690
remaining_conflicts.pop())
3691
self.assertLength(1, warnings)
3692
self.assertStartsWith(warnings[0], 'Value "donttouchmypreciouuus" ')
3695
class TestTransformHooks(tests.TestCaseWithTransport):
3698
super(TestTransformHooks, self).setUp()
3699
self.wt = self.make_branch_and_tree('.')
3702
def get_transform(self):
3703
transform = TreeTransform(self.wt)
3704
self.addCleanup(transform.finalize)
3705
return transform, transform.root
3707
def test_pre_commit_hooks(self):
3709
def record_pre_transform(tree, tt):
3710
calls.append((tree, tt))
3711
MutableTree.hooks.install_named_hook('pre_transform',
3712
record_pre_transform, "Pre transform")
3713
transform, root = self.get_transform()
3714
old_root_id = transform.tree_file_id(root)
3716
self.assertEqual(old_root_id, self.wt.get_root_id())
3717
self.assertEquals([(self.wt, transform)], calls)
3719
def test_post_commit_hooks(self):
3721
def record_post_transform(tree, tt):
3722
calls.append((tree, tt))
3723
MutableTree.hooks.install_named_hook('post_transform',
3724
record_post_transform, "Post transform")
3725
transform, root = self.get_transform()
3726
old_root_id = transform.tree_file_id(root)
3728
self.assertEqual(old_root_id, self.wt.get_root_id())
3729
self.assertEquals([(self.wt, transform)], calls)