42
41
from bzrlib.tests import (
43
42
TestCaseWithTransport,
44
from bzrlib.transport import (
48
from bzrlib.plugins.git import (
46
51
from bzrlib.plugins.git.fetch import (
50
55
from bzrlib.plugins.git.mapping import (
59
from bzrlib.plugins.git.shamap import (
54
62
from bzrlib.plugins.git.tests import (
65
73
def clone_git_repo(self, from_url, to_url, revision_id=None):
66
74
oldrepos = self.open_git_repo(from_url)
67
dir = BzrDir.create(to_url)
75
dir = BzrDir.create(to_url, get_rich_root_format())
68
76
newrepos = dir.create_repository()
69
77
oldrepos.copy_content_into(newrepos, revision_id=revision_id)
257
265
return Repository.open(path)
260
class DummyStoreUpdater(object):
262
def add_object(self, obj, ie, path):
269
268
class ImportObjects(TestCaseWithTransport):
272
271
super(ImportObjects, self).setUp()
272
self._map = DictGitShaMap()
273
273
self._mapping = BzrGitMappingv1()
274
274
factory = knit.make_file_factory(True, versionedfile.PrefixMapper())
275
275
self._texts = factory(self.get_transport('texts'))
278
278
blob = Blob.from_string("bar")
279
279
base_inv = Inventory()
280
280
objs = { "blobname": blob}
281
ret = import_git_blob(self._texts, self._mapping, "bla", "bla",
283
base_inv, None, "somerevid", [], objs.__getitem__,
284
(None, DEFAULT_FILE_MODE), DummyStoreUpdater(),
285
self._mapping.generate_file_id)
281
ret, _= import_git_blob(self._texts, self._mapping, "bla", "blobname",
282
base_inv, None, None, "somerevid", [], self._map, objs.__getitem__, False,
286
284
self.assertEquals(set([('bla', 'somerevid')]), self._texts.keys())
287
285
self.assertEquals(self._texts.get_record_stream([('bla', 'somerevid')],
288
286
"unordered", True).next().get_bytes_as("fulltext"), "bar")
298
296
def test_import_tree_empty_root(self):
299
297
base_inv = Inventory(root_id=None)
301
ret, child_modes = import_git_tree(self._texts, self._mapping, "", "",
302
(None, tree.id), base_inv,
303
None, "somerevid", [], {tree.id: tree}.__getitem__,
304
(None, stat.S_IFDIR), DummyStoreUpdater(),
305
self._mapping.generate_file_id)
306
self.assertEquals(child_modes, {})
300
ret, _, _ = import_git_tree(self._texts, self._mapping, "",
301
tree.id, base_inv, None,
302
None, "somerevid", [], self._map, {tree.id: tree}.__getitem__)
307
303
self.assertEquals(set([("TREE_ROOT", 'somerevid')]), self._texts.keys())
308
304
self.assertEquals(1, len(ret))
309
305
self.assertEquals(None, ret[0][0])
318
314
def test_import_tree_empty(self):
319
315
base_inv = Inventory()
321
ret, child_modes = import_git_tree(self._texts, self._mapping, "bla", "bla",
322
(None, tree.id), base_inv, None, "somerevid", [],
323
{ tree.id: tree }.__getitem__,
324
(None, stat.S_IFDIR), DummyStoreUpdater(),
325
self._mapping.generate_file_id)
326
self.assertEquals(child_modes, {})
318
ret, _, _ = import_git_tree(self._texts, self._mapping, "bla",
319
tree.id, base_inv, None, None, "somerevid", [],
320
self._map, { tree.id: tree }.__getitem__)
327
321
self.assertEquals(set([("bla", 'somerevid')]), self._texts.keys())
328
322
self.assertEquals(1, len(ret))
329
323
self.assertEquals(None, ret[0][0])
339
333
base_inv = Inventory()
340
334
blob = Blob.from_string("bar1")
342
tree.add(stat.S_IFREG | 0644, "foo", blob.id)
336
tree.add(0100600, "foo", blob.id)
343
338
objects = { blob.id: blob, tree.id: tree }
344
ret, child_modes = import_git_tree(self._texts, self._mapping, "bla", "bla",
345
(None, tree.id), base_inv, None, "somerevid", [],
346
objects.__getitem__, (None, stat.S_IFDIR), DummyStoreUpdater(),
347
self._mapping.generate_file_id)
348
self.assertEquals(child_modes, {})
339
ret, _, _ = import_git_tree(self._texts, self._mapping, "bla", tree.id,
340
base_inv, None, None, "somerevid", [], self._map, objects.__getitem__)
349
341
self.assertEquals(2, len(ret))
350
342
self.assertEquals(None, ret[0][0])
351
343
self.assertEquals("bla", ret[0][1])
360
352
self.assertEquals(osutils.sha_strings(["bar1"]), ie.text_sha1)
361
353
self.assertEquals(False, ie.executable)
363
def test_import_tree_with_unusual_mode_file(self):
364
base_inv = Inventory()
365
blob = Blob.from_string("bar1")
367
tree.add(stat.S_IFREG | 0664, "foo", blob.id)
368
objects = { blob.id: blob, tree.id: tree }
369
ret, child_modes = import_git_tree(self._texts, self._mapping, "bla", "bla",
370
(None, tree.id), base_inv, None, "somerevid", [],
371
objects.__getitem__, (None, stat.S_IFDIR), DummyStoreUpdater(),
372
self._mapping.generate_file_id)
373
self.assertEquals(child_modes, { "bla/foo": stat.S_IFREG | 0664 })
375
355
def test_import_tree_with_file_exe(self):
376
356
base_inv = Inventory(root_id=None)
377
357
blob = Blob.from_string("bar")
379
359
tree.add(0100755, "foo", blob.id)
380
361
objects = { blob.id: blob, tree.id: tree }
381
ret, child_modes = import_git_tree(self._texts, self._mapping, "", "",
382
(None, tree.id), base_inv, None, "somerevid", [],
383
objects.__getitem__, (None, stat.S_IFDIR), DummyStoreUpdater(),
384
self._mapping.generate_file_id)
385
self.assertEquals(child_modes, {})
362
ret, _, _ = import_git_tree(self._texts, self._mapping, "", tree.id,
363
base_inv, None, None, "somerevid", [], self._map, objects.__getitem__)
386
364
self.assertEquals(2, len(ret))
387
365
self.assertEquals(None, ret[0][0])
388
366
self.assertEquals("", ret[0][1])