/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.51 by Jelmer Vernooij
Fix copyright.
1
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
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
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
18
from bzrlib.inventory import (
19
    InventoryDirectory,
20
    InventoryFile,
21
    )
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
22
from bzrlib.revision import (
23
    Revision,
24
    )
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
25
0.200.264 by Jelmer Vernooij
Add more tests.
26
from dulwich.objects import (
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
27
    Blob,
0.200.264 by Jelmer Vernooij
Add more tests.
28
    Commit,
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
29
    Tree,
0.200.264 by Jelmer Vernooij
Add more tests.
30
    )
31
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
32
from bzrlib.plugins.git import tests
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
33
from bzrlib.plugins.git.mapping import (
34
    BzrGitMappingv1,
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
35
    directory_to_tree,
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
36
    escape_file_id,
37
    unescape_file_id,
38
    )
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
39
40
41
class TestRevidConversionV1(tests.TestCase):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
42
43
    def test_simple_git_to_bzr_revision_id(self):
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
44
        self.assertEqual("git-v1:"
0.204.1 by James Westby
Fix id tests to match new revid prefix.
45
                         "c6a4d8f1fa4ac650748e647c4b1b368f589a7356",
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
46
                         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.
47
                            "c6a4d8f1fa4ac650748e647c4b1b368f589a7356"))
48
49
    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.
50
        self.assertEqual(("c6a4d8f1fa4ac650748e647c4b1b368f589a7356", 
51
                         BzrGitMappingv1()),
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
52
                         BzrGitMappingv1().revision_id_bzr_to_foreign(
53
                            "git-v1:"
0.204.1 by James Westby
Fix id tests to match new revid prefix.
54
                            "c6a4d8f1fa4ac650748e647c4b1b368f589a7356"))
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
55
0.252.26 by Jelmer Vernooij
Add is_control_file method to BzrGitMapping.
56
    def test_is_control_file(self):
57
        mapping = BzrGitMappingv1()
0.200.920 by Jelmer Vernooij
Fix some more tests.
58
        if mapping.roundtripping:
59
            self.assertTrue(mapping.is_control_file(".bzrdummy"))
60
            self.assertTrue(mapping.is_control_file(".bzrfileids"))
0.252.26 by Jelmer Vernooij
Add is_control_file method to BzrGitMapping.
61
        self.assertFalse(mapping.is_control_file(".bzrfoo"))
62
0.200.973 by Jelmer Vernooij
Add tests for generate_file_id.
63
    def test_generate_file_id(self):
64
        mapping = BzrGitMappingv1()
65
        self.assertIsInstance(mapping.generate_file_id("la"), str)
66
        self.assertIsInstance(mapping.generate_file_id(u"é"), str)
67
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
68
69
class FileidTests(tests.TestCase):
70
71
    def test_escape_space(self):
72
        self.assertEquals("bla_s", escape_file_id("bla "))
73
0.200.1419 by Jelmer Vernooij
Escape/unescape ^L characters.
74
    def test_escape_control_l(self):
75
        self.assertEquals("bla_c", escape_file_id("bla\x0c"))
76
77
    def test_unescape_control_l(self):
78
        self.assertEquals("bla\x0c", unescape_file_id("bla_c"))
79
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
80
    def test_escape_underscore(self):
81
        self.assertEquals("bla__", escape_file_id("bla_"))
82
83
    def test_escape_underscore_space(self):
84
        self.assertEquals("bla___s", escape_file_id("bla_ "))
85
86
    def test_unescape_underscore(self):
87
        self.assertEquals("bla ", unescape_file_id("bla_s"))
88
89
    def test_unescape_underscore_space(self):
90
        self.assertEquals("bla _", unescape_file_id("bla_s__"))
0.200.264 by Jelmer Vernooij
Add more tests.
91
92
93
class TestImportCommit(tests.TestCase):
94
95
    def test_commit(self):
96
        c = Commit()
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
97
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
98
        c.message = "Some message"
99
        c.committer = "Committer"
100
        c.commit_time = 4
101
        c.author_time = 5
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
102
        c.commit_timezone = 60 * 5
103
        c.author_timezone = 60 * 3
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
104
        c.author = "Author"
0.252.44 by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped.
105
        mapping = BzrGitMappingv1()
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
106
        rev, roundtrip_revid, verifiers = mapping.import_commit(c,
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
107
            mapping.revision_id_foreign_to_bzr)
108
        self.assertEquals(None, roundtrip_revid)
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
109
        self.assertEquals({}, verifiers)
0.200.264 by Jelmer Vernooij
Add more tests.
110
        self.assertEquals("Some message", rev.message)
111
        self.assertEquals("Committer", rev.committer)
112
        self.assertEquals("Author", rev.properties['author'])
0.200.368 by Jelmer Vernooij
Cope with more granular timezones.
113
        self.assertEquals(300, rev.timezone)
0.200.264 by Jelmer Vernooij
Add more tests.
114
        self.assertEquals((), rev.parent_ids)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
115
        self.assertEquals("5", rev.properties['author-timestamp'])
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
116
        self.assertEquals("180", rev.properties['author-timezone'])
0.200.264 by Jelmer Vernooij
Add more tests.
117
        self.assertEquals("git-v1:" + c.id, rev.revision_id)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
118
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
119
    def test_explicit_encoding(self):
120
        c = Commit()
121
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
122
        c.message = "Some message"
123
        c.committer = "Committer"
124
        c.commit_time = 4
125
        c.author_time = 5
126
        c.commit_timezone = 60 * 5
127
        c.author_timezone = 60 * 3
128
        c.author = u"Authér".encode("iso8859-1")
129
        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.
130
        mapping = BzrGitMappingv1()
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
131
        rev, roundtrip_revid, verifiers = mapping.import_commit(c,
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
132
            mapping.revision_id_foreign_to_bzr)
133
        self.assertEquals(None, roundtrip_revid)
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
134
        self.assertEquals({}, verifiers)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
135
        self.assertEquals(u"Authér", rev.properties['author'])
136
        self.assertEquals("iso8859-1", rev.properties["git-explicit-encoding"])
137
        self.assertTrue("git-implicit-encoding" not in rev.properties)
138
139
    def test_implicit_encoding_fallback(self):
140
        c = Commit()
141
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
142
        c.message = "Some message"
143
        c.committer = "Committer"
144
        c.commit_time = 4
145
        c.author_time = 5
146
        c.commit_timezone = 60 * 5
147
        c.author_timezone = 60 * 3
148
        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.
149
        mapping = BzrGitMappingv1()
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
150
        rev, roundtrip_revid, verifiers = mapping.import_commit(c,
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
151
            mapping.revision_id_foreign_to_bzr)
152
        self.assertEquals(None, roundtrip_revid)
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
153
        self.assertEquals({}, verifiers)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
154
        self.assertEquals(u"Authér", rev.properties['author'])
155
        self.assertEquals("latin1", rev.properties["git-implicit-encoding"])
156
        self.assertTrue("git-explicit-encoding" not in rev.properties)
157
158
    def test_implicit_encoding_utf8(self):
159
        c = Commit()
160
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
161
        c.message = "Some message"
162
        c.committer = "Committer"
163
        c.commit_time = 4
164
        c.author_time = 5
165
        c.commit_timezone = 60 * 5
166
        c.author_timezone = 60 * 3
167
        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.
168
        mapping = BzrGitMappingv1()
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
169
        rev, roundtrip_revid, verifiers = mapping.import_commit(c,
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
170
            mapping.revision_id_foreign_to_bzr)
171
        self.assertEquals(None, roundtrip_revid)
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
172
        self.assertEquals({}, verifiers)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
173
        self.assertEquals(u"Authér", rev.properties['author'])
174
        self.assertTrue("git-explicit-encoding" not in rev.properties)
175
        self.assertTrue("git-implicit-encoding" not in rev.properties)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
176
177
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
178
class RoundtripRevisionsFromBazaar(tests.TestCase):
179
180
    def setUp(self):
181
        super(RoundtripRevisionsFromBazaar, self).setUp()
182
        self.mapping = BzrGitMappingv1()
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
183
        self._parent_map = {}
184
        self._lookup_parent = self._parent_map.__getitem__
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
185
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
186
    def assertRoundtripRevision(self, orig_rev):
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
187
        commit = self.mapping.export_commit(orig_rev, "mysha",
0.200.1023 by Jelmer Vernooij
Set and verify testament.
188
            self._lookup_parent, True, "testamentsha")
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
189
        rev, roundtrip_revid, verifiers = self.mapping.import_commit(
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
190
            commit, self.mapping.revision_id_foreign_to_bzr)
191
        self.assertEquals(rev.revision_id,
192
            self.mapping.revision_id_foreign_to_bzr(commit.id))
0.200.912 by Jelmer Vernooij
Merge roundtrip support.
193
        if self.mapping.roundtripping:
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
194
            self.assertEquals({"testament3-sha1": "testamentsha"} , verifiers)
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
195
            self.assertEquals(orig_rev.revision_id, roundtrip_revid)
0.200.912 by Jelmer Vernooij
Merge roundtrip support.
196
            self.assertEquals(orig_rev.properties, rev.properties)
197
            self.assertEquals(orig_rev.committer, rev.committer)
198
            self.assertEquals(orig_rev.timestamp, rev.timestamp)
199
            self.assertEquals(orig_rev.timezone, rev.timezone)
200
            self.assertEquals(orig_rev.message, rev.message)
201
            self.assertEquals(list(orig_rev.parent_ids), list(rev.parent_ids))
0.200.1023 by Jelmer Vernooij
Set and verify testament.
202
        else:
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
203
            self.assertEquals({}, verifiers)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
204
205
    def test_simple_commit(self):
206
        r = Revision(self.mapping.revision_id_foreign_to_bzr("edf99e6c56495c620f20d5dacff9859ff7119261"))
207
        r.message = "MyCommitMessage"
208
        r.parent_ids = []
209
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
210
        r.timestamp = 453543543
211
        r.timezone = 0
212
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
213
        self.assertRoundtripRevision(r)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
214
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
215
    def test_revision_id(self):
216
        r = Revision("myrevid")
217
        r.message = "MyCommitMessage"
218
        r.parent_ids = []
219
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
220
        r.timestamp = 453543543
221
        r.timezone = 0
222
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
223
        self.assertRoundtripRevision(r)
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
224
225
    def test_ghost_parent(self):
226
        r = Revision("myrevid")
227
        r.message = "MyCommitMessage"
228
        r.parent_ids = ["iamaghost"]
229
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
230
        r.timestamp = 453543543
231
        r.timezone = 0
232
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
233
        self.assertRoundtripRevision(r)
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
234
0.252.10 by Jelmer Vernooij
Support roundtripping custom revision properties.
235
    def test_custom_property(self):
236
        r = Revision("myrevid")
237
        r.message = "MyCommitMessage"
238
        r.parent_ids = []
239
        r.properties = {"fool": "bar"}
240
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
241
        r.timestamp = 453543543
242
        r.timezone = 0
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
243
        self.assertRoundtripRevision(r)
0.252.16 by Jelmer Vernooij
make sure file ids are roundtripped properly.
244
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
245
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
246
class RoundtripRevisionsFromGit(tests.TestCase):
247
248
    def setUp(self):
249
        super(RoundtripRevisionsFromGit, self).setUp()
250
        self.mapping = BzrGitMappingv1()
251
252
    def assertRoundtripTree(self, tree):
253
        raise NotImplementedError(self.assertRoundtripTree)
254
255
    def assertRoundtripBlob(self, blob):
256
        raise NotImplementedError(self.assertRoundtripBlob)
257
258
    def assertRoundtripCommit(self, commit1):
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
259
        rev, roundtrip_revid, verifiers = self.mapping.import_commit(
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
260
            commit1, self.mapping.revision_id_foreign_to_bzr)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
261
        commit2 = self.mapping.export_commit(rev, "12341212121212", None,
0.200.1023 by Jelmer Vernooij
Set and verify testament.
262
            True, None)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
263
        self.assertEquals(commit1.committer, commit2.committer)
264
        self.assertEquals(commit1.commit_time, commit2.commit_time)
0.200.362 by Jelmer Vernooij
Fix tests.
265
        self.assertEquals(commit1.commit_timezone, commit2.commit_timezone)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
266
        self.assertEquals(commit1.author, commit2.author)
267
        self.assertEquals(commit1.author_time, commit2.author_time)
0.200.362 by Jelmer Vernooij
Fix tests.
268
        self.assertEquals(commit1.author_timezone, commit2.author_timezone)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
269
        self.assertEquals(commit1.message, commit2.message)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
270
        self.assertEquals(commit1.encoding, commit2.encoding)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
271
272
    def test_commit(self):
273
        c = Commit()
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
274
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
275
        c.message = "Some message"
276
        c.committer = "Committer <Committer>"
277
        c.commit_time = 4
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
278
        c.commit_timezone = -60 * 3
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
279
        c.author_time = 5
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
280
        c.author_timezone = 60 * 2
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
281
        c.author = "Author <author>"
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
282
        self.assertRoundtripCommit(c)
283
0.200.884 by Jelmer Vernooij
Cope with -0000 as timezone in Git commits.
284
    def test_commit_zero_utc_timezone(self):
285
        c = Commit()
286
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
287
        c.message = "Some message"
288
        c.committer = "Committer <Committer>"
289
        c.commit_time = 4
290
        c.commit_timezone = 0
291
        c._commit_timezone_neg_utc = True
292
        c.author_time = 5
293
        c.author_timezone = 60 * 2
294
        c.author = "Author <author>"
295
        self.assertRoundtripCommit(c)
296
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
297
    def test_commit_encoding(self):
298
        c = Commit()
299
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
300
        c.message = "Some message"
301
        c.committer = "Committer <Committer>"
302
        c.encoding = 'iso8859-1'
303
        c.commit_time = 4
304
        c.commit_timezone = -60 * 3
305
        c.author_time = 5
306
        c.author_timezone = 60 * 2
307
        c.author = "Author <author>"
308
        self.assertRoundtripCommit(c)
309
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
310
311
class DirectoryToTreeTests(tests.TestCase):
312
313
    def test_empty(self):
314
        ie = InventoryDirectory('foo', 'foo', 'foo')
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
315
        t = directory_to_tree(ie, None, {}, None)
0.200.589 by Jelmer Vernooij
Fix handling of empty trees.
316
        self.assertEquals(None, t)
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
317
318
    def test_empty_dir(self):
319
        ie = InventoryDirectory('foo', 'foo', 'foo')
320
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
321
        ie.children['bar'] = child_ie
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
322
        t = directory_to_tree(ie, lambda x: None, {}, None)
0.200.589 by Jelmer Vernooij
Fix handling of empty trees.
323
        self.assertEquals(None, t)
324
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
325
    def test_empty_dir_dummy_files(self):
326
        ie = InventoryDirectory('foo', 'foo', 'foo')
327
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
328
        ie.children['bar'] = child_ie
329
        t = directory_to_tree(ie, lambda x: None, {}, ".mydummy")
330
        self.assertTrue(".mydummy" in t)
331
0.200.589 by Jelmer Vernooij
Fix handling of empty trees.
332
    def test_empty_root(self):
333
        ie = InventoryDirectory('foo', 'foo', None)
334
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
335
        ie.children['bar'] = child_ie
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
336
        t = directory_to_tree(ie, lambda x: None, {}, None)
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
337
        self.assertEquals(Tree(), t)
338
339
    def test_with_file(self):
340
        ie = InventoryDirectory('foo', 'foo', 'foo')
341
        child_ie = InventoryFile('bar', 'bar', 'bar')
342
        ie.children['bar'] = child_ie
343
        b = Blob.from_string("bla")
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
344
        t1 = directory_to_tree(ie, lambda x: b.id, {}, None)
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
345
        t2 = Tree()
0.200.1152 by Jelmer Vernooij
Require dulwich 0.7.1.
346
        t2.add("bar", 0100644, b.id)
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
347
        self.assertEquals(t1, t2)