127
123
imaginary_id = transform.trans_id_tree_path('imaginary')
128
124
imaginary_id2 = transform.trans_id_tree_path('imaginary/')
129
125
self.assertEqual(imaginary_id, imaginary_id2)
130
self.assertEqual(root, transform.get_tree_parent(imaginary_id))
131
self.assertEqual('directory', transform.final_kind(root))
132
self.assertEqual(self.wt.get_root_id(), transform.final_file_id(root))
126
self.assertEqual(transform.get_tree_parent(imaginary_id), root)
127
self.assertEqual(transform.final_kind(root), 'directory')
128
self.assertEqual(transform.final_file_id(root), self.wt.get_root_id())
133
129
trans_id = transform.create_path('name', root)
134
130
self.assertIs(transform.final_file_id(trans_id), None)
135
self.assertIs(None, transform.final_kind(trans_id))
131
self.assertRaises(NoSuchFile, transform.final_kind, trans_id)
136
132
transform.create_file('contents', trans_id)
137
133
transform.set_executability(True, trans_id)
138
134
transform.version_file('my_pretties', trans_id)
818
814
self.assertIs(None, self.wt.path2id('parent'))
819
815
self.assertIs(None, self.wt.path2id('parent.new'))
821
def test_resolve_conflicts_missing_parent(self):
822
wt = self.make_branch_and_tree('.')
823
tt = TreeTransform(wt)
824
self.addCleanup(tt.finalize)
825
parent = tt.trans_id_file_id('parent-id')
826
tt.new_file('file', parent, 'Contents')
827
raw_conflicts = resolve_conflicts(tt)
828
# Since the directory doesn't exist it's seen as 'missing'. So
829
# 'resolve_conflicts' create a conflict asking for it to be created.
830
self.assertLength(1, raw_conflicts)
831
self.assertEqual(('missing parent', 'Created directory', 'new-1'),
833
# apply fail since the missing directory doesn't exist
834
self.assertRaises(errors.NoFinalPath, tt.apply)
836
817
def test_moving_versioned_directories(self):
837
818
create, root = self.get_transform()
838
819
kansas = create.new_directory('kansas', root, 'kansas-id')
2198
2178
self.assertEqual('tree', revision.properties['branch-nick'])
2201
class TestBackupName(tests.TestCase):
2203
def test_deprecations(self):
2204
class MockTransform(object):
2206
def has_named_child(self, by_parent, parent_id, name):
2207
return name in by_parent.get(parent_id, [])
2209
class MockEntry(object):
2212
object.__init__(self)
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):
2215
2201
tt = MockTransform()
2216
name1 = self.applyDeprecated(
2217
symbol_versioning.deprecated_in((2, 3, 0)),
2218
transform.get_backup_name, MockEntry(), {'a':[]}, 'a', tt)
2219
self.assertEqual('name.~1~', name1)
2220
name2 = self.applyDeprecated(
2221
symbol_versioning.deprecated_in((2, 3, 0)),
2222
transform._get_backup_name, 'name', {'a':['name.~1~']}, 'a', tt)
2223
self.assertEqual('name.~2~', name2)
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~')
2226
2214
class TestFileMover(tests.TestCaseWithTransport):
2341
2329
self.failUnlessExists('a')
2342
2330
self.failUnlessExists('a/b')
2345
class TestTransformMissingParent(tests.TestCaseWithTransport):
2347
def make_tt_with_versioned_dir(self):
2332
def test_resolve_no_parent(self):
2348
2333
wt = self.make_branch_and_tree('.')
2349
self.build_tree(['dir/',])
2350
wt.add(['dir'], ['dir-id'])
2351
wt.commit('Create dir')
2352
2334
tt = TreeTransform(wt)
2353
2335
self.addCleanup(tt.finalize)
2356
def test_resolve_create_parent_for_versioned_file(self):
2357
wt, tt = self.make_tt_with_versioned_dir()
2358
dir_tid = tt.trans_id_tree_file_id('dir-id')
2359
file_tid = tt.new_file('file', dir_tid, 'Contents', file_id='file-id')
2360
tt.delete_contents(dir_tid)
2361
tt.unversion_file(dir_tid)
2362
conflicts = resolve_conflicts(tt)
2363
# one conflict for the missing directory, one for the unversioned
2365
self.assertLength(2, conflicts)
2367
def test_non_versioned_file_create_conflict(self):
2368
wt, tt = self.make_tt_with_versioned_dir()
2369
dir_tid = tt.trans_id_tree_file_id('dir-id')
2370
tt.new_file('file', dir_tid, 'Contents')
2371
tt.delete_contents(dir_tid)
2372
tt.unversion_file(dir_tid)
2373
conflicts = resolve_conflicts(tt)
2374
# no conflicts or rather: orphaning 'file' resolve the 'dir' conflict
2375
self.assertLength(1, conflicts)
2376
self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
2336
parent = tt.trans_id_file_id('parent-id')
2337
tt.new_file('file', parent, 'Contents')
2338
resolve_conflicts(tt)
2380
2341
A_ENTRY = ('a-id', ('a', 'a'), True, (True, True),
2381
2342
('TREE_ROOT', 'TREE_ROOT'), ('a', 'a'), ('file', 'file'),
2382
2343
(False, False))
2383
2344
ROOT_ENTRY = ('TREE_ROOT', ('', ''), False, (True, True), (None, None),
2384
('', ''), ('directory', 'directory'), (False, False))
2345
('', ''), ('directory', 'directory'), (False, None))
2387
2348
class TestTransformPreview(tests.TestCaseWithTransport):
3257
3218
trans_id = tt.trans_id_tree_path('file')
3258
3219
self.assertEqual((LINES_ONE,),
3259
3220
tt._get_parents_texts(trans_id))
3262
class TestOrphan(tests.TestCaseWithTransport):
3264
def test_no_orphan_for_transform_preview(self):
3265
tree = self.make_branch_and_tree('tree')
3266
tt = transform.TransformPreview(tree)
3267
self.addCleanup(tt.finalize)
3268
self.assertRaises(NotImplementedError, tt.new_orphan, 'foo', 'bar')
3270
def _set_orphan_policy(self, wt, policy):
3271
wt.branch.get_config().set_user_option('bzr.transform.orphan_policy',
3274
def _prepare_orphan(self, wt):
3275
self.build_tree(['dir/', 'dir/file', 'dir/foo'])
3276
wt.add(['dir', 'dir/file'], ['dir-id', 'file-id'])
3277
wt.commit('add dir and file ignoring foo')
3278
tt = transform.TreeTransform(wt)
3279
self.addCleanup(tt.finalize)
3280
# dir and bar are deleted
3281
dir_tid = tt.trans_id_tree_path('dir')
3282
file_tid = tt.trans_id_tree_path('dir/file')
3283
orphan_tid = tt.trans_id_tree_path('dir/foo')
3284
tt.delete_contents(file_tid)
3285
tt.unversion_file(file_tid)
3286
tt.delete_contents(dir_tid)
3287
tt.unversion_file(dir_tid)
3288
# There should be a conflict because dir still contain foo
3289
raw_conflicts = tt.find_conflicts()
3290
self.assertLength(1, raw_conflicts)
3291
self.assertEqual(('missing parent', 'new-1'), raw_conflicts[0])
3292
return tt, orphan_tid
3294
def test_new_orphan_created(self):
3295
wt = self.make_branch_and_tree('.')
3296
self._set_orphan_policy(wt, 'move')
3297
tt, orphan_tid = self._prepare_orphan(wt)
3300
warnings.append(args[0] % args[1:])
3301
self.overrideAttr(trace, 'warning', warning)
3302
remaining_conflicts = resolve_conflicts(tt)
3303
self.assertEquals(['dir/foo has been orphaned in bzr-orphans'],
3305
# Yeah for resolved conflicts !
3306
self.assertLength(0, remaining_conflicts)
3307
# We have a new orphan
3308
self.assertEquals('foo.~1~', tt.final_name(orphan_tid))
3309
self.assertEquals('bzr-orphans',
3310
tt.final_name(tt.final_parent(orphan_tid)))
3312
def test_never_orphan(self):
3313
wt = self.make_branch_and_tree('.')
3314
self._set_orphan_policy(wt, 'conflict')
3315
tt, orphan_tid = self._prepare_orphan(wt)
3316
remaining_conflicts = resolve_conflicts(tt)
3317
self.assertLength(1, remaining_conflicts)
3318
self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
3319
remaining_conflicts.pop())
3321
def test_orphan_error(self):
3322
def bogus_orphan(tt, orphan_id, parent_id):
3323
raise transform.OrphaningError(tt.final_name(orphan_id),
3324
tt.final_name(parent_id))
3325
transform.orphaning_registry.register('bogus', bogus_orphan,
3326
'Raise an error when orphaning')
3327
wt = self.make_branch_and_tree('.')
3328
self._set_orphan_policy(wt, 'bogus')
3329
tt, orphan_tid = self._prepare_orphan(wt)
3330
remaining_conflicts = resolve_conflicts(tt)
3331
self.assertLength(1, remaining_conflicts)
3332
self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
3333
remaining_conflicts.pop())
3335
def test_unknown_orphan_policy(self):
3336
wt = self.make_branch_and_tree('.')
3337
# Set a fictional policy nobody ever implemented
3338
self._set_orphan_policy(wt, 'donttouchmypreciouuus')
3339
tt, orphan_tid = self._prepare_orphan(wt)
3342
warnings.append(args[0] % args[1:])
3343
self.overrideAttr(trace, 'warning', warning)
3344
remaining_conflicts = resolve_conflicts(tt)
3345
# We fallback to the default policy which create a conflict
3346
self.assertLength(1, remaining_conflicts)
3347
self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
3348
remaining_conflicts.pop())
3349
self.assertLength(1, warnings)
3350
self.assertStartsWith(warnings[0], 'donttouchmypreciouuus')