117
125
newrepo.fetch(oldrepo, revision_id=revid2)
118
126
self.assertEquals(set([revid1, revid2]), set(newrepo.all_revision_ids()))
120
def test_dir_becomes_symlink(self):
121
self.make_git_repo("d")
123
bb = GitBranchBuilder()
124
bb.set_file("mylink/somefile", "foo\nbar\n", False)
125
mark1 = bb.commit("Somebody <somebody@someorg.org>", "mymsg1")
126
bb.set_symlink("mylink", "target/")
127
mark2 = bb.commit("Somebody <somebody@someorg.org>", "mymsg2")
129
gitsha1 = marks[mark1]
130
gitsha2 = marks[mark2]
132
oldrepo = self.open_git_repo("d")
133
newrepo = self.clone_git_repo("d", "f")
134
revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
135
revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
136
tree1 = newrepo.revision_tree(revid1)
137
tree2 = newrepo.revision_tree(revid2)
138
fileid = tree1.path2id("mylink")
139
ie1 = tree1.inventory[fileid]
140
ie2 = tree2.inventory[fileid]
141
self.assertEquals(revid1, ie1.revision)
142
self.assertEquals("directory", ie1.kind)
143
self.assertEquals(None, ie1.symlink_target)
144
self.assertEquals(revid2, ie2.revision)
145
self.assertEquals("symlink", ie2.kind)
146
self.assertEquals("target/", ie2.symlink_target)
148
def test_symlink_becomes_dir(self):
149
self.make_git_repo("d")
151
bb = GitBranchBuilder()
152
bb.set_symlink("mylink", "target/")
153
mark1 = bb.commit("Somebody <somebody@someorg.org>", "mymsg1")
154
bb.set_file("mylink/somefile", "foo\nbar\n", False)
155
mark2 = bb.commit("Somebody <somebody@someorg.org>", "mymsg2")
157
gitsha1 = marks[mark1]
158
gitsha2 = marks[mark2]
160
oldrepo = self.open_git_repo("d")
161
newrepo = self.clone_git_repo("d", "f")
162
revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
163
revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
164
tree1 = newrepo.revision_tree(revid1)
165
tree2 = newrepo.revision_tree(revid2)
166
fileid = tree1.path2id("mylink")
167
ie1 = tree1.inventory[fileid]
168
ie2 = tree2.inventory[fileid]
169
self.assertEquals(revid1, ie1.revision)
170
self.assertEquals("symlink", ie1.kind)
171
self.assertEquals("target/", ie1.symlink_target)
172
self.assertEquals(revid2, ie2.revision)
173
self.assertEquals("directory", ie2.kind)
174
self.assertEquals(None, ie2.symlink_target)
176
def test_changing_symlink(self):
177
self.make_git_repo("d")
179
bb = GitBranchBuilder()
180
bb.set_symlink("mylink", "target")
181
mark1 = bb.commit("Somebody <somebody@someorg.org>", "mymsg1")
182
bb.set_symlink("mylink", "target/")
183
mark2 = bb.commit("Somebody <somebody@someorg.org>", "mymsg2")
185
gitsha1 = marks[mark1]
186
gitsha2 = marks[mark2]
188
oldrepo = self.open_git_repo("d")
189
newrepo = self.clone_git_repo("d", "f")
190
revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
191
revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
192
tree1 = newrepo.revision_tree(revid1)
193
tree2 = newrepo.revision_tree(revid2)
194
fileid = tree1.path2id("mylink")
195
ie1 = tree1.inventory[fileid]
196
ie2 = tree2.inventory[fileid]
197
self.assertEquals(revid1, ie1.revision)
198
self.assertEquals("target", ie1.symlink_target)
199
self.assertEquals(revid2, ie2.revision)
200
self.assertEquals("target/", ie2.symlink_target)
202
128
def test_executable(self):
203
129
self.make_git_repo("d")
217
143
self.assertTrue(tree.has_filename("notexec"))
218
144
self.assertEquals(False, tree.inventory[tree.path2id("notexec")].executable)
220
def test_becomes_executable(self):
221
self.make_git_repo("d")
223
bb = GitBranchBuilder()
224
bb.set_file("foobar", "foo\nbar\n", False)
225
mark1 = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
226
bb.set_file("foobar", "foo\nbar\n", True)
227
mark2 = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
228
gitsha2 = bb.finish()[mark2]
230
oldrepo = self.open_git_repo("d")
231
newrepo = self.clone_git_repo("d", "f")
232
revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
233
tree = newrepo.revision_tree(revid)
234
self.assertTrue(tree.has_filename("foobar"))
235
ie = tree.inventory[tree.path2id("foobar")]
236
self.assertEquals(True, ie.executable)
237
self.assertEquals(revid, ie.revision)
239
146
def test_non_ascii_characters(self):
240
147
self.make_git_repo("d")
278
177
blob = Blob.from_string("bar")
279
178
base_inv = Inventory()
280
179
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)
180
ret, _= import_git_blob(self._texts, self._mapping, "bla", "blobname",
181
base_inv, None, "somerevid", [], self._map, objs.__getitem__, False,
286
183
self.assertEquals(set([('bla', 'somerevid')]), self._texts.keys())
287
184
self.assertEquals(self._texts.get_record_stream([('bla', 'somerevid')],
288
185
"unordered", True).next().get_bytes_as("fulltext"), "bar")
298
195
def test_import_tree_empty_root(self):
299
196
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, {})
199
ret, _, _ = import_git_tree(self._texts, self._mapping, "",
201
None, "somerevid", [], self._map, {tree.id: tree}.__getitem__)
307
202
self.assertEquals(set([("TREE_ROOT", 'somerevid')]), self._texts.keys())
308
203
self.assertEquals(1, len(ret))
309
204
self.assertEquals(None, ret[0][0])
318
213
def test_import_tree_empty(self):
319
214
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, {})
217
ret, _, _ = import_git_tree(self._texts, self._mapping, "bla",
218
tree.id, base_inv, None, "somerevid", [],
219
self._map, { tree.id: tree }.__getitem__)
327
220
self.assertEquals(set([("bla", 'somerevid')]), self._texts.keys())
328
221
self.assertEquals(1, len(ret))
329
222
self.assertEquals(None, ret[0][0])
339
232
base_inv = Inventory()
340
233
blob = Blob.from_string("bar1")
342
tree.add(stat.S_IFREG | 0644, "foo", blob.id)
235
tree.add(0100600, "foo", blob.id)
343
237
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, {})
238
ret, _, _ = import_git_tree(self._texts, self._mapping, "bla", tree.id,
239
base_inv, None, "somerevid", [], self._map, objects.__getitem__)
349
240
self.assertEquals(2, len(ret))
350
241
self.assertEquals(None, ret[0][0])
351
242
self.assertEquals("bla", ret[0][1])
360
251
self.assertEquals(osutils.sha_strings(["bar1"]), ie.text_sha1)
361
252
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
254
def test_import_tree_with_file_exe(self):
376
255
base_inv = Inventory(root_id=None)
377
256
blob = Blob.from_string("bar")
379
258
tree.add(0100755, "foo", blob.id)
380
260
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, {})
261
ret, _, _ = import_git_tree(self._texts, self._mapping, "", tree.id,
262
base_inv, None, "somerevid", [], self._map, objects.__getitem__)
386
263
self.assertEquals(2, len(ret))
387
264
self.assertEquals(None, ret[0][0])
388
265
self.assertEquals("", ret[0][1])