/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

Add FOSDEM roundtripping notes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
from dulwich.objects import (
18
 
    Blob,
19
 
    Tree,
20
 
    )
21
 
import os
22
 
 
23
 
from bzrlib import (
24
 
    knit,
25
 
    osutils,
26
 
    versionedfile,
27
 
    )
28
 
from bzrlib.bzrdir import (
29
 
    BzrDir,
30
 
    )
31
 
from bzrlib.inventory import (
32
 
    Inventory,
33
 
    )
34
 
from bzrlib.repository import (
35
 
    Repository,
36
 
    )
37
 
from bzrlib.tests import (
38
 
    TestCaseWithTransport,
39
 
    )
40
 
from bzrlib.transport import (
41
 
    get_transport,
42
 
    )
43
 
 
44
 
from bzrlib.plugins.git import (
45
 
    get_rich_root_format,
46
 
    )
47
 
from bzrlib.plugins.git.fetch import (
48
 
    BzrFetchGraphWalker,
49
 
    import_git_blob,
50
 
    import_git_tree,
51
 
    )
52
 
from bzrlib.plugins.git.mapping import (
53
 
    BzrGitMappingv1,
54
 
    default_mapping,
55
 
    )
56
 
from bzrlib.plugins.git.shamap import (
57
 
    DictGitShaMap,
58
 
    )
59
 
from bzrlib.plugins.git.tests import (
60
 
    GitBranchBuilder,
61
 
    run_git,
62
 
    )
63
 
 
 
17
from bzrlib.plugins.git.fetch import BzrFetchGraphWalker
 
18
from bzrlib.plugins.git.mapping import default_mapping
 
19
 
 
20
from bzrlib.tests import TestCaseWithTransport
64
21
 
65
22
class FetchGraphWalkerTests(TestCaseWithTransport):
66
23
 
74
31
        self.assertEquals(None, graphwalker.next())
75
32
 
76
33
 
77
 
class LocalRepositoryFetchTests(TestCaseWithTransport):
78
 
 
79
 
    def make_git_repo(self, path):
80
 
        os.mkdir(path)
81
 
        os.chdir(path)
82
 
        run_git("init")
83
 
        os.chdir("..")
84
 
 
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)
90
 
        return newrepos
91
 
 
92
 
    def test_empty(self):
93
 
        self.make_git_repo("d")
94
 
        newrepos = self.clone_git_repo("d", "f")
95
 
        self.assertEquals([], newrepos.all_revision_ids())
96
 
 
97
 
    def test_single_rev(self):
98
 
        self.make_git_repo("d")
99
 
        os.chdir("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]
104
 
        os.chdir("..")
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())
108
 
 
109
 
    def test_executable(self):
110
 
        self.make_git_repo("d")
111
 
        os.chdir("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]
117
 
        os.chdir("..")
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)
126
 
 
127
 
 
128
 
class ImportObjects(TestCaseWithTransport):
129
 
 
130
 
    def setUp(self):
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'))
136
 
 
137
 
    def test_import_blob_simple(self):
138
 
        blob = Blob.from_string("bar")
139
 
        inv = Inventory()
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)
150
 
 
151
 
    def test_import_tree_empty_root(self):
152
 
        inv = Inventory()
153
 
        inv.revision_id = "somerevid"
154
 
        tree = Tree()
155
 
        tree.serialize()
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)
164
 
 
165
 
    def test_import_tree_empty(self):
166
 
        inv = Inventory()
167
 
        inv.revision_id = "somerevid"
168
 
        tree = Tree()
169
 
        tree.serialize()
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)
178
 
 
179
 
    def test_import_tree_with_file(self):
180
 
        inv = Inventory()
181
 
        inv.revision_id = "somerevid"
182
 
        blob = Blob.from_string("bar1")
183
 
        tree = Tree()
184
 
        tree.add(0100600, "foo", blob.id)
185
 
        tree.serialize()
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()]))
192
 
        ie = inv["bla/foo"]
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)
198
 
 
199
 
    def test_import_tree_with_file_exe(self):
200
 
        inv = Inventory()
201
 
        inv.revision_id = "somerevid"
202
 
        blob = Blob.from_string("bar")
203
 
        tree = Tree()
204
 
        tree.add(0100755, "foo", blob.id)
205
 
        tree.serialize()
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())
210
 
        ie = inv["bla/foo"]
211
 
        self.assertEquals("file", ie.kind)
212
 
        self.assertEquals(True, ie.executable)
213