23
from bzrlib import osutils
24
from bzrlib.tests import SymlinkFeature, TestCaseWithTransport
25
from bzrlib.testament import Testament, StrictTestament, StrictTestament3
26
from bzrlib.transform import TreeTransform
23
from breezy import osutils
24
from breezy.tests import TestCaseWithTransport
25
from breezy.bzr.testament import (
30
from breezy.tests.features import (
29
35
class TestamentSetup(TestCaseWithTransport):
32
38
super(TestamentSetup, self).setUp()
33
self.wt = self.make_branch_and_tree('.', format='dirstate-with-subtree')
34
self.wt.set_root_id('TREE_ROT')
39
self.wt = self.make_branch_and_tree('.', format='development-subtree')
40
self.wt.set_root_id(b'TREE_ROT')
35
41
b = self.b = self.wt.branch
36
42
b.nick = "test branch"
37
43
self.wt.commit(message='initial null commit',
38
committer='test@user',
39
timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005'
42
self.build_tree_contents([('hello', 'contents of hello file'),
44
('src/foo.c', 'int main()\n{\n}\n')])
44
committer='test@user',
45
timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005'
47
rev_id=b'test@user-1')
48
self.build_tree_contents([('hello', b'contents of hello file'),
50
('src/foo.c', b'int main()\n{\n}\n')])
45
51
self.wt.add(['hello', 'src', 'src/foo.c'],
46
['hello-id', 'src-id', 'foo.c-id'])
47
tt = TreeTransform(self.wt)
52
[b'hello-id', b'src-id', b'foo.c-id'])
53
tt = self.wt.get_transform()
48
54
trans_id = tt.trans_id_tree_path('hello')
49
55
tt.set_executability(True, trans_id)
51
57
self.wt.commit(message='add files and directories',
55
committer='test@user')
60
rev_id=b'test@user-2',
61
committer='test@user')
58
64
class TestamentTests(TestamentSetup):
69
75
def test_null_testament(self):
70
76
"""Testament for a revision with no contents."""
71
t = self.from_revision(self.b.repository, 'test@user-1')
77
t = self.from_revision(self.b.repository, b'test@user-1')
72
78
ass = self.assertTrue
73
79
eq = self.assertEqual
74
80
ass(isinstance(t, Testament))
75
eq(t.revision_id, 'test@user-1')
81
eq(t.revision_id, b'test@user-1')
76
82
eq(t.committer, 'test@user')
77
83
eq(t.timestamp, 1129025423)
80
86
def test_testment_text_form(self):
81
87
"""Conversion of testament to canonical text form."""
82
t = self.from_revision(self.b.repository, 'test@user-1')
88
t = self.from_revision(self.b.repository, b'test@user-1')
83
89
text_form = t.as_text()
84
self.log('testament text form:\n' + text_form)
90
self.log('testament text form:\n%s' % text_form)
85
91
self.assertEqualDiff(text_form, self.expected('rev_1'))
86
92
short_text_form = t.as_short_text()
87
93
self.assertEqualDiff(short_text_form, self.expected('rev_1_short'))
89
95
def test_testament_with_contents(self):
90
96
"""Testament containing a file and a directory."""
91
t = self.from_revision(self.b.repository, 'test@user-2')
97
t = self.from_revision(self.b.repository, b'test@user-2')
92
98
text_form = t.as_text()
93
self.log('testament text form:\n' + text_form)
99
self.log('testament text form:\n%s' % text_form)
94
100
self.assertEqualDiff(text_form, self.expected('rev_2'))
95
101
actual_short = t.as_short_text()
96
102
self.assertEqualDiff(actual_short, self.expected('rev_2_short'))
99
105
"""Testament containing symlink (where possible)"""
100
106
self.requireFeature(SymlinkFeature)
101
107
os.symlink('wibble/linktarget', 'link')
102
self.wt.add(['link'], ['link-id'])
108
self.wt.add(['link'], [b'link-id'])
103
109
self.wt.commit(message='add symlink',
104
timestamp=1129025493,
106
rev_id='test@user-3',
107
committer='test@user')
108
t = self.from_revision(self.b.repository, 'test@user-3')
110
timestamp=1129025493,
112
rev_id=b'test@user-3',
113
committer='test@user')
114
t = self.from_revision(self.b.repository, b'test@user-3')
109
115
self.assertEqualDiff(t.as_text(), self.expected('rev_3'))
111
117
def test_testament_revprops(self):
112
118
"""Testament to revision with extra properties"""
113
props = dict(flavor='sour cherry\ncream cheese',
119
props = {u'flavor': 'sour cherry\ncream cheese',
117
123
self.wt.commit(message='revision with properties',
118
timestamp=1129025493,
120
rev_id='test@user-3',
121
committer='test@user',
123
t = self.from_revision(self.b.repository, 'test@user-3')
124
timestamp=1129025493,
126
rev_id=b'test@user-3',
127
committer='test@user',
129
t = self.from_revision(self.b.repository, b'test@user-3')
124
130
self.assertEqualDiff(t.as_text(), self.expected('rev_props'))
126
132
def test_testament_unicode_commit_message(self):
128
134
message=u'non-ascii commit \N{COPYRIGHT SIGN} me',
129
135
timestamp=1129025493,
131
rev_id='test@user-3',
132
committer='Erik B\xe5gfors <test@user>',
133
revprops={'uni':u'\xb5'}
137
rev_id=b'test@user-3',
138
committer=u'Erik B\xe5gfors <test@user>',
139
revprops={u'uni': u'\xb5'}
135
t = self.from_revision(self.b.repository, 'test@user-3')
141
t = self.from_revision(self.b.repository, b'test@user-3')
136
142
self.assertEqualDiff(
137
143
self.expected('sample_unicode').encode('utf-8'), t.as_text())
145
def test_from_tree(self):
146
tree = self.b.repository.revision_tree(b'test@user-2')
147
testament = self.testament_class().from_revision_tree(tree)
148
text_1 = testament.as_short_text()
149
text_2 = self.from_revision(self.b.repository,
150
b'test@user-2').as_short_text()
151
self.assertEqual(text_1, text_2)
139
153
def test___init__(self):
140
revision = self.b.repository.get_revision('test@user-2')
141
inventory = self.b.repository.get_inventory('test@user-2')
142
testament_1 = self.testament_class()(revision, inventory)
154
revision = self.b.repository.get_revision(b'test@user-2')
155
tree = self.b.repository.revision_tree(b'test@user-2')
156
testament_1 = self.testament_class()(revision, tree)
143
157
text_1 = testament_1.as_short_text()
144
158
text_2 = self.from_revision(self.b.repository,
145
'test@user-2').as_short_text()
159
b'test@user-2').as_short_text()
146
160
self.assertEqual(text_1, text_2)
158
172
return StrictTestament3
161
REV_1_TESTAMENT = """\
162
bazaar-ng testament version 1
163
revision-id: test@user-1
165
timestamp: 1129025423
177
REV_1_STRICT_TESTAMENT = """\
178
bazaar-ng testament version 2.1
179
revision-id: test@user-1
181
timestamp: 1129025423
193
REV_1_STRICT_TESTAMENT3 = """\
194
bazaar testament version 3 strict
195
revision-id: test@user-1
197
timestamp: 1129025423
203
directory . TREE_ROT test@user-1 no
211
bazaar-ng testament short form 1
212
revision-id: test@user-1
214
""" % osutils.sha(REV_1_TESTAMENT).hexdigest()
217
REV_1_SHORT_STRICT = """\
218
bazaar-ng testament short form 2.1
219
revision-id: test@user-1
221
""" % osutils.sha(REV_1_STRICT_TESTAMENT).hexdigest()
224
REV_1_SHORT_STRICT3 = """\
225
bazaar testament short form 3 strict
226
revision-id: test@user-1
228
""" % osutils.sha(REV_1_STRICT_TESTAMENT3).hexdigest()
231
REV_2_TESTAMENT = """\
232
bazaar-ng testament version 1
233
revision-id: test@user-2
235
timestamp: 1129025483
240
add files and directories
242
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
244
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
251
REV_2_STRICT_TESTAMENT = """\
252
bazaar-ng testament version 2.1
253
revision-id: test@user-2
255
timestamp: 1129025483
260
add files and directories
262
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
263
directory src src-id test@user-2 no
264
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
271
REV_2_STRICT_TESTAMENT3 = """\
272
bazaar testament version 3 strict
273
revision-id: test@user-2
275
timestamp: 1129025483
280
add files and directories
282
directory . TREE_ROT test@user-1 no
283
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
284
directory src src-id test@user-2 no
285
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
293
bazaar-ng testament short form 1
294
revision-id: test@user-2
296
""" % osutils.sha(REV_2_TESTAMENT).hexdigest()
299
REV_2_SHORT_STRICT = """\
300
bazaar-ng testament short form 2.1
301
revision-id: test@user-2
303
""" % osutils.sha(REV_2_STRICT_TESTAMENT).hexdigest()
306
REV_2_SHORT_STRICT3 = """\
307
bazaar testament short form 3 strict
308
revision-id: test@user-2
310
""" % osutils.sha(REV_2_STRICT_TESTAMENT3).hexdigest()
313
REV_PROPS_TESTAMENT = """\
314
bazaar-ng testament version 1
315
revision-id: test@user-3
317
timestamp: 1129025493
322
revision with properties
324
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
326
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
339
REV_PROPS_TESTAMENT_STRICT = """\
340
bazaar-ng testament version 2.1
341
revision-id: test@user-3
343
timestamp: 1129025493
348
revision with properties
350
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
351
directory src src-id test@user-2 no
352
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
365
REV_PROPS_TESTAMENT_STRICT3 = """\
366
bazaar testament version 3 strict
367
revision-id: test@user-3
369
timestamp: 1129025493
374
revision with properties
376
directory . TREE_ROT test@user-1 no
377
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
378
directory src src-id test@user-2 no
379
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
392
REV_3_TESTAMENT = """\
175
REV_1_TESTAMENT = b"""\
176
bazaar-ng testament version 1
177
revision-id: test@user-1
179
timestamp: 1129025423
191
REV_1_STRICT_TESTAMENT = b"""\
192
bazaar-ng testament version 2.1
193
revision-id: test@user-1
195
timestamp: 1129025423
207
REV_1_STRICT_TESTAMENT3 = b"""\
208
bazaar testament version 3 strict
209
revision-id: test@user-1
211
timestamp: 1129025423
217
directory . TREE_ROT test@user-1 no
225
bazaar-ng testament short form 1
226
revision-id: test@user-1
228
""" % osutils.sha_string(REV_1_TESTAMENT)
231
REV_1_SHORT_STRICT = b"""\
232
bazaar-ng testament short form 2.1
233
revision-id: test@user-1
235
""" % osutils.sha_string(REV_1_STRICT_TESTAMENT)
238
REV_1_SHORT_STRICT3 = b"""\
239
bazaar testament short form 3 strict
240
revision-id: test@user-1
242
""" % osutils.sha_string(REV_1_STRICT_TESTAMENT3)
245
REV_2_TESTAMENT = b"""\
246
bazaar-ng testament version 1
247
revision-id: test@user-2
249
timestamp: 1129025483
254
add files and directories
256
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
258
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
265
REV_2_STRICT_TESTAMENT = b"""\
266
bazaar-ng testament version 2.1
267
revision-id: test@user-2
269
timestamp: 1129025483
274
add files and directories
276
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
277
directory src src-id test@user-2 no
278
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
285
REV_2_STRICT_TESTAMENT3 = b"""\
286
bazaar testament version 3 strict
287
revision-id: test@user-2
289
timestamp: 1129025483
294
add files and directories
296
directory . TREE_ROT test@user-1 no
297
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
298
directory src src-id test@user-2 no
299
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
307
bazaar-ng testament short form 1
308
revision-id: test@user-2
310
""" % osutils.sha_string(REV_2_TESTAMENT)
313
REV_2_SHORT_STRICT = b"""\
314
bazaar-ng testament short form 2.1
315
revision-id: test@user-2
317
""" % osutils.sha_string(REV_2_STRICT_TESTAMENT)
320
REV_2_SHORT_STRICT3 = b"""\
321
bazaar testament short form 3 strict
322
revision-id: test@user-2
324
""" % osutils.sha_string(REV_2_STRICT_TESTAMENT3)
327
REV_PROPS_TESTAMENT = b"""\
328
bazaar-ng testament version 1
329
revision-id: test@user-3
331
timestamp: 1129025493
336
revision with properties
338
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
340
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
353
REV_PROPS_TESTAMENT_STRICT = b"""\
354
bazaar-ng testament version 2.1
355
revision-id: test@user-3
357
timestamp: 1129025493
362
revision with properties
364
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
365
directory src src-id test@user-2 no
366
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
379
REV_PROPS_TESTAMENT_STRICT3 = b"""\
380
bazaar testament version 3 strict
381
revision-id: test@user-3
383
timestamp: 1129025493
388
revision with properties
390
directory . TREE_ROT test@user-1 no
391
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
392
directory src src-id test@user-2 no
393
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
406
REV_3_TESTAMENT = b"""\
393
407
bazaar-ng testament version 1
394
408
revision-id: test@user-3
395
409
committer: test@user
524
Testament: { 'rev_1': REV_1_TESTAMENT,
525
'rev_1_short': REV_1_SHORT,
526
'rev_2': REV_2_TESTAMENT,
527
'rev_2_short': REV_2_SHORT,
528
'rev_3': REV_3_TESTAMENT,
529
'rev_props': REV_PROPS_TESTAMENT,
530
'sample_unicode': SAMPLE_UNICODE_TESTAMENT,
538
Testament: {'rev_1': REV_1_TESTAMENT,
539
'rev_1_short': REV_1_SHORT,
540
'rev_2': REV_2_TESTAMENT,
541
'rev_2_short': REV_2_SHORT,
542
'rev_3': REV_3_TESTAMENT,
543
'rev_props': REV_PROPS_TESTAMENT,
544
'sample_unicode': SAMPLE_UNICODE_TESTAMENT,
532
546
StrictTestament: {'rev_1': REV_1_STRICT_TESTAMENT,
533
547
'rev_1_short': REV_1_SHORT_STRICT,
534
548
'rev_2': REV_2_STRICT_TESTAMENT,
536
550
'rev_3': REV_3_TESTAMENT_STRICT,
537
551
'rev_props': REV_PROPS_TESTAMENT_STRICT,
538
552
'sample_unicode': SAMPLE_UNICODE_TESTAMENT_STRICT,
540
554
StrictTestament3: {'rev_1': REV_1_STRICT_TESTAMENT3,
541
'rev_1_short': REV_1_SHORT_STRICT3,
542
'rev_2': REV_2_STRICT_TESTAMENT3,
543
'rev_2_short': REV_2_SHORT_STRICT3,
544
'rev_3': REV_3_TESTAMENT_STRICT3,
545
'rev_props': REV_PROPS_TESTAMENT_STRICT3,
546
'sample_unicode': SAMPLE_UNICODE_TESTAMENT_STRICT3,
555
'rev_1_short': REV_1_SHORT_STRICT3,
556
'rev_2': REV_2_STRICT_TESTAMENT3,
557
'rev_2_short': REV_2_SHORT_STRICT3,
558
'rev_3': REV_3_TESTAMENT_STRICT3,
559
'rev_props': REV_PROPS_TESTAMENT_STRICT3,
560
'sample_unicode': SAMPLE_UNICODE_TESTAMENT_STRICT3,