/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
20
from __future__ import absolute_import
21
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
22
from ....bzr.inventory import (
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
23
    InventoryDirectory,
24
    InventoryFile,
25
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
26
from ....revision import (
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
27
    Revision,
28
    )
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
29
0.200.264 by Jelmer Vernooij
Add more tests.
30
from dulwich.objects import (
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
31
    Blob,
0.200.264 by Jelmer Vernooij
Add more tests.
32
    Commit,
0.413.2 by Jelmer Vernooij
Add support for the mergetag property in git.
33
    Tag,
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
34
    Tree,
0.200.1589 by Jelmer Vernooij
Add test to make sure that certain invalid timezones are roundtripped correctly.
35
    parse_timezone,
0.200.264 by Jelmer Vernooij
Add more tests.
36
    )
0.413.2 by Jelmer Vernooij
Add support for the mergetag property in git.
37
from dulwich.tests.utils import (
38
    make_object,
39
    )
0.200.264 by Jelmer Vernooij
Add more tests.
40
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
41
from .. import tests
42
from ..errors import UnknownCommitExtra
43
from ..mapping import (
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
44
    BzrGitMappingv1,
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
45
    directory_to_tree,
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
46
    escape_file_id,
0.402.1 by Jelmer Vernooij
Improve identifier handling.
47
    fix_person_identifier,
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
48
    unescape_file_id,
49
    )
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
50
51
52
class TestRevidConversionV1(tests.TestCase):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
53
54
    def test_simple_git_to_bzr_revision_id(self):
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
55
        self.assertEqual("git-v1:"
0.204.1 by James Westby
Fix id tests to match new revid prefix.
56
                         "c6a4d8f1fa4ac650748e647c4b1b368f589a7356",
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
57
                         BzrGitMappingv1().revision_id_foreign_to_bzr(
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
58
                            "c6a4d8f1fa4ac650748e647c4b1b368f589a7356"))
59
60
    def test_simple_bzr_to_git_revision_id(self):
0.200.195 by Jelmer Vernooij
Return mapping in revision_id_bzr_to_foreign() as required by the interface.
61
        self.assertEqual(("c6a4d8f1fa4ac650748e647c4b1b368f589a7356", 
62
                         BzrGitMappingv1()),
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
63
                         BzrGitMappingv1().revision_id_bzr_to_foreign(
64
                            "git-v1:"
0.204.1 by James Westby
Fix id tests to match new revid prefix.
65
                            "c6a4d8f1fa4ac650748e647c4b1b368f589a7356"))
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
66
0.252.26 by Jelmer Vernooij
Add is_control_file method to BzrGitMapping.
67
    def test_is_control_file(self):
68
        mapping = BzrGitMappingv1()
0.200.920 by Jelmer Vernooij
Fix some more tests.
69
        if mapping.roundtripping:
0.200.1752 by Jelmer Vernooij
Don't traverse nested trees in WorkingTree.smart_add.
70
            self.assertTrue(mapping.is_special_file(".bzrdummy"))
71
            self.assertTrue(mapping.is_special_file(".bzrfileids"))
72
        self.assertFalse(mapping.is_special_file(".bzrfoo"))
0.252.26 by Jelmer Vernooij
Add is_control_file method to BzrGitMapping.
73
0.200.973 by Jelmer Vernooij
Add tests for generate_file_id.
74
    def test_generate_file_id(self):
75
        mapping = BzrGitMappingv1()
76
        self.assertIsInstance(mapping.generate_file_id("la"), str)
77
        self.assertIsInstance(mapping.generate_file_id(u"é"), str)
78
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
79
80
class FileidTests(tests.TestCase):
81
82
    def test_escape_space(self):
83
        self.assertEquals("bla_s", escape_file_id("bla "))
84
0.200.1419 by Jelmer Vernooij
Escape/unescape ^L characters.
85
    def test_escape_control_l(self):
86
        self.assertEquals("bla_c", escape_file_id("bla\x0c"))
87
88
    def test_unescape_control_l(self):
89
        self.assertEquals("bla\x0c", unescape_file_id("bla_c"))
90
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
91
    def test_escape_underscore(self):
92
        self.assertEquals("bla__", escape_file_id("bla_"))
93
94
    def test_escape_underscore_space(self):
95
        self.assertEquals("bla___s", escape_file_id("bla_ "))
96
97
    def test_unescape_underscore(self):
98
        self.assertEquals("bla ", unescape_file_id("bla_s"))
99
100
    def test_unescape_underscore_space(self):
101
        self.assertEquals("bla _", unescape_file_id("bla_s__"))
0.200.264 by Jelmer Vernooij
Add more tests.
102
103
104
class TestImportCommit(tests.TestCase):
105
106
    def test_commit(self):
107
        c = Commit()
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
108
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
109
        c.message = "Some message"
110
        c.committer = "Committer"
111
        c.commit_time = 4
112
        c.author_time = 5
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
113
        c.commit_timezone = 60 * 5
114
        c.author_timezone = 60 * 3
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
115
        c.author = "Author"
0.252.44 by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped.
116
        mapping = BzrGitMappingv1()
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
117
        rev, roundtrip_revid, verifiers = mapping.import_commit(c,
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
118
            mapping.revision_id_foreign_to_bzr)
119
        self.assertEquals(None, roundtrip_revid)
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
120
        self.assertEquals({}, verifiers)
0.200.264 by Jelmer Vernooij
Add more tests.
121
        self.assertEquals("Some message", rev.message)
122
        self.assertEquals("Committer", rev.committer)
123
        self.assertEquals("Author", rev.properties['author'])
0.200.368 by Jelmer Vernooij
Cope with more granular timezones.
124
        self.assertEquals(300, rev.timezone)
0.200.264 by Jelmer Vernooij
Add more tests.
125
        self.assertEquals((), rev.parent_ids)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
126
        self.assertEquals("5", rev.properties['author-timestamp'])
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
127
        self.assertEquals("180", rev.properties['author-timezone'])
0.200.264 by Jelmer Vernooij
Add more tests.
128
        self.assertEquals("git-v1:" + c.id, rev.revision_id)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
129
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
130
    def test_explicit_encoding(self):
131
        c = Commit()
132
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
133
        c.message = "Some message"
134
        c.committer = "Committer"
135
        c.commit_time = 4
136
        c.author_time = 5
137
        c.commit_timezone = 60 * 5
138
        c.author_timezone = 60 * 3
139
        c.author = u"Authér".encode("iso8859-1")
140
        c.encoding = "iso8859-1"
0.252.44 by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped.
141
        mapping = BzrGitMappingv1()
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
142
        rev, roundtrip_revid, verifiers = mapping.import_commit(c,
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
143
            mapping.revision_id_foreign_to_bzr)
144
        self.assertEquals(None, roundtrip_revid)
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
145
        self.assertEquals({}, verifiers)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
146
        self.assertEquals(u"Authér", rev.properties['author'])
147
        self.assertEquals("iso8859-1", rev.properties["git-explicit-encoding"])
148
        self.assertTrue("git-implicit-encoding" not in rev.properties)
149
150
    def test_implicit_encoding_fallback(self):
151
        c = Commit()
152
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
153
        c.message = "Some message"
154
        c.committer = "Committer"
155
        c.commit_time = 4
156
        c.author_time = 5
157
        c.commit_timezone = 60 * 5
158
        c.author_timezone = 60 * 3
159
        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.
160
        mapping = BzrGitMappingv1()
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
161
        rev, roundtrip_revid, verifiers = mapping.import_commit(c,
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
162
            mapping.revision_id_foreign_to_bzr)
163
        self.assertEquals(None, roundtrip_revid)
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
164
        self.assertEquals({}, verifiers)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
165
        self.assertEquals(u"Authér", rev.properties['author'])
166
        self.assertEquals("latin1", rev.properties["git-implicit-encoding"])
167
        self.assertTrue("git-explicit-encoding" not in rev.properties)
168
169
    def test_implicit_encoding_utf8(self):
170
        c = Commit()
171
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
172
        c.message = "Some message"
173
        c.committer = "Committer"
174
        c.commit_time = 4
175
        c.author_time = 5
176
        c.commit_timezone = 60 * 5
177
        c.author_timezone = 60 * 3
178
        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.
179
        mapping = BzrGitMappingv1()
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
180
        rev, roundtrip_revid, verifiers = mapping.import_commit(c,
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
181
            mapping.revision_id_foreign_to_bzr)
182
        self.assertEquals(None, roundtrip_revid)
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
183
        self.assertEquals({}, verifiers)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
184
        self.assertEquals(u"Authér", rev.properties['author'])
185
        self.assertTrue("git-explicit-encoding" not in rev.properties)
186
        self.assertTrue("git-implicit-encoding" not in rev.properties)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
187
0.200.1598 by Jelmer Vernooij
Print proper error when unknown fields are encountered.
188
    def test_unknown_extra(self):
189
        c = Commit()
190
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
191
        c.message = "Some message"
192
        c.committer = "Committer"
193
        c.commit_time = 4
194
        c.author_time = 5
195
        c.commit_timezone = 60 * 5
196
        c.author_timezone = 60 * 3
197
        c.author = "Author"
0.200.1639 by Jelmer Vernooij
Properly roundtrip HG:rename-source fields.
198
        c._extra.append(("iamextra", "foo"))
0.200.1598 by Jelmer Vernooij
Print proper error when unknown fields are encountered.
199
        mapping = BzrGitMappingv1()
200
        self.assertRaises(UnknownCommitExtra, mapping.import_commit, c,
201
            mapping.revision_id_foreign_to_bzr)
202
0.413.2 by Jelmer Vernooij
Add support for the mergetag property in git.
203
    def test_mergetag(self):
204
        c = Commit()
205
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
206
        c.message = "Some message"
207
        c.committer = "Committer"
208
        c.commit_time = 4
209
        c.author_time = 5
210
        c.commit_timezone = 60 * 5
211
        c.author_timezone = 60 * 3
212
        c.author = "Author"
213
        tag = make_object(Tag,
214
                tagger=b'Jelmer Vernooij <jelmer@samba.org>',
215
                name=b'0.1', message=None,
216
                object=(Blob, b'd80c186a03f423a81b39df39dc87fd269736ca86'),
217
                tag_time=423423423, tag_timezone=0)
218
        c.mergetag = [tag]
219
        mapping = BzrGitMappingv1()
220
        rev, roundtrip_revid, verifiers = mapping.import_commit(
221
                c, mapping.revision_id_foreign_to_bzr)
222
        self.assertEqual(rev.properties['git-mergetag-0'], tag.as_raw_string())
223
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
224
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
225
class RoundtripRevisionsFromBazaar(tests.TestCase):
226
227
    def setUp(self):
228
        super(RoundtripRevisionsFromBazaar, self).setUp()
229
        self.mapping = BzrGitMappingv1()
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
230
        self._parent_map = {}
231
        self._lookup_parent = self._parent_map.__getitem__
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
232
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
233
    def assertRoundtripRevision(self, orig_rev):
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
234
        commit = self.mapping.export_commit(orig_rev, "mysha",
0.200.1023 by Jelmer Vernooij
Set and verify testament.
235
            self._lookup_parent, True, "testamentsha")
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
236
        rev, roundtrip_revid, verifiers = self.mapping.import_commit(
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
237
            commit, self.mapping.revision_id_foreign_to_bzr)
238
        self.assertEquals(rev.revision_id,
239
            self.mapping.revision_id_foreign_to_bzr(commit.id))
0.200.912 by Jelmer Vernooij
Merge roundtrip support.
240
        if self.mapping.roundtripping:
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
241
            self.assertEquals({"testament3-sha1": "testamentsha"} , verifiers)
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
242
            self.assertEquals(orig_rev.revision_id, roundtrip_revid)
0.200.912 by Jelmer Vernooij
Merge roundtrip support.
243
            self.assertEquals(orig_rev.properties, rev.properties)
244
            self.assertEquals(orig_rev.committer, rev.committer)
245
            self.assertEquals(orig_rev.timestamp, rev.timestamp)
246
            self.assertEquals(orig_rev.timezone, rev.timezone)
247
            self.assertEquals(orig_rev.message, rev.message)
248
            self.assertEquals(list(orig_rev.parent_ids), list(rev.parent_ids))
0.200.1023 by Jelmer Vernooij
Set and verify testament.
249
        else:
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
250
            self.assertEquals({}, verifiers)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
251
252
    def test_simple_commit(self):
253
        r = Revision(self.mapping.revision_id_foreign_to_bzr("edf99e6c56495c620f20d5dacff9859ff7119261"))
254
        r.message = "MyCommitMessage"
255
        r.parent_ids = []
256
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
257
        r.timestamp = 453543543
258
        r.timezone = 0
259
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
260
        self.assertRoundtripRevision(r)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
261
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
262
    def test_revision_id(self):
263
        r = Revision("myrevid")
264
        r.message = "MyCommitMessage"
265
        r.parent_ids = []
266
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
267
        r.timestamp = 453543543
268
        r.timezone = 0
269
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
270
        self.assertRoundtripRevision(r)
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
271
272
    def test_ghost_parent(self):
273
        r = Revision("myrevid")
274
        r.message = "MyCommitMessage"
275
        r.parent_ids = ["iamaghost"]
276
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
277
        r.timestamp = 453543543
278
        r.timezone = 0
279
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
280
        self.assertRoundtripRevision(r)
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
281
0.252.10 by Jelmer Vernooij
Support roundtripping custom revision properties.
282
    def test_custom_property(self):
283
        r = Revision("myrevid")
284
        r.message = "MyCommitMessage"
285
        r.parent_ids = []
286
        r.properties = {"fool": "bar"}
287
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
288
        r.timestamp = 453543543
289
        r.timezone = 0
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
290
        self.assertRoundtripRevision(r)
0.252.16 by Jelmer Vernooij
make sure file ids are roundtripped properly.
291
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
292
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
293
class RoundtripRevisionsFromGit(tests.TestCase):
294
295
    def setUp(self):
296
        super(RoundtripRevisionsFromGit, self).setUp()
297
        self.mapping = BzrGitMappingv1()
298
299
    def assertRoundtripTree(self, tree):
300
        raise NotImplementedError(self.assertRoundtripTree)
301
302
    def assertRoundtripBlob(self, blob):
303
        raise NotImplementedError(self.assertRoundtripBlob)
304
305
    def assertRoundtripCommit(self, commit1):
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
306
        rev, roundtrip_revid, verifiers = self.mapping.import_commit(
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
307
            commit1, self.mapping.revision_id_foreign_to_bzr)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
308
        commit2 = self.mapping.export_commit(rev, "12341212121212", None,
0.200.1023 by Jelmer Vernooij
Set and verify testament.
309
            True, None)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
310
        self.assertEquals(commit1.committer, commit2.committer)
311
        self.assertEquals(commit1.commit_time, commit2.commit_time)
0.200.362 by Jelmer Vernooij
Fix tests.
312
        self.assertEquals(commit1.commit_timezone, commit2.commit_timezone)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
313
        self.assertEquals(commit1.author, commit2.author)
314
        self.assertEquals(commit1.author_time, commit2.author_time)
0.200.362 by Jelmer Vernooij
Fix tests.
315
        self.assertEquals(commit1.author_timezone, commit2.author_timezone)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
316
        self.assertEquals(commit1.message, commit2.message)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
317
        self.assertEquals(commit1.encoding, commit2.encoding)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
318
319
    def test_commit(self):
320
        c = Commit()
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
321
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
322
        c.message = "Some message"
323
        c.committer = "Committer <Committer>"
324
        c.commit_time = 4
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
325
        c.commit_timezone = -60 * 3
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
326
        c.author_time = 5
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
327
        c.author_timezone = 60 * 2
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
328
        c.author = "Author <author>"
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
329
        self.assertRoundtripCommit(c)
330
0.200.1589 by Jelmer Vernooij
Add test to make sure that certain invalid timezones are roundtripped correctly.
331
    def test_commit_double_negative_timezone(self):
332
        c = Commit()
333
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
334
        c.message = "Some message"
335
        c.committer = "Committer <Committer>"
336
        c.commit_time = 4
337
        (c.commit_timezone, c._commit_timezone_neg_utc) = parse_timezone("--700")
338
        c.author_time = 5
339
        c.author_timezone = 60 * 2
340
        c.author = "Author <author>"
341
        self.assertRoundtripCommit(c)
342
0.200.884 by Jelmer Vernooij
Cope with -0000 as timezone in Git commits.
343
    def test_commit_zero_utc_timezone(self):
344
        c = Commit()
345
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
346
        c.message = "Some message"
347
        c.committer = "Committer <Committer>"
348
        c.commit_time = 4
349
        c.commit_timezone = 0
350
        c._commit_timezone_neg_utc = True
351
        c.author_time = 5
352
        c.author_timezone = 60 * 2
353
        c.author = "Author <author>"
354
        self.assertRoundtripCommit(c)
355
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
356
    def test_commit_encoding(self):
357
        c = Commit()
358
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
359
        c.message = "Some message"
360
        c.committer = "Committer <Committer>"
361
        c.encoding = 'iso8859-1'
362
        c.commit_time = 4
363
        c.commit_timezone = -60 * 3
364
        c.author_time = 5
365
        c.author_timezone = 60 * 2
366
        c.author = "Author <author>"
367
        self.assertRoundtripCommit(c)
368
0.200.1639 by Jelmer Vernooij
Properly roundtrip HG:rename-source fields.
369
    def test_commit_extra(self):
370
        c = Commit()
371
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
372
        c.message = "Some message"
373
        c.committer = "Committer <Committer>"
374
        c.commit_time = 4
375
        c.commit_timezone = -60 * 3
376
        c.author_time = 5
377
        c.author_timezone = 60 * 2
378
        c.author = "Author <author>"
379
        c._extra = [("HG:rename-source", "hg")]
380
        self.assertRoundtripCommit(c)
381
0.414.2 by Jelmer Vernooij
Fix mergetag roundtripping.
382
    def test_commit_mergetag(self):
383
        c = Commit()
384
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
385
        c.message = "Some message"
386
        c.committer = "Committer <Committer>"
387
        c.commit_time = 4
388
        c.commit_timezone = -60 * 3
389
        c.author_time = 5
390
        c.author_timezone = 60 * 2
391
        c.author = "Author <author>"
392
        tag = make_object(Tag,
393
                tagger=b'Jelmer Vernooij <jelmer@samba.org>',
394
                name=b'0.1', message=None,
395
                object=(Blob, b'd80c186a03f423a81b39df39dc87fd269736ca86'),
396
                tag_time=423423423, tag_timezone=0)
397
        c.mergetag = [tag]
398
        self.assertRoundtripCommit(c)
399
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
400
401
class DirectoryToTreeTests(tests.TestCase):
402
403
    def test_empty(self):
0.275.4 by Jelmer Vernooij
Pass children list to directory_to_tree .
404
        t = directory_to_tree({}, None, {}, None, allow_empty=False)
0.200.589 by Jelmer Vernooij
Fix handling of empty trees.
405
        self.assertEquals(None, t)
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
406
407
    def test_empty_dir(self):
408
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
0.275.4 by Jelmer Vernooij
Pass children list to directory_to_tree .
409
        children = {'bar': child_ie}
410
        t = directory_to_tree(children, lambda x: None, {}, None,
411
                allow_empty=False)
0.200.589 by Jelmer Vernooij
Fix handling of empty trees.
412
        self.assertEquals(None, t)
413
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
414
    def test_empty_dir_dummy_files(self):
415
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
0.275.4 by Jelmer Vernooij
Pass children list to directory_to_tree .
416
        children = {'bar':child_ie}
417
        t = directory_to_tree(children, lambda x: None, {}, ".mydummy",
418
                allow_empty=False)
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
419
        self.assertTrue(".mydummy" in t)
420
0.200.589 by Jelmer Vernooij
Fix handling of empty trees.
421
    def test_empty_root(self):
422
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
0.275.4 by Jelmer Vernooij
Pass children list to directory_to_tree .
423
        children = {'bar': child_ie}
424
        t = directory_to_tree(children, lambda x: None, {}, None,
425
                allow_empty=True)
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
426
        self.assertEquals(Tree(), t)
427
428
    def test_with_file(self):
429
        child_ie = InventoryFile('bar', 'bar', 'bar')
0.275.4 by Jelmer Vernooij
Pass children list to directory_to_tree .
430
        children = {"bar": child_ie}
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
431
        b = Blob.from_string("bla")
0.275.4 by Jelmer Vernooij
Pass children list to directory_to_tree .
432
        t1 = directory_to_tree(children, lambda x: b.id, {}, None,
433
                allow_empty=False)
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
434
        t2 = Tree()
0.200.1152 by Jelmer Vernooij
Require dulwich 0.7.1.
435
        t2.add("bar", 0100644, b.id)
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
436
        self.assertEquals(t1, t2)
0.402.1 by Jelmer Vernooij
Improve identifier handling.
437
438
439
class FixPersonIdentifierTests(tests.TestCase):
440
441
    def test_valid(self):
442
        self.assertEqual("foo <bar@blah.nl>",
443
                         fix_person_identifier("foo <bar@blah.nl>"))
444
        self.assertEqual("bar@blah.nl <bar@blah.nl>",
445
                         fix_person_identifier("bar@blah.nl"))
446
447
    def test_fix(self):
448
        self.assertEqual("person <bar@blah.nl>",
449
                         fix_person_identifier("somebody <person <bar@blah.nl>>"))
450
        self.assertEqual("person <bar@blah.nl>",
451
                         fix_person_identifier("person<bar@blah.nl>"))
452
        self.assertRaises(ValueError,
453
                         fix_person_identifier, "person >bar@blah.nl<")