128
130
self.assertIs(self.wt.is_executable('my_pretties2'), False)
129
131
self.assertEqual('directory', file_kind(self.wt.abspath('oz')))
130
132
self.assertEqual(len(modified_paths), 3)
131
tree_mod_paths = [self.wt.id2abspath(f) for f in
133
tree_mod_paths = [self.wt.id2abspath(f) for f in
132
134
('ozzie', 'my_pretties', 'my_pretties2')]
133
135
self.assertSubset(tree_mod_paths, modified_paths)
134
136
# is it safe to finalize repeatedly?
135
137
transform.finalize()
136
138
transform.finalize()
140
def test_create_files_same_timestamp(self):
141
transform, root = self.get_transform()
142
self.wt.lock_tree_write()
143
self.addCleanup(self.wt.unlock)
144
# Roll back the clock, so that we know everything is being set to the
146
transform._creation_mtime = creation_mtime = time.time() - 20.0
147
transform.create_file('content-one',
148
transform.create_path('one', root))
149
time.sleep(1) # *ugly*
150
transform.create_file('content-two',
151
transform.create_path('two', root))
153
fo, st1 = self.wt.get_file_with_stat(None, path='one', filtered=False)
155
fo, st2 = self.wt.get_file_with_stat(None, path='two', filtered=False)
157
# We only guarantee 2s resolution
158
self.assertTrue(abs(creation_mtime - st1.st_mtime) < 2.0,
159
"%s != %s within 2 seconds" % (creation_mtime, st1.st_mtime))
160
# But if we have more than that, all files should get the same result
161
self.assertEqual(st1.st_mtime, st2.st_mtime)
163
def test_change_root_id(self):
164
transform, root = self.get_transform()
165
self.assertNotEqual('new-root-id', self.wt.get_root_id())
166
transform.new_directory('', ROOT_PARENT, 'new-root-id')
167
transform.delete_contents(root)
168
transform.unversion_file(root)
169
transform.fixup_new_roots()
171
self.assertEqual('new-root-id', self.wt.get_root_id())
173
def test_change_root_id_add_files(self):
174
transform, root = self.get_transform()
175
self.assertNotEqual('new-root-id', self.wt.get_root_id())
176
new_trans_id = transform.new_directory('', ROOT_PARENT, 'new-root-id')
177
transform.new_file('file', new_trans_id, ['new-contents\n'],
179
transform.delete_contents(root)
180
transform.unversion_file(root)
181
transform.fixup_new_roots()
183
self.assertEqual('new-root-id', self.wt.get_root_id())
184
self.assertEqual('new-file-id', self.wt.path2id('file'))
185
self.assertFileEqual('new-contents\n', self.wt.abspath('file'))
187
def test_add_two_roots(self):
188
transform, root = self.get_transform()
189
new_trans_id = transform.new_directory('', ROOT_PARENT, 'new-root-id')
190
new_trans_id = transform.new_directory('', ROOT_PARENT, 'alt-root-id')
191
self.assertRaises(ValueError, transform.fixup_new_roots)
138
193
def test_hardlink(self):
139
194
self.requireFeature(HardlinkFeature)
140
195
transform, root = self.get_transform()
189
244
def test_conflicts(self):
190
245
transform, root = self.get_transform()
191
trans_id = transform.new_file('name', root, 'contents',
246
trans_id = transform.new_file('name', root, 'contents',
193
248
self.assertEqual(len(transform.find_conflicts()), 0)
194
249
trans_id2 = transform.new_file('name', root, 'Crontents', 'toto')
195
self.assertEqual(transform.find_conflicts(),
250
self.assertEqual(transform.find_conflicts(),
196
251
[('duplicate', trans_id, trans_id2, 'name')])
197
252
self.assertRaises(MalformedTransform, transform.apply)
198
253
transform.adjust_path('name', trans_id, trans_id2)
199
self.assertEqual(transform.find_conflicts(),
254
self.assertEqual(transform.find_conflicts(),
200
255
[('non-directory parent', trans_id)])
201
256
tinman_id = transform.trans_id_tree_path('tinman')
202
257
transform.adjust_path('name', tinman_id, trans_id2)
203
self.assertEqual(transform.find_conflicts(),
204
[('unversioned parent', tinman_id),
258
self.assertEqual(transform.find_conflicts(),
259
[('unversioned parent', tinman_id),
205
260
('missing parent', tinman_id)])
206
261
lion_id = transform.create_path('lion', root)
207
self.assertEqual(transform.find_conflicts(),
208
[('unversioned parent', tinman_id),
262
self.assertEqual(transform.find_conflicts(),
263
[('unversioned parent', tinman_id),
209
264
('missing parent', tinman_id)])
210
265
transform.adjust_path('name', lion_id, trans_id2)
211
self.assertEqual(transform.find_conflicts(),
266
self.assertEqual(transform.find_conflicts(),
212
267
[('unversioned parent', lion_id),
213
268
('missing parent', lion_id)])
214
269
transform.version_file("Courage", lion_id)
215
self.assertEqual(transform.find_conflicts(),
216
[('missing parent', lion_id),
270
self.assertEqual(transform.find_conflicts(),
271
[('missing parent', lion_id),
217
272
('versioning no contents', lion_id)])
218
273
transform.adjust_path('name2', root, trans_id2)
219
self.assertEqual(transform.find_conflicts(),
274
self.assertEqual(transform.find_conflicts(),
220
275
[('versioning no contents', lion_id)])
221
276
transform.create_file('Contents, okay?', lion_id)
222
277
transform.adjust_path('name2', trans_id2, trans_id2)
223
self.assertEqual(transform.find_conflicts(),
224
[('parent loop', trans_id2),
278
self.assertEqual(transform.find_conflicts(),
279
[('parent loop', trans_id2),
225
280
('non-directory parent', trans_id2)])
226
281
transform.adjust_path('name2', root, trans_id2)
227
282
oz_id = transform.new_directory('oz', root)
228
283
transform.set_executability(True, oz_id)
229
self.assertEqual(transform.find_conflicts(),
284
self.assertEqual(transform.find_conflicts(),
230
285
[('unversioned executability', oz_id)])
231
286
transform.version_file('oz-id', oz_id)
232
self.assertEqual(transform.find_conflicts(),
287
self.assertEqual(transform.find_conflicts(),
233
288
[('non-file executability', oz_id)])
234
289
transform.set_executability(None, oz_id)
235
290
tip_id = transform.new_file('tip', oz_id, 'ozma', 'tip-id')
1809
1986
self.assertEqual('FILE', target.id2path('upper-id'))
1989
class TestCommitTransform(tests.TestCaseWithTransport):
1991
def get_branch(self):
1992
tree = self.make_branch_and_tree('tree')
1994
self.addCleanup(tree.unlock)
1995
tree.commit('empty commit')
1998
def get_branch_and_transform(self):
1999
branch = self.get_branch()
2000
tt = TransformPreview(branch.basis_tree())
2001
self.addCleanup(tt.finalize)
2004
def test_commit_wrong_basis(self):
2005
branch = self.get_branch()
2006
basis = branch.repository.revision_tree(
2007
_mod_revision.NULL_REVISION)
2008
tt = TransformPreview(basis)
2009
self.addCleanup(tt.finalize)
2010
e = self.assertRaises(ValueError, tt.commit, branch, '')
2011
self.assertEqual('TreeTransform not based on branch basis: null:',
2014
def test_empy_commit(self):
2015
branch, tt = self.get_branch_and_transform()
2016
rev = tt.commit(branch, 'my message')
2017
self.assertEqual(2, branch.revno())
2018
repo = branch.repository
2019
self.assertEqual('my message', repo.get_revision(rev).message)
2021
def test_merge_parents(self):
2022
branch, tt = self.get_branch_and_transform()
2023
rev = tt.commit(branch, 'my message', ['rev1b', 'rev1c'])
2024
self.assertEqual(['rev1b', 'rev1c'],
2025
branch.basis_tree().get_parent_ids()[1:])
2027
def test_first_commit(self):
2028
branch = self.make_branch('branch')
2030
self.addCleanup(branch.unlock)
2031
tt = TransformPreview(branch.basis_tree())
2032
self.addCleanup(tt.finalize)
2033
tt.new_directory('', ROOT_PARENT, 'TREE_ROOT')
2034
rev = tt.commit(branch, 'my message')
2035
self.assertEqual([], branch.basis_tree().get_parent_ids())
2036
self.assertNotEqual(_mod_revision.NULL_REVISION,
2037
branch.last_revision())
2039
def test_first_commit_with_merge_parents(self):
2040
branch = self.make_branch('branch')
2042
self.addCleanup(branch.unlock)
2043
tt = TransformPreview(branch.basis_tree())
2044
self.addCleanup(tt.finalize)
2045
e = self.assertRaises(ValueError, tt.commit, branch,
2046
'my message', ['rev1b-id'])
2047
self.assertEqual('Cannot supply merge parents for first commit.',
2049
self.assertEqual(_mod_revision.NULL_REVISION, branch.last_revision())
2051
def test_add_files(self):
2052
branch, tt = self.get_branch_and_transform()
2053
tt.new_file('file', tt.root, 'contents', 'file-id')
2054
trans_id = tt.new_directory('dir', tt.root, 'dir-id')
2055
if SymlinkFeature.available():
2056
tt.new_symlink('symlink', trans_id, 'target', 'symlink-id')
2057
rev = tt.commit(branch, 'message')
2058
tree = branch.basis_tree()
2059
self.assertEqual('file', tree.id2path('file-id'))
2060
self.assertEqual('contents', tree.get_file_text('file-id'))
2061
self.assertEqual('dir', tree.id2path('dir-id'))
2062
if SymlinkFeature.available():
2063
self.assertEqual('dir/symlink', tree.id2path('symlink-id'))
2064
self.assertEqual('target', tree.get_symlink_target('symlink-id'))
2066
def test_add_unversioned(self):
2067
branch, tt = self.get_branch_and_transform()
2068
tt.new_file('file', tt.root, 'contents')
2069
self.assertRaises(errors.StrictCommitFailed, tt.commit, branch,
2070
'message', strict=True)
2072
def test_modify_strict(self):
2073
branch, tt = self.get_branch_and_transform()
2074
tt.new_file('file', tt.root, 'contents', 'file-id')
2075
tt.commit(branch, 'message', strict=True)
2076
tt = TransformPreview(branch.basis_tree())
2077
self.addCleanup(tt.finalize)
2078
trans_id = tt.trans_id_file_id('file-id')
2079
tt.delete_contents(trans_id)
2080
tt.create_file('contents', trans_id)
2081
tt.commit(branch, 'message', strict=True)
2083
def test_commit_malformed(self):
2084
"""Committing a malformed transform should raise an exception.
2086
In this case, we are adding a file without adding its parent.
2088
branch, tt = self.get_branch_and_transform()
2089
parent_id = tt.trans_id_file_id('parent-id')
2090
tt.new_file('file', parent_id, 'contents', 'file-id')
2091
self.assertRaises(errors.MalformedTransform, tt.commit, branch,
1812
2095
class MockTransform(object):
1814
2097
def has_named_child(self, by_parent, parent_id, name):
2446
2738
def test_walkdirs(self):
2447
2739
preview = self.get_empty_preview()
2448
preview.version_file('tree-root', preview.root)
2740
root = preview.new_directory('', ROOT_PARENT, 'tree-root')
2741
# FIXME: new_directory should mark root.
2742
preview.fixup_new_roots()
2449
2743
preview_tree = preview.get_preview_tree()
2450
2744
file_trans_id = preview.new_file('a', preview.root, 'contents',
2452
2746
expected = [(('', 'tree-root'),
2453
2747
[('a', 'a', 'file', None, 'a-id', 'file')])]
2454
2748
self.assertEqual(expected, list(preview_tree.walkdirs()))
2750
def test_extras(self):
2751
work_tree = self.make_branch_and_tree('tree')
2752
self.build_tree(['tree/removed-file', 'tree/existing-file',
2753
'tree/not-removed-file'])
2754
work_tree.add(['removed-file', 'not-removed-file'])
2755
preview = TransformPreview(work_tree)
2756
self.addCleanup(preview.finalize)
2757
preview.new_file('new-file', preview.root, 'contents')
2758
preview.new_file('new-versioned-file', preview.root, 'contents',
2760
tree = preview.get_preview_tree()
2761
preview.unversion_file(preview.trans_id_tree_path('removed-file'))
2762
self.assertEqual(set(['new-file', 'removed-file', 'existing-file']),
2765
def test_merge_into_preview(self):
2766
work_tree = self.make_branch_and_tree('tree')
2767
self.build_tree_contents([('tree/file','b\n')])
2768
work_tree.add('file', 'file-id')
2769
work_tree.commit('first commit')
2770
child_tree = work_tree.bzrdir.sprout('child').open_workingtree()
2771
self.build_tree_contents([('child/file','b\nc\n')])
2772
child_tree.commit('child commit')
2773
child_tree.lock_write()
2774
self.addCleanup(child_tree.unlock)
2775
work_tree.lock_write()
2776
self.addCleanup(work_tree.unlock)
2777
preview = TransformPreview(work_tree)
2778
self.addCleanup(preview.finalize)
2779
file_trans_id = preview.trans_id_file_id('file-id')
2780
preview.delete_contents(file_trans_id)
2781
preview.create_file('a\nb\n', file_trans_id)
2782
preview_tree = preview.get_preview_tree()
2783
merger = Merger.from_revision_ids(None, preview_tree,
2784
child_tree.branch.last_revision(),
2785
other_branch=child_tree.branch,
2786
tree_branch=work_tree.branch)
2787
merger.merge_type = Merge3Merger
2788
tt = merger.make_merger().make_preview_transform()
2789
self.addCleanup(tt.finalize)
2790
final_tree = tt.get_preview_tree()
2791
self.assertEqual('a\nb\nc\n', final_tree.get_file_text('file-id'))
2793
def test_merge_preview_into_workingtree(self):
2794
tree = self.make_branch_and_tree('tree')
2795
tree.set_root_id('TREE_ROOT')
2796
tt = TransformPreview(tree)
2797
self.addCleanup(tt.finalize)
2798
tt.new_file('name', tt.root, 'content', 'file-id')
2799
tree2 = self.make_branch_and_tree('tree2')
2800
tree2.set_root_id('TREE_ROOT')
2801
merger = Merger.from_uncommitted(tree2, tt.get_preview_tree(),
2802
None, tree.basis_tree())
2803
merger.merge_type = Merge3Merger
2806
def test_merge_preview_into_workingtree_handles_conflicts(self):
2807
tree = self.make_branch_and_tree('tree')
2808
self.build_tree_contents([('tree/foo', 'bar')])
2809
tree.add('foo', 'foo-id')
2811
tt = TransformPreview(tree)
2812
self.addCleanup(tt.finalize)
2813
trans_id = tt.trans_id_file_id('foo-id')
2814
tt.delete_contents(trans_id)
2815
tt.create_file('baz', trans_id)
2816
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
2817
self.build_tree_contents([('tree2/foo', 'qux')])
2819
merger = Merger.from_uncommitted(tree2, tt.get_preview_tree(),
2820
pb, tree.basis_tree())
2821
merger.merge_type = Merge3Merger
2824
def test_is_executable(self):
2825
tree = self.make_branch_and_tree('tree')
2826
preview = TransformPreview(tree)
2827
self.addCleanup(preview.finalize)
2828
preview.new_file('foo', preview.root, 'bar', 'baz-id')
2829
preview_tree = preview.get_preview_tree()
2830
self.assertEqual(False, preview_tree.is_executable('baz-id',
2832
self.assertEqual(False, preview_tree.is_executable('baz-id'))
2834
def test_commit_preview_tree(self):
2835
tree = self.make_branch_and_tree('tree')
2836
rev_id = tree.commit('rev1')
2837
tree.branch.lock_write()
2838
self.addCleanup(tree.branch.unlock)
2839
tt = TransformPreview(tree)
2840
tt.new_file('file', tt.root, 'contents', 'file_id')
2841
self.addCleanup(tt.finalize)
2842
preview = tt.get_preview_tree()
2843
preview.set_parent_ids([rev_id])
2844
builder = tree.branch.get_commit_builder([rev_id])
2845
list(builder.record_iter_changes(preview, rev_id, tt.iter_changes()))
2846
builder.finish_inventory()
2847
rev2_id = builder.commit('rev2')
2848
rev2_tree = tree.branch.repository.revision_tree(rev2_id)
2849
self.assertEqual('contents', rev2_tree.get_file_text('file_id'))
2851
def test_ascii_limbo_paths(self):
2852
self.requireFeature(tests.UnicodeFilenameFeature)
2853
branch = self.make_branch('any')
2854
tree = branch.repository.revision_tree(_mod_revision.NULL_REVISION)
2855
tt = TransformPreview(tree)
2856
self.addCleanup(tt.finalize)
2857
foo_id = tt.new_directory('', ROOT_PARENT)
2858
bar_id = tt.new_file(u'\u1234bar', foo_id, 'contents')
2859
limbo_path = tt._limbo_name(bar_id)
2860
self.assertEqual(limbo_path.encode('ascii', 'replace'), limbo_path)
2863
class FakeSerializer(object):
2864
"""Serializer implementation that simply returns the input.
2866
The input is returned in the order used by pack.ContainerPushParser.
2869
def bytes_record(bytes, names):
2873
class TestSerializeTransform(tests.TestCaseWithTransport):
2875
_test_needs_features = [tests.UnicodeFilenameFeature]
2877
def get_preview(self, tree=None):
2879
tree = self.make_branch_and_tree('tree')
2880
tt = TransformPreview(tree)
2881
self.addCleanup(tt.finalize)
2884
def assertSerializesTo(self, expected, tt):
2885
records = list(tt.serialize(FakeSerializer()))
2886
self.assertEqual(expected, records)
2889
def default_attribs():
2894
'_new_executability': {},
2896
'_tree_path_ids': {'': 'new-0'},
2898
'_removed_contents': [],
2899
'_non_present_ids': {},
2902
def make_records(self, attribs, contents):
2904
(((('attribs'),),), bencode.bencode(attribs))]
2905
records.extend([(((n, k),), c) for n, k, c in contents])
2908
def creation_records(self):
2909
attribs = self.default_attribs()
2910
attribs['_id_number'] = 3
2911
attribs['_new_name'] = {
2912
'new-1': u'foo\u1234'.encode('utf-8'), 'new-2': 'qux'}
2913
attribs['_new_id'] = {'new-1': 'baz', 'new-2': 'quxx'}
2914
attribs['_new_parent'] = {'new-1': 'new-0', 'new-2': 'new-0'}
2915
attribs['_new_executability'] = {'new-1': 1}
2917
('new-1', 'file', 'i 1\nbar\n'),
2918
('new-2', 'directory', ''),
2920
return self.make_records(attribs, contents)
2922
def test_serialize_creation(self):
2923
tt = self.get_preview()
2924
tt.new_file(u'foo\u1234', tt.root, 'bar', 'baz', True)
2925
tt.new_directory('qux', tt.root, 'quxx')
2926
self.assertSerializesTo(self.creation_records(), tt)
2928
def test_deserialize_creation(self):
2929
tt = self.get_preview()
2930
tt.deserialize(iter(self.creation_records()))
2931
self.assertEqual(3, tt._id_number)
2932
self.assertEqual({'new-1': u'foo\u1234',
2933
'new-2': 'qux'}, tt._new_name)
2934
self.assertEqual({'new-1': 'baz', 'new-2': 'quxx'}, tt._new_id)
2935
self.assertEqual({'new-1': tt.root, 'new-2': tt.root}, tt._new_parent)
2936
self.assertEqual({'baz': 'new-1', 'quxx': 'new-2'}, tt._r_new_id)
2937
self.assertEqual({'new-1': True}, tt._new_executability)
2938
self.assertEqual({'new-1': 'file',
2939
'new-2': 'directory'}, tt._new_contents)
2940
foo_limbo = open(tt._limbo_name('new-1'), 'rb')
2942
foo_content = foo_limbo.read()
2945
self.assertEqual('bar', foo_content)
2947
def symlink_creation_records(self):
2948
attribs = self.default_attribs()
2949
attribs['_id_number'] = 2
2950
attribs['_new_name'] = {'new-1': u'foo\u1234'.encode('utf-8')}
2951
attribs['_new_parent'] = {'new-1': 'new-0'}
2952
contents = [('new-1', 'symlink', u'bar\u1234'.encode('utf-8'))]
2953
return self.make_records(attribs, contents)
2955
def test_serialize_symlink_creation(self):
2956
self.requireFeature(tests.SymlinkFeature)
2957
tt = self.get_preview()
2958
tt.new_symlink(u'foo\u1234', tt.root, u'bar\u1234')
2959
self.assertSerializesTo(self.symlink_creation_records(), tt)
2961
def test_deserialize_symlink_creation(self):
2962
self.requireFeature(tests.SymlinkFeature)
2963
tt = self.get_preview()
2964
tt.deserialize(iter(self.symlink_creation_records()))
2965
abspath = tt._limbo_name('new-1')
2966
foo_content = osutils.readlink(abspath)
2967
self.assertEqual(u'bar\u1234', foo_content)
2969
def make_destruction_preview(self):
2970
tree = self.make_branch_and_tree('.')
2971
self.build_tree([u'foo\u1234', 'bar'])
2972
tree.add([u'foo\u1234', 'bar'], ['foo-id', 'bar-id'])
2973
return self.get_preview(tree)
2975
def destruction_records(self):
2976
attribs = self.default_attribs()
2977
attribs['_id_number'] = 3
2978
attribs['_removed_id'] = ['new-1']
2979
attribs['_removed_contents'] = ['new-2']
2980
attribs['_tree_path_ids'] = {
2982
u'foo\u1234'.encode('utf-8'): 'new-1',
2985
return self.make_records(attribs, [])
2987
def test_serialize_destruction(self):
2988
tt = self.make_destruction_preview()
2989
foo_trans_id = tt.trans_id_tree_file_id('foo-id')
2990
tt.unversion_file(foo_trans_id)
2991
bar_trans_id = tt.trans_id_tree_file_id('bar-id')
2992
tt.delete_contents(bar_trans_id)
2993
self.assertSerializesTo(self.destruction_records(), tt)
2995
def test_deserialize_destruction(self):
2996
tt = self.make_destruction_preview()
2997
tt.deserialize(iter(self.destruction_records()))
2998
self.assertEqual({u'foo\u1234': 'new-1',
3000
'': tt.root}, tt._tree_path_ids)
3001
self.assertEqual({'new-1': u'foo\u1234',
3003
tt.root: ''}, tt._tree_id_paths)
3004
self.assertEqual(set(['new-1']), tt._removed_id)
3005
self.assertEqual(set(['new-2']), tt._removed_contents)
3007
def missing_records(self):
3008
attribs = self.default_attribs()
3009
attribs['_id_number'] = 2
3010
attribs['_non_present_ids'] = {
3012
return self.make_records(attribs, [])
3014
def test_serialize_missing(self):
3015
tt = self.get_preview()
3016
boo_trans_id = tt.trans_id_file_id('boo')
3017
self.assertSerializesTo(self.missing_records(), tt)
3019
def test_deserialize_missing(self):
3020
tt = self.get_preview()
3021
tt.deserialize(iter(self.missing_records()))
3022
self.assertEqual({'boo': 'new-1'}, tt._non_present_ids)
3024
def make_modification_preview(self):
3025
LINES_ONE = 'aa\nbb\ncc\ndd\n'
3026
LINES_TWO = 'z\nbb\nx\ndd\n'
3027
tree = self.make_branch_and_tree('tree')
3028
self.build_tree_contents([('tree/file', LINES_ONE)])
3029
tree.add('file', 'file-id')
3030
return self.get_preview(tree), LINES_TWO
3032
def modification_records(self):
3033
attribs = self.default_attribs()
3034
attribs['_id_number'] = 2
3035
attribs['_tree_path_ids'] = {
3038
attribs['_removed_contents'] = ['new-1']
3039
contents = [('new-1', 'file',
3040
'i 1\nz\n\nc 0 1 1 1\ni 1\nx\n\nc 0 3 3 1\n')]
3041
return self.make_records(attribs, contents)
3043
def test_serialize_modification(self):
3044
tt, LINES = self.make_modification_preview()
3045
trans_id = tt.trans_id_file_id('file-id')
3046
tt.delete_contents(trans_id)
3047
tt.create_file(LINES, trans_id)
3048
self.assertSerializesTo(self.modification_records(), tt)
3050
def test_deserialize_modification(self):
3051
tt, LINES = self.make_modification_preview()
3052
tt.deserialize(iter(self.modification_records()))
3053
self.assertFileEqual(LINES, tt._limbo_name('new-1'))
3055
def make_kind_change_preview(self):
3056
LINES = 'a\nb\nc\nd\n'
3057
tree = self.make_branch_and_tree('tree')
3058
self.build_tree(['tree/foo/'])
3059
tree.add('foo', 'foo-id')
3060
return self.get_preview(tree), LINES
3062
def kind_change_records(self):
3063
attribs = self.default_attribs()
3064
attribs['_id_number'] = 2
3065
attribs['_tree_path_ids'] = {
3068
attribs['_removed_contents'] = ['new-1']
3069
contents = [('new-1', 'file',
3070
'i 4\na\nb\nc\nd\n\n')]
3071
return self.make_records(attribs, contents)
3073
def test_serialize_kind_change(self):
3074
tt, LINES = self.make_kind_change_preview()
3075
trans_id = tt.trans_id_file_id('foo-id')
3076
tt.delete_contents(trans_id)
3077
tt.create_file(LINES, trans_id)
3078
self.assertSerializesTo(self.kind_change_records(), tt)
3080
def test_deserialize_kind_change(self):
3081
tt, LINES = self.make_kind_change_preview()
3082
tt.deserialize(iter(self.kind_change_records()))
3083
self.assertFileEqual(LINES, tt._limbo_name('new-1'))
3085
def make_add_contents_preview(self):
3086
LINES = 'a\nb\nc\nd\n'
3087
tree = self.make_branch_and_tree('tree')
3088
self.build_tree(['tree/foo'])
3090
os.unlink('tree/foo')
3091
return self.get_preview(tree), LINES
3093
def add_contents_records(self):
3094
attribs = self.default_attribs()
3095
attribs['_id_number'] = 2
3096
attribs['_tree_path_ids'] = {
3099
contents = [('new-1', 'file',
3100
'i 4\na\nb\nc\nd\n\n')]
3101
return self.make_records(attribs, contents)
3103
def test_serialize_add_contents(self):
3104
tt, LINES = self.make_add_contents_preview()
3105
trans_id = tt.trans_id_tree_path('foo')
3106
tt.create_file(LINES, trans_id)
3107
self.assertSerializesTo(self.add_contents_records(), tt)
3109
def test_deserialize_add_contents(self):
3110
tt, LINES = self.make_add_contents_preview()
3111
tt.deserialize(iter(self.add_contents_records()))
3112
self.assertFileEqual(LINES, tt._limbo_name('new-1'))
3114
def test_get_parents_lines(self):
3115
LINES_ONE = 'aa\nbb\ncc\ndd\n'
3116
LINES_TWO = 'z\nbb\nx\ndd\n'
3117
tree = self.make_branch_and_tree('tree')
3118
self.build_tree_contents([('tree/file', LINES_ONE)])
3119
tree.add('file', 'file-id')
3120
tt = self.get_preview(tree)
3121
trans_id = tt.trans_id_tree_path('file')
3122
self.assertEqual((['aa\n', 'bb\n', 'cc\n', 'dd\n'],),
3123
tt._get_parents_lines(trans_id))
3125
def test_get_parents_texts(self):
3126
LINES_ONE = 'aa\nbb\ncc\ndd\n'
3127
LINES_TWO = 'z\nbb\nx\ndd\n'
3128
tree = self.make_branch_and_tree('tree')
3129
self.build_tree_contents([('tree/file', LINES_ONE)])
3130
tree.add('file', 'file-id')
3131
tt = self.get_preview(tree)
3132
trans_id = tt.trans_id_tree_path('file')
3133
self.assertEqual((LINES_ONE,),
3134
tt._get_parents_texts(trans_id))