2031
2046
preview_tree = preview.get_preview_tree()
2032
2047
self.assertEqual('target',
2033
2048
preview_tree.get_symlink_target('symlink-id'))
2050
def test_all_file_ids(self):
2051
tree = self.make_branch_and_tree('tree')
2052
self.build_tree(['tree/a', 'tree/b', 'tree/c'])
2053
tree.add(['a', 'b', 'c'], ['a-id', 'b-id', 'c-id'])
2054
preview = TransformPreview(tree)
2055
self.addCleanup(preview.finalize)
2056
preview.unversion_file(preview.trans_id_file_id('b-id'))
2057
c_trans_id = preview.trans_id_file_id('c-id')
2058
preview.unversion_file(c_trans_id)
2059
preview.version_file('c-id', c_trans_id)
2060
preview_tree = preview.get_preview_tree()
2061
self.assertEqual(set(['a-id', 'c-id', tree.get_root_id()]),
2062
preview_tree.all_file_ids())
2064
def test_path2id_deleted_unchanged(self):
2065
tree = self.make_branch_and_tree('tree')
2066
self.build_tree(['tree/unchanged', 'tree/deleted'])
2067
tree.add(['unchanged', 'deleted'], ['unchanged-id', 'deleted-id'])
2068
preview = TransformPreview(tree)
2069
self.addCleanup(preview.finalize)
2070
preview.unversion_file(preview.trans_id_file_id('deleted-id'))
2071
preview_tree = preview.get_preview_tree()
2072
self.assertEqual('unchanged-id', preview_tree.path2id('unchanged'))
2073
self.assertIs(None, preview_tree.path2id('deleted'))
2075
def test_path2id_created(self):
2076
tree = self.make_branch_and_tree('tree')
2077
self.build_tree(['tree/unchanged'])
2078
tree.add(['unchanged'], ['unchanged-id'])
2079
preview = TransformPreview(tree)
2080
self.addCleanup(preview.finalize)
2081
preview.new_file('new', preview.trans_id_file_id('unchanged-id'),
2082
'contents', 'new-id')
2083
preview_tree = preview.get_preview_tree()
2084
self.assertEqual('new-id', preview_tree.path2id('unchanged/new'))
2086
def test_path2id_moved(self):
2087
tree = self.make_branch_and_tree('tree')
2088
self.build_tree(['tree/old_parent/', 'tree/old_parent/child'])
2089
tree.add(['old_parent', 'old_parent/child'],
2090
['old_parent-id', 'child-id'])
2091
preview = TransformPreview(tree)
2092
self.addCleanup(preview.finalize)
2093
new_parent = preview.new_directory('new_parent', preview.root,
2095
preview.adjust_path('child', new_parent,
2096
preview.trans_id_file_id('child-id'))
2097
preview_tree = preview.get_preview_tree()
2098
self.assertIs(None, preview_tree.path2id('old_parent/child'))
2099
self.assertEqual('child-id', preview_tree.path2id('new_parent/child'))
2101
def test_path2id_renamed_parent(self):
2102
tree = self.make_branch_and_tree('tree')
2103
self.build_tree(['tree/old_name/', 'tree/old_name/child'])
2104
tree.add(['old_name', 'old_name/child'],
2105
['parent-id', 'child-id'])
2106
preview = TransformPreview(tree)
2107
self.addCleanup(preview.finalize)
2108
preview.adjust_path('new_name', preview.root,
2109
preview.trans_id_file_id('parent-id'))
2110
preview_tree = preview.get_preview_tree()
2111
self.assertIs(None, preview_tree.path2id('old_name/child'))
2112
self.assertEqual('child-id', preview_tree.path2id('new_name/child'))
2114
def assertMatchingIterEntries(self, tt, specific_file_ids=None):
2115
preview_tree = tt.get_preview_tree()
2116
preview_result = list(preview_tree.iter_entries_by_dir(
2120
actual_result = list(tree.iter_entries_by_dir(specific_file_ids))
2121
self.assertEqual(actual_result, preview_result)
2123
def test_iter_entries_by_dir_new(self):
2124
tree = self.make_branch_and_tree('tree')
2125
tt = TreeTransform(tree)
2126
tt.new_file('new', tt.root, 'contents', 'new-id')
2127
self.assertMatchingIterEntries(tt)
2129
def test_iter_entries_by_dir_deleted(self):
2130
tree = self.make_branch_and_tree('tree')
2131
self.build_tree(['tree/deleted'])
2132
tree.add('deleted', 'deleted-id')
2133
tt = TreeTransform(tree)
2134
tt.delete_contents(tt.trans_id_file_id('deleted-id'))
2135
self.assertMatchingIterEntries(tt)
2137
def test_iter_entries_by_dir_unversioned(self):
2138
tree = self.make_branch_and_tree('tree')
2139
self.build_tree(['tree/removed'])
2140
tree.add('removed', 'removed-id')
2141
tt = TreeTransform(tree)
2142
tt.unversion_file(tt.trans_id_file_id('removed-id'))
2143
self.assertMatchingIterEntries(tt)
2145
def test_iter_entries_by_dir_moved(self):
2146
tree = self.make_branch_and_tree('tree')
2147
self.build_tree(['tree/moved', 'tree/new_parent/'])
2148
tree.add(['moved', 'new_parent'], ['moved-id', 'new_parent-id'])
2149
tt = TreeTransform(tree)
2150
tt.adjust_path('moved', tt.trans_id_file_id('new_parent-id'),
2151
tt.trans_id_file_id('moved-id'))
2152
self.assertMatchingIterEntries(tt)
2154
def test_iter_entries_by_dir_specific_file_ids(self):
2155
tree = self.make_branch_and_tree('tree')
2156
tree.set_root_id('tree-root-id')
2157
self.build_tree(['tree/parent/', 'tree/parent/child'])
2158
tree.add(['parent', 'parent/child'], ['parent-id', 'child-id'])
2159
tt = TreeTransform(tree)
2160
self.assertMatchingIterEntries(tt, ['tree-root-id', 'child-id'])
2162
def test_symlink_content_summary(self):
2163
self.requireFeature(SymlinkFeature)
2164
preview = self.get_empty_preview()
2165
preview.new_symlink('path', preview.root, 'target', 'path-id')
2166
summary = preview.get_preview_tree().path_content_summary('path')
2167
self.assertEqual(('symlink', None, None, 'target'), summary)
2169
def test_missing_content_summary(self):
2170
preview = self.get_empty_preview()
2171
summary = preview.get_preview_tree().path_content_summary('path')
2172
self.assertEqual(('missing', None, None, None), summary)
2174
def test_deleted_content_summary(self):
2175
tree = self.make_branch_and_tree('tree')
2176
self.build_tree(['tree/path/'])
2178
preview = TransformPreview(tree)
2179
self.addCleanup(preview.finalize)
2180
preview.delete_contents(preview.trans_id_tree_path('path'))
2181
summary = preview.get_preview_tree().path_content_summary('path')
2182
self.assertEqual(('missing', None, None, None), summary)
2184
def test_file_content_summary_executable(self):
2185
if not osutils.supports_executable():
2186
raise TestNotApplicable()
2187
preview = self.get_empty_preview()
2188
path_id = preview.new_file('path', preview.root, 'contents', 'path-id')
2189
preview.set_executability(True, path_id)
2190
summary = preview.get_preview_tree().path_content_summary('path')
2191
self.assertEqual(4, len(summary))
2192
self.assertEqual('file', summary[0])
2193
# size must be known
2194
self.assertEqual(len('contents'), summary[1])
2196
self.assertEqual(True, summary[2])
2197
# will not have hash (not cheap to determine)
2198
self.assertIs(None, summary[3])
2200
def test_change_executability(self):
2201
if not osutils.supports_executable():
2202
raise TestNotApplicable()
2203
tree = self.make_branch_and_tree('tree')
2204
self.build_tree(['tree/path'])
2206
preview = TransformPreview(tree)
2207
self.addCleanup(preview.finalize)
2208
path_id = preview.trans_id_tree_path('path')
2209
preview.set_executability(True, path_id)
2210
summary = preview.get_preview_tree().path_content_summary('path')
2211
self.assertEqual(True, summary[2])
2213
def test_file_content_summary_non_exec(self):
2214
preview = self.get_empty_preview()
2215
preview.new_file('path', preview.root, 'contents', 'path-id')
2216
summary = preview.get_preview_tree().path_content_summary('path')
2217
self.assertEqual(4, len(summary))
2218
self.assertEqual('file', summary[0])
2219
# size must be known
2220
self.assertEqual(len('contents'), summary[1])
2222
if osutils.supports_executable():
2223
self.assertEqual(False, summary[2])
2225
self.assertEqual(None, summary[2])
2226
# will not have hash (not cheap to determine)
2227
self.assertIs(None, summary[3])
2229
def test_dir_content_summary(self):
2230
preview = self.get_empty_preview()
2231
preview.new_directory('path', preview.root, 'path-id')
2232
summary = preview.get_preview_tree().path_content_summary('path')
2233
self.assertEqual(('directory', None, None, None), summary)
2235
def test_tree_content_summary(self):
2236
preview = self.get_empty_preview()
2237
path = preview.new_directory('path', preview.root, 'path-id')
2238
preview.set_tree_reference('rev-1', path)
2239
summary = preview.get_preview_tree().path_content_summary('path')
2240
self.assertEqual(4, len(summary))
2241
self.assertEqual('tree-reference', summary[0])
2243
def test_annotate(self):
2244
tree = self.make_branch_and_tree('tree')
2245
self.build_tree_contents([('tree/file', 'a\n')])
2246
tree.add('file', 'file-id')
2247
tree.commit('a', rev_id='one')
2248
self.build_tree_contents([('tree/file', 'a\nb\n')])
2249
preview = TransformPreview(tree)
2250
self.addCleanup(preview.finalize)
2251
file_trans_id = preview.trans_id_file_id('file-id')
2252
preview.delete_contents(file_trans_id)
2253
preview.create_file('a\nb\nc\n', file_trans_id)
2254
preview_tree = preview.get_preview_tree()
2260
annotation = preview_tree.annotate_iter('file-id', 'me:')
2261
self.assertEqual(expected, annotation)
2263
def test_annotate_missing(self):
2264
preview = self.get_empty_preview()
2265
preview.new_file('file', preview.root, 'a\nb\nc\n', 'file-id')
2266
preview_tree = preview.get_preview_tree()
2272
annotation = preview_tree.annotate_iter('file-id', 'me:')
2273
self.assertEqual(expected, annotation)
2275
def test_annotate_rename(self):
2276
tree = self.make_branch_and_tree('tree')
2277
self.build_tree_contents([('tree/file', 'a\n')])
2278
tree.add('file', 'file-id')
2279
tree.commit('a', rev_id='one')
2280
preview = TransformPreview(tree)
2281
self.addCleanup(preview.finalize)
2282
file_trans_id = preview.trans_id_file_id('file-id')
2283
preview.adjust_path('newname', preview.root, file_trans_id)
2284
preview_tree = preview.get_preview_tree()
2288
annotation = preview_tree.annotate_iter('file-id', 'me:')
2289
self.assertEqual(expected, annotation)
2291
def test_annotate_deleted(self):
2292
tree = self.make_branch_and_tree('tree')
2293
self.build_tree_contents([('tree/file', 'a\n')])
2294
tree.add('file', 'file-id')
2295
tree.commit('a', rev_id='one')
2296
self.build_tree_contents([('tree/file', 'a\nb\n')])
2297
preview = TransformPreview(tree)
2298
self.addCleanup(preview.finalize)
2299
file_trans_id = preview.trans_id_file_id('file-id')
2300
preview.delete_contents(file_trans_id)
2301
preview_tree = preview.get_preview_tree()
2302
annotation = preview_tree.annotate_iter('file-id', 'me:')
2303
self.assertIs(None, annotation)
2305
def test_stored_kind(self):
2306
preview = self.get_empty_preview()
2307
preview.new_file('file', preview.root, 'a\nb\nc\n', 'file-id')
2308
preview_tree = preview.get_preview_tree()
2309
self.assertEqual('file', preview_tree.stored_kind('file-id'))
2311
def test_is_executable(self):
2312
preview = self.get_empty_preview()
2313
preview.new_file('file', preview.root, 'a\nb\nc\n', 'file-id')
2314
preview.set_executability(True, preview.trans_id_file_id('file-id'))
2315
preview_tree = preview.get_preview_tree()
2316
self.assertEqual(True, preview_tree.is_executable('file-id'))
2318
def test_get_set_parent_ids(self):
2319
revision_tree, preview_tree = self.get_tree_and_preview_tree()
2320
self.assertEqual([], preview_tree.get_parent_ids())
2321
preview_tree.set_parent_ids(['rev-1'])
2322
self.assertEqual(['rev-1'], preview_tree.get_parent_ids())
2324
def test_plan_file_merge(self):
2325
work_a = self.make_branch_and_tree('wta')
2326
self.build_tree_contents([('wta/file', 'a\nb\nc\nd\n')])
2327
work_a.add('file', 'file-id')
2328
base_id = work_a.commit('base version')
2329
tree_b = work_a.bzrdir.sprout('wtb').open_workingtree()
2330
preview = TransformPreview(work_a)
2331
self.addCleanup(preview.finalize)
2332
trans_id = preview.trans_id_file_id('file-id')
2333
preview.delete_contents(trans_id)
2334
preview.create_file('b\nc\nd\ne\n', trans_id)
2335
self.build_tree_contents([('wtb/file', 'a\nc\nd\nf\n')])
2336
tree_a = preview.get_preview_tree()
2337
tree_a.set_parent_ids([base_id])
2339
('killed-a', 'a\n'),
2340
('killed-b', 'b\n'),
2341
('unchanged', 'c\n'),
2342
('unchanged', 'd\n'),
2345
], list(tree_a.plan_file_merge('file-id', tree_b)))
2347
def test_plan_file_merge_revision_tree(self):
2348
work_a = self.make_branch_and_tree('wta')
2349
self.build_tree_contents([('wta/file', 'a\nb\nc\nd\n')])
2350
work_a.add('file', 'file-id')
2351
base_id = work_a.commit('base version')
2352
tree_b = work_a.bzrdir.sprout('wtb').open_workingtree()
2353
preview = TransformPreview(work_a.basis_tree())
2354
self.addCleanup(preview.finalize)
2355
trans_id = preview.trans_id_file_id('file-id')
2356
preview.delete_contents(trans_id)
2357
preview.create_file('b\nc\nd\ne\n', trans_id)
2358
self.build_tree_contents([('wtb/file', 'a\nc\nd\nf\n')])
2359
tree_a = preview.get_preview_tree()
2360
tree_a.set_parent_ids([base_id])
2362
('killed-a', 'a\n'),
2363
('killed-b', 'b\n'),
2364
('unchanged', 'c\n'),
2365
('unchanged', 'd\n'),
2368
], list(tree_a.plan_file_merge('file-id', tree_b)))