/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
1
# Copyright (C) 2007-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
2
# -*- encoding: utf-8 -*-
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
3
#
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
8
#
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
13
#
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
0.358.1 by Jelmer Vernooij
Fix FSF address.
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
17
0.358.3 by Jelmer Vernooij
Enable absolute import.
18
"""Tests for mapping."""
19
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
20
from ...revision import (
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
21
    Revision,
22
    )
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
23
0.200.264 by Jelmer Vernooij
Add more tests.
24
from dulwich.objects import (
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
25
    Blob,
0.200.264 by Jelmer Vernooij
Add more tests.
26
    Commit,
0.413.2 by Jelmer Vernooij
Add support for the mergetag property in git.
27
    Tag,
0.200.1589 by Jelmer Vernooij
Add test to make sure that certain invalid timezones are roundtripped correctly.
28
    parse_timezone,
0.200.264 by Jelmer Vernooij
Add more tests.
29
    )
0.413.2 by Jelmer Vernooij
Add support for the mergetag property in git.
30
from dulwich.tests.utils import (
31
    make_object,
32
    )
0.200.264 by Jelmer Vernooij
Add more tests.
33
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
34
from .. import tests
35
from ..mapping import (
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
36
    BzrGitMappingv1,
37
    escape_file_id,
0.402.1 by Jelmer Vernooij
Improve identifier handling.
38
    fix_person_identifier,
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
39
    unescape_file_id,
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
40
    UnknownCommitExtra,
41
    UnknownMercurialCommitExtra,
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
42
    )
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
43
44
45
class TestRevidConversionV1(tests.TestCase):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
46
47
    def test_simple_git_to_bzr_revision_id(self):
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
48
        self.assertEqual(b"git-v1:"
49
                         b"c6a4d8f1fa4ac650748e647c4b1b368f589a7356",
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
50
                         BzrGitMappingv1().revision_id_foreign_to_bzr(
7143.15.2 by Jelmer Vernooij
Run autopep8.
51
                             b"c6a4d8f1fa4ac650748e647c4b1b368f589a7356"))
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
52
53
    def test_simple_bzr_to_git_revision_id(self):
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
54
        self.assertEqual((b"c6a4d8f1fa4ac650748e647c4b1b368f589a7356",
7143.15.2 by Jelmer Vernooij
Run autopep8.
55
                          BzrGitMappingv1()),
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
56
                         BzrGitMappingv1().revision_id_bzr_to_foreign(
7143.15.2 by Jelmer Vernooij
Run autopep8.
57
            b"git-v1:"
58
            b"c6a4d8f1fa4ac650748e647c4b1b368f589a7356"))
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
59
0.252.26 by Jelmer Vernooij
Add is_control_file method to BzrGitMapping.
60
    def test_is_control_file(self):
61
        mapping = BzrGitMappingv1()
0.200.920 by Jelmer Vernooij
Fix some more tests.
62
        if mapping.roundtripping:
0.200.1752 by Jelmer Vernooij
Don't traverse nested trees in WorkingTree.smart_add.
63
            self.assertTrue(mapping.is_special_file(".bzrdummy"))
64
            self.assertTrue(mapping.is_special_file(".bzrfileids"))
65
        self.assertFalse(mapping.is_special_file(".bzrfoo"))
0.252.26 by Jelmer Vernooij
Add is_control_file method to BzrGitMapping.
66
0.200.973 by Jelmer Vernooij
Add tests for generate_file_id.
67
    def test_generate_file_id(self):
68
        mapping = BzrGitMappingv1()
7018.3.2 by Jelmer Vernooij
Fix some git tests.
69
        self.assertIsInstance(mapping.generate_file_id("la"), bytes)
70
        self.assertIsInstance(mapping.generate_file_id(u"é"), bytes)
0.200.973 by Jelmer Vernooij
Add tests for generate_file_id.
71
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
72
73
class FileidTests(tests.TestCase):
74
75
    def test_escape_space(self):
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
76
        self.assertEqual(b"bla_s", escape_file_id(b"bla "))
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
77
0.200.1419 by Jelmer Vernooij
Escape/unescape ^L characters.
78
    def test_escape_control_l(self):
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
79
        self.assertEqual(b"bla_c", escape_file_id(b"bla\x0c"))
0.200.1419 by Jelmer Vernooij
Escape/unescape ^L characters.
80
81
    def test_unescape_control_l(self):
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
82
        self.assertEqual(b"bla\x0c", unescape_file_id(b"bla_c"))
0.200.1419 by Jelmer Vernooij
Escape/unescape ^L characters.
83
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
84
    def test_escape_underscore(self):
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
85
        self.assertEqual(b"bla__", escape_file_id(b"bla_"))
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
86
87
    def test_escape_underscore_space(self):
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
88
        self.assertEqual(b"bla___s", escape_file_id(b"bla_ "))
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
89
90
    def test_unescape_underscore(self):
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
91
        self.assertEqual(b"bla ", unescape_file_id(b"bla_s"))
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
92
93
    def test_unescape_underscore_space(self):
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
94
        self.assertEqual(b"bla _", unescape_file_id(b"bla_s__"))
0.200.264 by Jelmer Vernooij
Add more tests.
95
96
97
class TestImportCommit(tests.TestCase):
98
99
    def test_commit(self):
100
        c = Commit()
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
101
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
102
        c.message = b"Some message"
103
        c.committer = b"Committer"
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
104
        c.commit_time = 4
105
        c.author_time = 5
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
106
        c.commit_timezone = 60 * 5
107
        c.author_timezone = 60 * 3
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
108
        c.author = b"Author"
0.252.44 by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped.
109
        mapping = BzrGitMappingv1()
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
110
        rev, roundtrip_revid, verifiers = mapping.import_commit(
111
            c, mapping.revision_id_foreign_to_bzr)
6964.2.3 by Jelmer Vernooij
Review comments.
112
        self.assertEqual(None, roundtrip_revid)
113
        self.assertEqual({}, verifiers)
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
114
        self.assertEqual(u"Some message", rev.message)
115
        self.assertEqual(u"Committer", rev.committer)
116
        self.assertEqual(u"Author", rev.properties[u'author'])
6964.2.3 by Jelmer Vernooij
Review comments.
117
        self.assertEqual(300, rev.timezone)
7096.3.2 by Jelmer Vernooij
Fix some git tests.
118
        self.assertEqual([], rev.parent_ids)
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
119
        self.assertEqual("5", rev.properties[u'author-timestamp'])
120
        self.assertEqual("180", rev.properties[u'author-timezone'])
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
121
        self.assertEqual(b"git-v1:" + c.id, rev.revision_id)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
122
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
123
    def test_explicit_encoding(self):
124
        c = Commit()
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
125
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
126
        c.message = b"Some message"
127
        c.committer = b"Committer"
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
128
        c.commit_time = 4
129
        c.author_time = 5
130
        c.commit_timezone = 60 * 5
131
        c.author_timezone = 60 * 3
132
        c.author = u"Authér".encode("iso8859-1")
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
133
        c.encoding = b"iso8859-1"
0.252.44 by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped.
134
        mapping = BzrGitMappingv1()
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
135
        rev, roundtrip_revid, verifiers = mapping.import_commit(
136
            c, mapping.revision_id_foreign_to_bzr)
6964.2.3 by Jelmer Vernooij
Review comments.
137
        self.assertEqual(None, roundtrip_revid)
138
        self.assertEqual({}, verifiers)
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
139
        self.assertEqual(u"Authér", rev.properties[u'author'])
140
        self.assertEqual("iso8859-1", rev.properties[u"git-explicit-encoding"])
141
        self.assertTrue(u"git-implicit-encoding" not in rev.properties)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
142
143
    def test_implicit_encoding_fallback(self):
144
        c = Commit()
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
145
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
146
        c.message = b"Some message"
147
        c.committer = b"Committer"
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
148
        c.commit_time = 4
149
        c.author_time = 5
150
        c.commit_timezone = 60 * 5
151
        c.author_timezone = 60 * 3
152
        c.author = u"Authér".encode("latin1")
0.252.44 by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped.
153
        mapping = BzrGitMappingv1()
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
154
        rev, roundtrip_revid, verifiers = mapping.import_commit(
155
            c, mapping.revision_id_foreign_to_bzr)
6964.2.3 by Jelmer Vernooij
Review comments.
156
        self.assertEqual(None, roundtrip_revid)
157
        self.assertEqual({}, verifiers)
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
158
        self.assertEqual(u"Authér", rev.properties[u'author'])
159
        self.assertEqual("latin1", rev.properties[u"git-implicit-encoding"])
160
        self.assertTrue(u"git-explicit-encoding" not in rev.properties)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
161
162
    def test_implicit_encoding_utf8(self):
163
        c = Commit()
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
164
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
165
        c.message = b"Some message"
166
        c.committer = b"Committer"
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
167
        c.commit_time = 4
168
        c.author_time = 5
169
        c.commit_timezone = 60 * 5
170
        c.author_timezone = 60 * 3
171
        c.author = u"Authér".encode("utf-8")
0.252.44 by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped.
172
        mapping = BzrGitMappingv1()
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
173
        rev, roundtrip_revid, verifiers = mapping.import_commit(
174
            c, mapping.revision_id_foreign_to_bzr)
6964.2.3 by Jelmer Vernooij
Review comments.
175
        self.assertEqual(None, roundtrip_revid)
176
        self.assertEqual({}, verifiers)
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
177
        self.assertEqual(u"Authér", rev.properties[u'author'])
6973.13.2 by Jelmer Vernooij
Fix some more tests.
178
        self.assertTrue(u"git-explicit-encoding" not in rev.properties)
179
        self.assertTrue(u"git-implicit-encoding" not in rev.properties)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
180
0.200.1598 by Jelmer Vernooij
Print proper error when unknown fields are encountered.
181
    def test_unknown_extra(self):
182
        c = Commit()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
183
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
184
        c.message = b"Some message"
185
        c.committer = b"Committer"
0.200.1598 by Jelmer Vernooij
Print proper error when unknown fields are encountered.
186
        c.commit_time = 4
187
        c.author_time = 5
188
        c.commit_timezone = 60 * 5
189
        c.author_timezone = 60 * 3
6973.13.2 by Jelmer Vernooij
Fix some more tests.
190
        c.author = b"Author"
191
        c._extra.append((b"iamextra", b"foo"))
0.200.1598 by Jelmer Vernooij
Print proper error when unknown fields are encountered.
192
        mapping = BzrGitMappingv1()
193
        self.assertRaises(UnknownCommitExtra, mapping.import_commit, c,
7143.15.2 by Jelmer Vernooij
Run autopep8.
194
                          mapping.revision_id_foreign_to_bzr)
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
195
        mapping.import_commit(c, mapping.revision_id_foreign_to_bzr, strict=False)
0.200.1598 by Jelmer Vernooij
Print proper error when unknown fields are encountered.
196
0.413.2 by Jelmer Vernooij
Add support for the mergetag property in git.
197
    def test_mergetag(self):
198
        c = Commit()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
199
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
200
        c.message = b"Some message"
201
        c.committer = b"Committer"
0.413.2 by Jelmer Vernooij
Add support for the mergetag property in git.
202
        c.commit_time = 4
203
        c.author_time = 5
204
        c.commit_timezone = 60 * 5
205
        c.author_timezone = 60 * 3
6973.13.2 by Jelmer Vernooij
Fix some more tests.
206
        c.author = b"Author"
0.413.2 by Jelmer Vernooij
Add support for the mergetag property in git.
207
        tag = make_object(Tag,
7143.15.2 by Jelmer Vernooij
Run autopep8.
208
                          tagger=b'Jelmer Vernooij <jelmer@samba.org>',
209
                          name=b'0.1', message=None,
210
                          object=(
211
                              Blob, b'd80c186a03f423a81b39df39dc87fd269736ca86'),
212
                          tag_time=423423423, tag_timezone=0)
0.413.2 by Jelmer Vernooij
Add support for the mergetag property in git.
213
        c.mergetag = [tag]
214
        mapping = BzrGitMappingv1()
215
        rev, roundtrip_revid, verifiers = mapping.import_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
216
            c, mapping.revision_id_foreign_to_bzr)
217
        self.assertEqual(
218
            rev.properties[u'git-mergetag-0'], tag.as_raw_string())
0.413.2 by Jelmer Vernooij
Add support for the mergetag property in git.
219
7240.10.1 by Jelmer Vernooij
Properly handle exceptions about hg extra fields.
220
    def test_unknown_hg_fields(self):
221
        c = Commit()
222
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
223
        c.message = b"Some message"
224
        c.committer = b"Committer"
225
        c.commit_time = 4
226
        c.author_time = 5
227
        c.commit_timezone = 60 * 5
228
        c.author_timezone = 60 * 3
229
        c.author = b"Author"
230
        c._extra = [(b"HG:extra", b"bla:Foo")]
231
        mapping = BzrGitMappingv1()
232
        self.assertRaises(
233
            UnknownMercurialCommitExtra,
234
            mapping.import_commit, c, mapping.revision_id_foreign_to_bzr)
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
235
        mapping.import_commit(
236
            c, mapping.revision_id_foreign_to_bzr, strict=False)
7268.1.2 by Jelmer Vernooij
Allow access to native git repositories, ignoring unknown hg fields.
237
        self.assertEqual(
238
            mapping.revision_id_foreign_to_bzr(c.id),
239
            mapping.get_revision_id(c))
7240.10.1 by Jelmer Vernooij
Properly handle exceptions about hg extra fields.
240
7290.21.1 by Jelmer Vernooij
Cope with utf-8 invalid characters in commit messages when scanning for revision ids.
241
    def test_invalid_utf8(self):
242
        c = Commit()
243
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
244
        c.message = b"Some message \xc1"
245
        c.committer = b"Committer"
246
        c.commit_time = 4
247
        c.author_time = 5
248
        c.commit_timezone = 60 * 5
249
        c.author_timezone = 60 * 3
250
        c.author = b"Author"
251
        mapping = BzrGitMappingv1()
252
        self.assertEqual(
253
            mapping.revision_id_foreign_to_bzr(c.id),
254
            mapping.get_revision_id(c))
255
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
256
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
257
class RoundtripRevisionsFromBazaar(tests.TestCase):
258
259
    def setUp(self):
260
        super(RoundtripRevisionsFromBazaar, self).setUp()
261
        self.mapping = BzrGitMappingv1()
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
262
        self._parent_map = {}
263
        self._lookup_parent = self._parent_map.__getitem__
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
264
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
265
    def assertRoundtripRevision(self, orig_rev):
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
266
        commit = self.mapping.export_commit(orig_rev, b"mysha",
7143.15.2 by Jelmer Vernooij
Run autopep8.
267
                                            self._lookup_parent, True, b"testamentsha")
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
268
        rev, roundtrip_revid, verifiers = self.mapping.import_commit(
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
269
            commit, self.mapping.revision_id_foreign_to_bzr, strict=True)
6964.2.3 by Jelmer Vernooij
Review comments.
270
        self.assertEqual(rev.revision_id,
7143.15.2 by Jelmer Vernooij
Run autopep8.
271
                         self.mapping.revision_id_foreign_to_bzr(commit.id))
0.200.912 by Jelmer Vernooij
Merge roundtrip support.
272
        if self.mapping.roundtripping:
7143.15.2 by Jelmer Vernooij
Run autopep8.
273
            self.assertEqual({"testament3-sha1": b"testamentsha"}, verifiers)
6964.2.3 by Jelmer Vernooij
Review comments.
274
            self.assertEqual(orig_rev.revision_id, roundtrip_revid)
275
            self.assertEqual(orig_rev.properties, rev.properties)
276
            self.assertEqual(orig_rev.committer, rev.committer)
277
            self.assertEqual(orig_rev.timestamp, rev.timestamp)
278
            self.assertEqual(orig_rev.timezone, rev.timezone)
279
            self.assertEqual(orig_rev.message, rev.message)
280
            self.assertEqual(list(orig_rev.parent_ids), list(rev.parent_ids))
0.200.1023 by Jelmer Vernooij
Set and verify testament.
281
        else:
6964.2.3 by Jelmer Vernooij
Review comments.
282
            self.assertEqual({}, verifiers)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
283
284
    def test_simple_commit(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
285
        r = Revision(self.mapping.revision_id_foreign_to_bzr(
286
            b"edf99e6c56495c620f20d5dacff9859ff7119261"))
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
287
        r.message = "MyCommitMessage"
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
288
        r.parent_ids = []
289
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
290
        r.timestamp = 453543543
291
        r.timezone = 0
292
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
293
        self.assertRoundtripRevision(r)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
294
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
295
    def test_revision_id(self):
6973.13.2 by Jelmer Vernooij
Fix some more tests.
296
        r = Revision(b"myrevid")
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
297
        r.message = "MyCommitMessage"
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
298
        r.parent_ids = []
299
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
300
        r.timestamp = 453543543
301
        r.timezone = 0
302
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
303
        self.assertRoundtripRevision(r)
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
304
305
    def test_ghost_parent(self):
6973.13.2 by Jelmer Vernooij
Fix some more tests.
306
        r = Revision(b"myrevid")
307
        r.message = u"MyCommitMessage"
308
        r.parent_ids = [b"iamaghost"]
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
309
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
310
        r.timestamp = 453543543
311
        r.timezone = 0
312
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
313
        self.assertRoundtripRevision(r)
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
314
0.252.10 by Jelmer Vernooij
Support roundtripping custom revision properties.
315
    def test_custom_property(self):
6973.13.2 by Jelmer Vernooij
Fix some more tests.
316
        r = Revision(b"myrevid")
317
        r.message = u"MyCommitMessage"
0.252.10 by Jelmer Vernooij
Support roundtripping custom revision properties.
318
        r.parent_ids = []
6973.13.2 by Jelmer Vernooij
Fix some more tests.
319
        r.properties = {u"fool": "bar"}
0.252.10 by Jelmer Vernooij
Support roundtripping custom revision properties.
320
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
321
        r.timestamp = 453543543
322
        r.timezone = 0
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
323
        self.assertRoundtripRevision(r)
0.252.16 by Jelmer Vernooij
make sure file ids are roundtripped properly.
324
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
325
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
326
class RoundtripRevisionsFromGit(tests.TestCase):
327
328
    def setUp(self):
329
        super(RoundtripRevisionsFromGit, self).setUp()
330
        self.mapping = BzrGitMappingv1()
331
332
    def assertRoundtripTree(self, tree):
333
        raise NotImplementedError(self.assertRoundtripTree)
334
335
    def assertRoundtripBlob(self, blob):
336
        raise NotImplementedError(self.assertRoundtripBlob)
337
338
    def assertRoundtripCommit(self, commit1):
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
339
        rev, roundtrip_revid, verifiers = self.mapping.import_commit(
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
340
            commit1, self.mapping.revision_id_foreign_to_bzr, strict=True)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
341
        commit2 = self.mapping.export_commit(rev, "12341212121212", None,
7143.15.2 by Jelmer Vernooij
Run autopep8.
342
                                             True, None)
6964.2.3 by Jelmer Vernooij
Review comments.
343
        self.assertEqual(commit1.committer, commit2.committer)
344
        self.assertEqual(commit1.commit_time, commit2.commit_time)
345
        self.assertEqual(commit1.commit_timezone, commit2.commit_timezone)
346
        self.assertEqual(commit1.author, commit2.author)
347
        self.assertEqual(commit1.author_time, commit2.author_time)
348
        self.assertEqual(commit1.author_timezone, commit2.author_timezone)
349
        self.assertEqual(commit1.message, commit2.message)
350
        self.assertEqual(commit1.encoding, commit2.encoding)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
351
352
    def test_commit(self):
353
        c = Commit()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
354
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
355
        c.message = b"Some message"
356
        c.committer = b"Committer <Committer>"
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
357
        c.commit_time = 4
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
358
        c.commit_timezone = -60 * 3
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
359
        c.author_time = 5
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
360
        c.author_timezone = 60 * 2
6973.13.2 by Jelmer Vernooij
Fix some more tests.
361
        c.author = b"Author <author>"
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
362
        self.assertRoundtripCommit(c)
363
0.200.1589 by Jelmer Vernooij
Add test to make sure that certain invalid timezones are roundtripped correctly.
364
    def test_commit_double_negative_timezone(self):
365
        c = Commit()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
366
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
367
        c.message = b"Some message"
368
        c.committer = b"Committer <Committer>"
0.200.1589 by Jelmer Vernooij
Add test to make sure that certain invalid timezones are roundtripped correctly.
369
        c.commit_time = 4
7018.3.2 by Jelmer Vernooij
Fix some git tests.
370
        (c.commit_timezone, c._commit_timezone_neg_utc) = parse_timezone(b"--700")
0.200.1589 by Jelmer Vernooij
Add test to make sure that certain invalid timezones are roundtripped correctly.
371
        c.author_time = 5
372
        c.author_timezone = 60 * 2
6973.13.2 by Jelmer Vernooij
Fix some more tests.
373
        c.author = b"Author <author>"
0.200.1589 by Jelmer Vernooij
Add test to make sure that certain invalid timezones are roundtripped correctly.
374
        self.assertRoundtripCommit(c)
375
0.200.884 by Jelmer Vernooij
Cope with -0000 as timezone in Git commits.
376
    def test_commit_zero_utc_timezone(self):
377
        c = Commit()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
378
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
379
        c.message = b"Some message"
380
        c.committer = b"Committer <Committer>"
0.200.884 by Jelmer Vernooij
Cope with -0000 as timezone in Git commits.
381
        c.commit_time = 4
382
        c.commit_timezone = 0
383
        c._commit_timezone_neg_utc = True
384
        c.author_time = 5
385
        c.author_timezone = 60 * 2
6973.13.2 by Jelmer Vernooij
Fix some more tests.
386
        c.author = b"Author <author>"
0.200.884 by Jelmer Vernooij
Cope with -0000 as timezone in Git commits.
387
        self.assertRoundtripCommit(c)
388
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
389
    def test_commit_encoding(self):
390
        c = Commit()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
391
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
392
        c.message = b"Some message"
393
        c.committer = b"Committer <Committer>"
394
        c.encoding = b'iso8859-1'
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
395
        c.commit_time = 4
396
        c.commit_timezone = -60 * 3
397
        c.author_time = 5
398
        c.author_timezone = 60 * 2
6973.13.2 by Jelmer Vernooij
Fix some more tests.
399
        c.author = b"Author <author>"
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
400
        self.assertRoundtripCommit(c)
401
0.200.1639 by Jelmer Vernooij
Properly roundtrip HG:rename-source fields.
402
    def test_commit_extra(self):
403
        c = Commit()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
404
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
405
        c.message = b"Some message"
406
        c.committer = b"Committer <Committer>"
0.200.1639 by Jelmer Vernooij
Properly roundtrip HG:rename-source fields.
407
        c.commit_time = 4
408
        c.commit_timezone = -60 * 3
409
        c.author_time = 5
410
        c.author_timezone = 60 * 2
6973.13.2 by Jelmer Vernooij
Fix some more tests.
411
        c.author = b"Author <author>"
412
        c._extra = [(b"HG:rename-source", b"hg")]
0.200.1639 by Jelmer Vernooij
Properly roundtrip HG:rename-source fields.
413
        self.assertRoundtripCommit(c)
414
0.414.2 by Jelmer Vernooij
Fix mergetag roundtripping.
415
    def test_commit_mergetag(self):
416
        c = Commit()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
417
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
418
        c.message = b"Some message"
419
        c.committer = b"Committer <Committer>"
0.414.2 by Jelmer Vernooij
Fix mergetag roundtripping.
420
        c.commit_time = 4
421
        c.commit_timezone = -60 * 3
422
        c.author_time = 5
423
        c.author_timezone = 60 * 2
6973.13.2 by Jelmer Vernooij
Fix some more tests.
424
        c.author = b"Author <author>"
0.414.2 by Jelmer Vernooij
Fix mergetag roundtripping.
425
        tag = make_object(Tag,
7143.15.2 by Jelmer Vernooij
Run autopep8.
426
                          tagger=b'Jelmer Vernooij <jelmer@samba.org>',
427
                          name=b'0.1', message=None,
428
                          object=(
429
                              Blob, b'd80c186a03f423a81b39df39dc87fd269736ca86'),
430
                          tag_time=423423423, tag_timezone=0)
0.414.2 by Jelmer Vernooij
Fix mergetag roundtripping.
431
        c.mergetag = [tag]
432
        self.assertRoundtripCommit(c)
433
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
434
0.402.1 by Jelmer Vernooij
Improve identifier handling.
435
class FixPersonIdentifierTests(tests.TestCase):
436
437
    def test_valid(self):
6973.13.2 by Jelmer Vernooij
Fix some more tests.
438
        self.assertEqual(b"foo <bar@blah.nl>",
439
                         fix_person_identifier(b"foo <bar@blah.nl>"))
440
        self.assertEqual(b"bar@blah.nl <bar@blah.nl>",
441
                         fix_person_identifier(b"bar@blah.nl"))
0.402.1 by Jelmer Vernooij
Improve identifier handling.
442
443
    def test_fix(self):
7490.41.1 by Jelmer Vernooij
Fix handling of a particular kind of broken committer id.
444
        self.assertEqual(
445
            b"person <bar@blah.nl>",
446
            fix_person_identifier(b"somebody <person <bar@blah.nl>>"))
447
        self.assertEqual(
448
            b"person <bar@blah.nl>",
449
            fix_person_identifier(b"person<bar@blah.nl>"))
450
        self.assertEqual(
451
            b'Rohan Garg <rohangarg@kubuntu.org>',
452
            fix_person_identifier(b'Rohan Garg <rohangarg@kubuntu.org'))
0.402.1 by Jelmer Vernooij
Improve identifier handling.
453
        self.assertRaises(ValueError,
7143.15.2 by Jelmer Vernooij
Run autopep8.
454
                          fix_person_identifier, b"person >bar@blah.nl<")