/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tests/test_fetch.py

  • Committer: Jelmer Vernooij
  • Date: 2009-05-16 21:13:17 UTC
  • mto: (0.200.527 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20090516211317-a0s14tsrf2qusapf
Fix tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
    Repo as GitRepo,
24
24
    )
25
25
import os
26
 
import stat
27
26
 
28
27
from bzrlib import (
29
28
    knit,
42
41
from bzrlib.tests import (
43
42
    TestCaseWithTransport,
44
43
    )
 
44
from bzrlib.transport import (
 
45
    get_transport,
 
46
    )
45
47
 
 
48
from bzrlib.plugins.git import (
 
49
    get_rich_root_format,
 
50
    )
46
51
from bzrlib.plugins.git.fetch import (
47
52
    import_git_blob,
48
53
    import_git_tree,
49
54
    )
50
55
from bzrlib.plugins.git.mapping import (
51
56
    BzrGitMappingv1,
52
 
    DEFAULT_FILE_MODE,
 
57
    default_mapping,
 
58
    )
 
59
from bzrlib.plugins.git.shamap import (
 
60
    DictGitShaMap,
53
61
    )
54
62
from bzrlib.plugins.git.tests import (
55
63
    GitBranchBuilder,
64
72
 
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)
70
78
        return newrepos
117
125
        newrepo.fetch(oldrepo, revision_id=revid2)
118
126
        self.assertEquals(set([revid1, revid2]), set(newrepo.all_revision_ids()))
119
127
 
120
 
    def test_dir_becomes_symlink(self):
121
 
        self.make_git_repo("d")
122
 
        os.chdir("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")
128
 
        marks = bb.finish()
129
 
        gitsha1 = marks[mark1]
130
 
        gitsha2 = marks[mark2]
131
 
        os.chdir("..")
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)
147
 
 
148
 
    def test_symlink_becomes_dir(self):
149
 
        self.make_git_repo("d")
150
 
        os.chdir("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")
156
 
        marks = bb.finish()
157
 
        gitsha1 = marks[mark1]
158
 
        gitsha2 = marks[mark2]
159
 
        os.chdir("..")
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)
175
 
 
176
 
    def test_changing_symlink(self):
177
 
        self.make_git_repo("d")
178
 
        os.chdir("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")
184
 
        marks = bb.finish()
185
 
        gitsha1 = marks[mark1]
186
 
        gitsha2 = marks[mark2]
187
 
        os.chdir("..")
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)
201
 
 
202
128
    def test_executable(self):
203
129
        self.make_git_repo("d")
204
130
        os.chdir("d")
217
143
        self.assertTrue(tree.has_filename("notexec"))
218
144
        self.assertEquals(False, tree.inventory[tree.path2id("notexec")].executable)
219
145
 
220
 
    def test_becomes_executable(self):
221
 
        self.make_git_repo("d")
222
 
        os.chdir("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]
229
 
        os.chdir("..")
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)
238
 
 
239
146
    def test_non_ascii_characters(self):
240
147
        self.make_git_repo("d")
241
148
        os.chdir("d")
257
164
        return Repository.open(path)
258
165
 
259
166
 
260
 
class DummyStoreUpdater(object):
261
 
 
262
 
    def add_object(self, obj, ie, path):
263
 
        pass
264
 
 
265
 
    def finish(self):
266
 
        pass
267
 
 
268
 
 
269
167
class ImportObjects(TestCaseWithTransport):
270
168
 
271
169
    def setUp(self):
272
170
        super(ImportObjects, self).setUp()
 
171
        self._map = DictGitShaMap()
273
172
        self._mapping = BzrGitMappingv1()
274
173
        factory = knit.make_file_factory(True, versionedfile.PrefixMapper())
275
174
        self._texts = factory(self.get_transport('texts'))
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",
282
 
            (None, "blobname"), 
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,
 
182
            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)
300
197
        tree = Tree()
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, {})
 
198
        tree.serialize()
 
199
        ret, _, _ = import_git_tree(self._texts, self._mapping, "", 
 
200
               tree.id, base_inv, 
 
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()
320
215
        tree = Tree()
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, {})
 
216
        tree.serialize()
 
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")
341
234
        tree = Tree()
342
 
        tree.add(stat.S_IFREG | 0644, "foo", blob.id)
 
235
        tree.add(0100600, "foo", blob.id)
 
236
        tree.serialize()
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)
362
253
 
363
 
    def test_import_tree_with_unusual_mode_file(self):
364
 
        base_inv = Inventory()
365
 
        blob = Blob.from_string("bar1")
366
 
        tree = Tree()
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 })
374
 
 
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")
378
257
        tree = Tree()
379
258
        tree.add(0100755, "foo", blob.id)
 
259
        tree.serialize()
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])