31
74
self.assertEquals(None, graphwalker.next())
77
class LocalRepositoryFetchTests(TestCaseWithTransport):
79
def make_git_repo(self, path):
85
def clone_git_repo(self, from_url, to_url):
86
oldrepos = Repository.open(from_url)
87
dir = BzrDir.create(to_url, get_rich_root_format())
88
newrepos = dir.create_repository()
89
oldrepos.copy_content_into(newrepos)
93
self.make_git_repo("d")
94
newrepos = self.clone_git_repo("d", "f")
95
self.assertEquals([], newrepos.all_revision_ids())
97
def test_single_rev(self):
98
self.make_git_repo("d")
100
bb = GitBranchBuilder()
101
bb.set_file("foobar", "foo\nbar\n", False)
102
mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
103
gitsha = bb.finish()[mark]
105
oldrepo = Repository.open("d")
106
newrepo = self.clone_git_repo("d", "f")
107
self.assertEquals([oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)], newrepo.all_revision_ids())
109
def test_executable(self):
110
self.make_git_repo("d")
112
bb = GitBranchBuilder()
113
bb.set_file("foobar", "foo\nbar\n", True)
114
bb.set_file("notexec", "foo\nbar\n", False)
115
mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
116
gitsha = bb.finish()[mark]
118
oldrepo = Repository.open("d")
119
newrepo = self.clone_git_repo("d", "f")
120
revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
121
tree = newrepo.revision_tree(revid)
122
self.assertTrue(tree.has_filename("foobar"))
123
self.assertEquals(True, tree.inventory[tree.path2id("foobar")].executable)
124
self.assertTrue(tree.has_filename("notexec"))
125
self.assertEquals(False, tree.inventory[tree.path2id("notexec")].executable)
128
class ImportObjects(TestCaseWithTransport):
131
super(ImportObjects, self).setUp()
132
self._map = DictGitShaMap()
133
self._mapping = BzrGitMappingv1()
134
factory = knit.make_file_factory(True, versionedfile.PrefixMapper())
135
self._texts = factory(self.get_transport('texts'))
137
def test_import_blob_simple(self):
138
blob = Blob.from_string("bar")
140
inv.revision_id = "somerevid"
141
import_git_blob(self._texts, self._mapping, "bla", blob,
142
inv, [], self._map, False)
143
self.assertEquals(set([('bla', 'somerevid')]), self._texts.keys())
144
self.assertEquals(self._texts.get_record_stream([('bla', 'somerevid')],
145
"unordered", True).next().get_bytes_as("fulltext"), "bar")
146
self.assertEquals(False, inv["bla"].executable)
147
self.assertEquals("file", inv["bla"].kind)
148
self.assertEquals("somerevid", inv["bla"].revision)
149
self.assertEquals(osutils.sha_strings(["bar"]), inv["bla"].text_sha1)
151
def test_import_tree_empty_root(self):
153
inv.revision_id = "somerevid"
156
import_git_tree(self._texts, self._mapping, "", tree, inv, [],
157
self._map, {}.__getitem__)
158
self.assertEquals(set([("TREE_ROOT", 'somerevid')]), self._texts.keys())
159
self.assertEquals(False, inv["TREE_ROOT"].executable)
160
self.assertEquals("directory", inv["TREE_ROOT"].kind)
161
self.assertEquals({}, inv["TREE_ROOT"].children)
162
self.assertEquals("somerevid", inv["TREE_ROOT"].revision)
163
self.assertEquals(None, inv["TREE_ROOT"].text_sha1)
165
def test_import_tree_empty(self):
167
inv.revision_id = "somerevid"
170
import_git_tree(self._texts, self._mapping, "bla", tree, inv, [],
171
self._map, {}.__getitem__)
172
self.assertEquals(set([("bla", 'somerevid')]), self._texts.keys())
173
self.assertEquals("directory", inv["bla"].kind)
174
self.assertEquals(False, inv["bla"].executable)
175
self.assertEquals({}, inv["bla"].children)
176
self.assertEquals("somerevid", inv["bla"].revision)
177
self.assertEquals(None, inv["bla"].text_sha1)
179
def test_import_tree_with_file(self):
181
inv.revision_id = "somerevid"
182
blob = Blob.from_string("bar1")
184
tree.add(0100600, "foo", blob.id)
186
objects = { blob.id: blob, tree.id: tree }
187
import_git_tree(self._texts, self._mapping, "bla", tree, inv, [],
188
self._map, objects.__getitem__)
189
self.assertEquals(["foo"], inv["bla"].children.keys())
190
self.assertEquals(set(["bla", "bla/foo"]),
191
set([ie.file_id for (path, ie) in inv.entries()]))
193
self.assertEquals("file", ie.kind)
194
self.assertEquals("bla/foo", ie.file_id)
195
self.assertEquals("somerevid", ie.revision)
196
self.assertEquals(osutils.sha_strings(["bar1"]), ie.text_sha1)
197
self.assertEquals(False, ie.executable)
199
def test_import_tree_with_file_exe(self):
201
inv.revision_id = "somerevid"
202
blob = Blob.from_string("bar")
204
tree.add(0100755, "foo", blob.id)
206
objects = { blob.id: blob, tree.id: tree }
207
import_git_tree(self._texts, self._mapping, "bla", tree, inv, [],
208
self._map, objects.__getitem__)
209
self.assertEquals(["foo"], inv["bla"].children.keys())
211
self.assertEquals("file", ie.kind)
212
self.assertEquals(True, ie.executable)