/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
1
# Copyright (C) 2009-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.200.298 by Jelmer Vernooij
Add test for non-ascii characters.
2
# -*- coding: utf-8 -*-
0.200.196 by Jelmer Vernooij
Add simple tests and docstrings for GraphWalker.
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
0.358.1 by Jelmer Vernooij
Fix FSF address.
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.200.196 by Jelmer Vernooij
Add simple tests and docstrings for GraphWalker.
17
0.358.3 by Jelmer Vernooij
Enable absolute import.
18
"""Tests from fetching from git into bzr."""
19
20
from __future__ import absolute_import
21
0.200.264 by Jelmer Vernooij
Add more tests.
22
from dulwich.objects import (
23
    Blob,
0.200.1403 by Jelmer Vernooij
Cope with tags pointing at tree objects when cloning local git repositories.
24
    Tag,
0.200.265 by Jelmer Vernooij
Add more tests.
25
    Tree,
0.200.1408 by Jelmer Vernooij
Remove old ie children when converting directory into tree reference.
26
    S_IFGITLINK,
0.200.264 by Jelmer Vernooij
Add more tests.
27
    )
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
28
from dulwich.repo import (
29
    Repo as GitRepo,
30
    )
0.228.1 by Jelmer Vernooij
Add basic tests for local fetch.
31
import os
0.200.817 by Jelmer Vernooij
Deal with all modes locally.
32
import stat
0.200.1403 by Jelmer Vernooij
Cope with tags pointing at tree objects when cloning local git repositories.
33
import time
0.228.1 by Jelmer Vernooij
Add basic tests for local fetch.
34
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
35
from .... import (
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
36
    osutils,
37
    )
38
from ....bzr import (
0.200.264 by Jelmer Vernooij
Add more tests.
39
    knit,
40
    versionedfile,
41
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
42
from ....branch import (
0.200.1404 by jelmer at samba
Add test for stacked on.
43
    Branch,
44
    )
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
45
from ....controldir import (
46
    ControlDir,
0.200.264 by Jelmer Vernooij
Add more tests.
47
    )
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
48
from ....bzr.inventory import (
0.200.264 by Jelmer Vernooij
Add more tests.
49
    Inventory,
50
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
51
from ....repository import (
0.200.264 by Jelmer Vernooij
Add more tests.
52
    Repository,
53
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
54
from ....tests import (
0.200.264 by Jelmer Vernooij
Add more tests.
55
    TestCaseWithTransport,
56
    )
0.228.1 by Jelmer Vernooij
Add basic tests for local fetch.
57
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
58
from ..fetch import (
0.200.264 by Jelmer Vernooij
Add more tests.
59
    import_git_blob,
60
    import_git_tree,
0.200.1408 by Jelmer Vernooij
Remove old ie children when converting directory into tree reference.
61
    import_git_submodule,
0.200.264 by Jelmer Vernooij
Add more tests.
62
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
63
from ..mapping import (
0.200.264 by Jelmer Vernooij
Add more tests.
64
    BzrGitMappingv1,
0.200.816 by Jelmer Vernooij
Leave mode handling for blobs to import_git_blob.
65
    DEFAULT_FILE_MODE,
0.200.264 by Jelmer Vernooij
Add more tests.
66
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
67
from . import (
0.228.1 by Jelmer Vernooij
Add basic tests for local fetch.
68
    GitBranchBuilder,
69
    )
0.200.196 by Jelmer Vernooij
Add simple tests and docstrings for GraphWalker.
70
71
0.259.8 by Jelmer Vernooij
Add test.
72
class RepositoryFetchTests(object):
0.228.1 by Jelmer Vernooij
Add basic tests for local fetch.
73
74
    def make_git_repo(self, path):
75
        os.mkdir(path)
0.200.1403 by Jelmer Vernooij
Cope with tags pointing at tree objects when cloning local git repositories.
76
        return GitRepo.init(os.path.abspath(path))
0.228.1 by Jelmer Vernooij
Add basic tests for local fetch.
77
0.200.268 by Jelmer Vernooij
Add more fetch tests.
78
    def clone_git_repo(self, from_url, to_url, revision_id=None):
79
        oldrepos = self.open_git_repo(from_url)
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
80
        dir = ControlDir.create(to_url)
0.228.1 by Jelmer Vernooij
Add basic tests for local fetch.
81
        newrepos = dir.create_repository()
0.200.268 by Jelmer Vernooij
Add more fetch tests.
82
        oldrepos.copy_content_into(newrepos, revision_id=revision_id)
0.228.1 by Jelmer Vernooij
Add basic tests for local fetch.
83
        return newrepos
84
85
    def test_empty(self):
86
        self.make_git_repo("d")
87
        newrepos = self.clone_git_repo("d", "f")
6964.2.3 by Jelmer Vernooij
Review comments.
88
        self.assertEqual([], newrepos.all_revision_ids())
0.228.1 by Jelmer Vernooij
Add basic tests for local fetch.
89
0.200.268 by Jelmer Vernooij
Add more fetch tests.
90
    def make_onerev_branch(self):
91
        self.make_git_repo("d")
92
        os.chdir("d")
93
        bb = GitBranchBuilder()
7027.2.1 by Jelmer Vernooij
Port fastimport to python3.
94
        bb.set_file("foobar", b"foo\nbar\n", False)
95
        mark = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg")
0.200.268 by Jelmer Vernooij
Add more fetch tests.
96
        gitsha = bb.finish()[mark]
97
        os.chdir("..")
98
        return "d", gitsha
99
0.228.1 by Jelmer Vernooij
Add basic tests for local fetch.
100
    def test_single_rev(self):
0.200.268 by Jelmer Vernooij
Add more fetch tests.
101
        path, gitsha = self.make_onerev_branch()
102
        oldrepo = self.open_git_repo(path)
103
        newrepo = self.clone_git_repo(path, "f")
0.200.1404 by jelmer at samba
Add test for stacked on.
104
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
6964.2.3 by Jelmer Vernooij
Review comments.
105
        self.assertEqual([revid], newrepo.all_revision_ids())
0.228.1 by Jelmer Vernooij
Add basic tests for local fetch.
106
0.200.268 by Jelmer Vernooij
Add more fetch tests.
107
    def test_single_rev_specific(self):
108
        path, gitsha = self.make_onerev_branch()
109
        oldrepo = self.open_git_repo(path)
110
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
111
        newrepo = self.clone_git_repo(path, "f", revision_id=revid)
6964.2.3 by Jelmer Vernooij
Review comments.
112
        self.assertEqual([revid], newrepo.all_revision_ids())
0.200.268 by Jelmer Vernooij
Add more fetch tests.
113
114
    def test_incremental(self):
115
        self.make_git_repo("d")
116
        os.chdir("d")
117
        bb = GitBranchBuilder()
7027.2.1 by Jelmer Vernooij
Port fastimport to python3.
118
        bb.set_file("foobar", b"foo\nbar\n", False)
119
        mark1 = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg")
120
        bb.set_file("foobar", b"fooll\nbar\n", False)
121
        mark2 = bb.commit(b"Somebody <somebody@someorg.org>", b"nextmsg")
0.200.268 by Jelmer Vernooij
Add more fetch tests.
122
        marks = bb.finish()
123
        gitsha1 = marks[mark1]
124
        gitsha2 = marks[mark2]
125
        os.chdir("..")
126
        oldrepo = self.open_git_repo("d")
127
        revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
128
        newrepo = self.clone_git_repo("d", "f", revision_id=revid1)
6964.2.3 by Jelmer Vernooij
Review comments.
129
        self.assertEqual([revid1], newrepo.all_revision_ids())
0.200.268 by Jelmer Vernooij
Add more fetch tests.
130
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
131
        newrepo.fetch(oldrepo, revision_id=revid2)
6964.2.3 by Jelmer Vernooij
Review comments.
132
        self.assertEqual(set([revid1, revid2]), set(newrepo.all_revision_ids()))
0.200.268 by Jelmer Vernooij
Add more fetch tests.
133
0.200.552 by Jelmer Vernooij
Cope with directories becoming symlinks.
134
    def test_dir_becomes_symlink(self):
135
        self.make_git_repo("d")
136
        os.chdir("d")
137
        bb = GitBranchBuilder()
7027.2.1 by Jelmer Vernooij
Port fastimport to python3.
138
        bb.set_file("mylink/somefile", b"foo\nbar\n", False)
139
        mark1 = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg1")
0.200.552 by Jelmer Vernooij
Cope with directories becoming symlinks.
140
        bb.set_symlink("mylink", "target/")
7027.2.1 by Jelmer Vernooij
Port fastimport to python3.
141
        mark2 = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg2")
0.200.552 by Jelmer Vernooij
Cope with directories becoming symlinks.
142
        marks = bb.finish()
143
        gitsha1 = marks[mark1]
144
        gitsha2 = marks[mark2]
145
        os.chdir("..")
146
        oldrepo = self.open_git_repo("d")
147
        newrepo = self.clone_git_repo("d", "f")
148
        revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
149
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
150
        tree1 = newrepo.revision_tree(revid1)
151
        tree2 = newrepo.revision_tree(revid2)
6964.2.3 by Jelmer Vernooij
Review comments.
152
        self.assertEqual(revid1, tree1.get_file_revision("mylink"))
153
        self.assertEqual("directory", tree1.kind("mylink"))
154
        self.assertEqual(None, tree1.get_symlink_target("mylink"))
155
        self.assertEqual(revid2, tree2.get_file_revision("mylink"))
156
        self.assertEqual("symlink", tree2.kind("mylink"))
157
        self.assertEqual("target/", tree2.get_symlink_target("mylink"))
0.200.552 by Jelmer Vernooij
Cope with directories becoming symlinks.
158
0.200.553 by Jelmer Vernooij
Support symlinks being turned into directories.
159
    def test_symlink_becomes_dir(self):
160
        self.make_git_repo("d")
161
        os.chdir("d")
162
        bb = GitBranchBuilder()
163
        bb.set_symlink("mylink", "target/")
7027.2.1 by Jelmer Vernooij
Port fastimport to python3.
164
        mark1 = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg1")
165
        bb.set_file("mylink/somefile", b"foo\nbar\n", False)
166
        mark2 = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg2")
0.200.553 by Jelmer Vernooij
Support symlinks being turned into directories.
167
        marks = bb.finish()
168
        gitsha1 = marks[mark1]
169
        gitsha2 = marks[mark2]
170
        os.chdir("..")
171
        oldrepo = self.open_git_repo("d")
172
        newrepo = self.clone_git_repo("d", "f")
173
        revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
174
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
175
        tree1 = newrepo.revision_tree(revid1)
176
        tree2 = newrepo.revision_tree(revid2)
6964.2.3 by Jelmer Vernooij
Review comments.
177
        self.assertEqual(revid1, tree1.get_file_revision("mylink"))
178
        self.assertEqual("symlink", tree1.kind("mylink"))
179
        self.assertEqual("target/", tree1.get_symlink_target("mylink"))
180
        self.assertEqual(revid2, tree2.get_file_revision("mylink"))
181
        self.assertEqual("directory", tree2.kind("mylink"))
182
        self.assertEqual(None, tree2.get_symlink_target("mylink"))
0.200.553 by Jelmer Vernooij
Support symlinks being turned into directories.
183
0.200.551 by Jelmer Vernooij
Properly set InventoryEntry revision when changing symlink targets.
184
    def test_changing_symlink(self):
185
        self.make_git_repo("d")
186
        os.chdir("d")
187
        bb = GitBranchBuilder()
188
        bb.set_symlink("mylink", "target")
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
189
        mark1 = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg1")
0.200.551 by Jelmer Vernooij
Properly set InventoryEntry revision when changing symlink targets.
190
        bb.set_symlink("mylink", "target/")
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
191
        mark2 = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg2")
0.200.551 by Jelmer Vernooij
Properly set InventoryEntry revision when changing symlink targets.
192
        marks = bb.finish()
193
        gitsha1 = marks[mark1]
194
        gitsha2 = marks[mark2]
195
        os.chdir("..")
196
        oldrepo = self.open_git_repo("d")
197
        newrepo = self.clone_git_repo("d", "f")
198
        revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
199
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
200
        tree1 = newrepo.revision_tree(revid1)
201
        tree2 = newrepo.revision_tree(revid2)
6964.2.3 by Jelmer Vernooij
Review comments.
202
        self.assertEqual(revid1, tree1.get_file_revision("mylink"))
203
        self.assertEqual("target", tree1.get_symlink_target("mylink"))
204
        self.assertEqual(revid2, tree2.get_file_revision("mylink"))
205
        self.assertEqual("target/", tree2.get_symlink_target("mylink"))
0.200.551 by Jelmer Vernooij
Properly set InventoryEntry revision when changing symlink targets.
206
0.228.2 by Jelmer Vernooij
Add test for fetching executables.
207
    def test_executable(self):
208
        self.make_git_repo("d")
209
        os.chdir("d")
210
        bb = GitBranchBuilder()
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
211
        bb.set_file("foobar", b"foo\nbar\n", True)
212
        bb.set_file("notexec", b"foo\nbar\n", False)
213
        mark = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg")
0.228.2 by Jelmer Vernooij
Add test for fetching executables.
214
        gitsha = bb.finish()[mark]
215
        os.chdir("..")
0.200.268 by Jelmer Vernooij
Add more fetch tests.
216
        oldrepo = self.open_git_repo("d")
0.228.2 by Jelmer Vernooij
Add test for fetching executables.
217
        newrepo = self.clone_git_repo("d", "f")
218
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
219
        tree = newrepo.revision_tree(revid)
220
        self.assertTrue(tree.has_filename("foobar"))
6964.2.3 by Jelmer Vernooij
Review comments.
221
        self.assertEqual(True, tree.is_executable("foobar"))
0.228.2 by Jelmer Vernooij
Add test for fetching executables.
222
        self.assertTrue(tree.has_filename("notexec"))
6964.2.3 by Jelmer Vernooij
Review comments.
223
        self.assertEqual(False, tree.is_executable("notexec"))
0.200.264 by Jelmer Vernooij
Add more tests.
224
0.200.537 by Jelmer Vernooij
Fix handling of not-executable files becoming executable without any other changes.
225
    def test_becomes_executable(self):
226
        self.make_git_repo("d")
227
        os.chdir("d")
228
        bb = GitBranchBuilder()
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
229
        bb.set_file("foobar", b"foo\nbar\n", False)
230
        mark1 = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg")
231
        bb.set_file("foobar", b"foo\nbar\n", True)
232
        mark2 = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg")
0.200.537 by Jelmer Vernooij
Fix handling of not-executable files becoming executable without any other changes.
233
        gitsha2 = bb.finish()[mark2]
234
        os.chdir("..")
235
        oldrepo = self.open_git_repo("d")
236
        newrepo = self.clone_git_repo("d", "f")
237
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
238
        tree = newrepo.revision_tree(revid)
239
        self.assertTrue(tree.has_filename("foobar"))
6964.2.3 by Jelmer Vernooij
Review comments.
240
        self.assertEqual(True, tree.is_executable("foobar"))
241
        self.assertEqual(revid, tree.get_file_revision("foobar"))
0.200.537 by Jelmer Vernooij
Fix handling of not-executable files becoming executable without any other changes.
242
0.200.1404 by jelmer at samba
Add test for stacked on.
243
    def test_into_stacked_on(self):
244
        r = self.make_git_repo("d")
245
        os.chdir("d")
246
        bb = GitBranchBuilder()
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
247
        bb.set_file(u"foobar", b"foo\n", False)
248
        mark1 = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg1")
0.200.1404 by jelmer at samba
Add test for stacked on.
249
        gitsha1 = bb.finish()[mark1]
250
        os.chdir("..")
251
        stacked_on = self.clone_git_repo("d", "stacked-on")
252
        oldrepo = Repository.open("d")
253
        revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
6964.2.3 by Jelmer Vernooij
Review comments.
254
        self.assertEqual([revid1], stacked_on.all_revision_ids())
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
255
        b = stacked_on.controldir.create_branch()
0.200.1404 by jelmer at samba
Add test for stacked on.
256
        b.generate_revision_history(revid1)
6964.2.3 by Jelmer Vernooij
Review comments.
257
        self.assertEqual(b.last_revision(), revid1)
0.200.1404 by jelmer at samba
Add test for stacked on.
258
        tree = self.make_branch_and_tree("stacked")
259
        tree.branch.set_stacked_on_url(b.user_url)
260
        os.chdir("d")
261
        bb = GitBranchBuilder()
7027.2.1 by Jelmer Vernooij
Port fastimport to python3.
262
        bb.set_file(u"barbar", b"bar\n", False)
263
        bb.set_file(u"foo/blie/bla", b"bla\n", False)
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
264
        mark2 = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg2")
0.200.1404 by jelmer at samba
Add test for stacked on.
265
        gitsha2 = bb.finish()[mark2]
266
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
267
        os.chdir("..")
268
        tree.branch.fetch(Branch.open("d"))
269
        tree.branch.repository.check()
270
        self.addCleanup(tree.lock_read().unlock)
6964.2.3 by Jelmer Vernooij
Review comments.
271
        self.assertEqual(
0.200.1404 by jelmer at samba
Add test for stacked on.
272
            set([(revid2,)]),
273
            tree.branch.repository.revisions.without_fallbacks().keys())
6964.2.3 by Jelmer Vernooij
Review comments.
274
        self.assertEqual(
0.200.1404 by jelmer at samba
Add test for stacked on.
275
            set([revid1, revid2]),
276
            set(tree.branch.repository.all_revision_ids()))
277
0.200.298 by Jelmer Vernooij
Add test for non-ascii characters.
278
    def test_non_ascii_characters(self):
279
        self.make_git_repo("d")
280
        os.chdir("d")
281
        bb = GitBranchBuilder()
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
282
        bb.set_file(u"foőbar", b"foo\nbar\n", False)
283
        mark = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg")
0.200.298 by Jelmer Vernooij
Add test for non-ascii characters.
284
        gitsha = bb.finish()[mark]
285
        os.chdir("..")
286
        oldrepo = self.open_git_repo("d")
287
        newrepo = self.clone_git_repo("d", "f")
288
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
289
        tree = newrepo.revision_tree(revid)
290
        self.assertTrue(tree.has_filename(u"foőbar"))
291
0.200.1403 by Jelmer Vernooij
Cope with tags pointing at tree objects when cloning local git repositories.
292
    def test_tagged_tree(self):
293
        r = self.make_git_repo("d")
294
        os.chdir("d")
295
        bb = GitBranchBuilder()
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
296
        bb.set_file("foobar", b"fooll\nbar\n", False)
297
        mark = bb.commit(b"Somebody <somebody@someorg.org>", b"nextmsg")
0.200.1403 by Jelmer Vernooij
Cope with tags pointing at tree objects when cloning local git repositories.
298
        marks = bb.finish()
299
        gitsha = marks[mark]
300
        tag = Tag()
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
301
        tag.name = b"sometag"
0.281.6 by William Grant
Fix test_tagged_tree to not create a non-integral tag timestamp.
302
        tag.tag_time = int(time.time())
0.200.1403 by Jelmer Vernooij
Cope with tags pointing at tree objects when cloning local git repositories.
303
        tag.tag_timezone = 0
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
304
        tag.tagger = b"Somebody <somebody@example.com>"
305
        tag.message = b"Created tag pointed at tree"
0.200.1403 by Jelmer Vernooij
Cope with tags pointing at tree objects when cloning local git repositories.
306
        tag.object = (Tree, r[gitsha].tree)
307
        r.object_store.add_object(tag)
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
308
        r[b"refs/tags/sometag"] = tag
0.200.1403 by Jelmer Vernooij
Cope with tags pointing at tree objects when cloning local git repositories.
309
        os.chdir("..")
310
        oldrepo = self.open_git_repo("d")
311
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
312
        newrepo = self.clone_git_repo("d", "f")
6964.2.3 by Jelmer Vernooij
Review comments.
313
        self.assertEqual(set([revid]), set(newrepo.all_revision_ids()))
0.200.1403 by Jelmer Vernooij
Cope with tags pointing at tree objects when cloning local git repositories.
314
0.200.264 by Jelmer Vernooij
Add more tests.
315
0.200.269 by Jelmer Vernooij
Prepare for testing remote repos.
316
class LocalRepositoryFetchTests(RepositoryFetchTests, TestCaseWithTransport):
317
318
    def open_git_repo(self, path):
319
        return Repository.open(path)
320
321
0.200.839 by Jelmer Vernooij
Add convenience object for updating the object store caching layer.
322
class DummyStoreUpdater(object):
323
0.200.952 by Jelmer Vernooij
Write git pack files rather than loose objects.
324
    def add_object(self, obj, ie, path):
0.200.839 by Jelmer Vernooij
Add convenience object for updating the object store caching layer.
325
        pass
326
327
    def finish(self):
328
        pass
329
330
0.200.264 by Jelmer Vernooij
Add more tests.
331
class ImportObjects(TestCaseWithTransport):
332
333
    def setUp(self):
334
        super(ImportObjects, self).setUp()
0.200.265 by Jelmer Vernooij
Add more tests.
335
        self._mapping = BzrGitMappingv1()
0.200.264 by Jelmer Vernooij
Add more tests.
336
        factory = knit.make_file_factory(True, versionedfile.PrefixMapper())
337
        self._texts = factory(self.get_transport('texts'))
338
339
    def test_import_blob_simple(self):
6973.13.2 by Jelmer Vernooij
Fix some more tests.
340
        blob = Blob.from_string(b"bar")
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
341
        base_inv = Inventory()
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
342
        objs = { "blobname": blob}
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
343
        ret = import_git_blob(self._texts, self._mapping, b"bla", b"bla",
0.200.815 by Jelmer Vernooij
Pass tuple with base_sha, sha to make the argument list for import_git_* a bit more understandable.
344
            (None, "blobname"), 
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
345
            base_inv, None, b"somerevid", [], objs.__getitem__, 
0.200.896 by Jelmer Vernooij
Add separate function for looking up file ids.
346
            (None, DEFAULT_FILE_MODE), DummyStoreUpdater(),
347
            self._mapping.generate_file_id)
6973.13.2 by Jelmer Vernooij
Fix some more tests.
348
        self.assertEqual(set([(b'git:bla', b'somerevid')]), self._texts.keys())
7018.3.10 by Jelmer Vernooij
Consistent return values in PreviewTree.list_files.
349
        self.assertEqual(next(self._texts.get_record_stream([(b'git:bla', b'somerevid')],
350
            "unordered", True)).get_bytes_as("fulltext"), "bar")
6964.2.3 by Jelmer Vernooij
Review comments.
351
        self.assertEqual(1, len(ret)) 
352
        self.assertEqual(None, ret[0][0])
353
        self.assertEqual("bla", ret[0][1])
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
354
        ie = ret[0][3]
6964.2.3 by Jelmer Vernooij
Review comments.
355
        self.assertEqual(False, ie.executable)
356
        self.assertEqual("file", ie.kind)
6973.13.2 by Jelmer Vernooij
Fix some more tests.
357
        self.assertEqual(b"somerevid", ie.revision)
6964.2.3 by Jelmer Vernooij
Review comments.
358
        self.assertEqual(osutils.sha_strings(["bar"]), ie.text_sha1)
0.200.265 by Jelmer Vernooij
Add more tests.
359
360
    def test_import_tree_empty_root(self):
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
361
        base_inv = Inventory(root_id=None)
0.200.265 by Jelmer Vernooij
Add more tests.
362
        tree = Tree()
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
363
        ret, child_modes = import_git_tree(self._texts, self._mapping, b"", b"",
0.200.848 by Jelmer Vernooij
remove unnecessary parent_inv_shamap.
364
               (None, tree.id), base_inv, 
6973.13.2 by Jelmer Vernooij
Fix some more tests.
365
               None, b"somerevid", [], {tree.id: tree}.__getitem__,
0.200.896 by Jelmer Vernooij
Add separate function for looking up file ids.
366
               (None, stat.S_IFDIR), DummyStoreUpdater(),
367
               self._mapping.generate_file_id)
6964.2.3 by Jelmer Vernooij
Review comments.
368
        self.assertEqual(child_modes, {})
6973.13.2 by Jelmer Vernooij
Fix some more tests.
369
        self.assertEqual(set([(b"TREE_ROOT", b'somerevid')]), self._texts.keys())
6964.2.3 by Jelmer Vernooij
Review comments.
370
        self.assertEqual(1, len(ret))
371
        self.assertEqual(None, ret[0][0])
372
        self.assertEqual("", ret[0][1])
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
373
        ie = ret[0][3]
6964.2.3 by Jelmer Vernooij
Review comments.
374
        self.assertEqual(False, ie.executable)
375
        self.assertEqual("directory", ie.kind)
376
        self.assertEqual({}, ie.children)
6973.13.2 by Jelmer Vernooij
Fix some more tests.
377
        self.assertEqual(b"somerevid", ie.revision)
6964.2.3 by Jelmer Vernooij
Review comments.
378
        self.assertEqual(None, ie.text_sha1)
0.200.265 by Jelmer Vernooij
Add more tests.
379
380
    def test_import_tree_empty(self):
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
381
        base_inv = Inventory()
0.200.265 by Jelmer Vernooij
Add more tests.
382
        tree = Tree()
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
383
        ret, child_modes = import_git_tree(self._texts, self._mapping, b"bla", b"bla",
6973.13.2 by Jelmer Vernooij
Fix some more tests.
384
           (None, tree.id), base_inv, None, b"somerevid", [], 
0.200.817 by Jelmer Vernooij
Deal with all modes locally.
385
           { tree.id: tree }.__getitem__,
0.200.896 by Jelmer Vernooij
Add separate function for looking up file ids.
386
           (None, stat.S_IFDIR), DummyStoreUpdater(),
387
           self._mapping.generate_file_id)
6964.2.3 by Jelmer Vernooij
Review comments.
388
        self.assertEqual(child_modes, {})
6973.13.2 by Jelmer Vernooij
Fix some more tests.
389
        self.assertEqual(set([(b"git:bla", b'somerevid')]), self._texts.keys())
6964.2.3 by Jelmer Vernooij
Review comments.
390
        self.assertEqual(1, len(ret))
391
        self.assertEqual(None, ret[0][0])
392
        self.assertEqual("bla", ret[0][1])
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
393
        ie = ret[0][3]
6964.2.3 by Jelmer Vernooij
Review comments.
394
        self.assertEqual("directory", ie.kind)
395
        self.assertEqual(False, ie.executable)
396
        self.assertEqual({}, ie.children)
6973.13.2 by Jelmer Vernooij
Fix some more tests.
397
        self.assertEqual(b"somerevid", ie.revision)
6964.2.3 by Jelmer Vernooij
Review comments.
398
        self.assertEqual(None, ie.text_sha1)
0.200.267 by Jelmer Vernooij
Add more tests for fetch code.
399
400
    def test_import_tree_with_file(self):
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
401
        base_inv = Inventory()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
402
        blob = Blob.from_string(b"bar1")
0.200.267 by Jelmer Vernooij
Add more tests for fetch code.
403
        tree = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
404
        tree.add(b"foo", stat.S_IFREG | 0o644, blob.id)
0.200.267 by Jelmer Vernooij
Add more tests for fetch code.
405
        objects = { blob.id: blob, tree.id: tree }
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
406
        ret, child_modes = import_git_tree(self._texts, self._mapping, b"bla", b"bla",
6973.13.2 by Jelmer Vernooij
Fix some more tests.
407
                (None, tree.id), base_inv, None, b"somerevid", [],
0.200.896 by Jelmer Vernooij
Add separate function for looking up file ids.
408
            objects.__getitem__, (None, stat.S_IFDIR), DummyStoreUpdater(),
409
            self._mapping.generate_file_id)
6964.2.3 by Jelmer Vernooij
Review comments.
410
        self.assertEqual(child_modes, {})
411
        self.assertEqual(2, len(ret))
412
        self.assertEqual(None, ret[0][0])
413
        self.assertEqual("bla", ret[0][1])
414
        self.assertEqual(None, ret[1][0])
415
        self.assertEqual("bla/foo", ret[1][1])
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
416
        ie = ret[0][3]
6964.2.3 by Jelmer Vernooij
Review comments.
417
        self.assertEqual("directory", ie.kind)
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
418
        ie = ret[1][3]
6964.2.3 by Jelmer Vernooij
Review comments.
419
        self.assertEqual("file", ie.kind)
6973.13.2 by Jelmer Vernooij
Fix some more tests.
420
        self.assertEqual(b"git:bla/foo", ie.file_id)
421
        self.assertEqual(b"somerevid", ie.revision)
422
        self.assertEqual(osutils.sha_strings([b"bar1"]), ie.text_sha1)
6964.2.3 by Jelmer Vernooij
Review comments.
423
        self.assertEqual(False, ie.executable)
0.200.267 by Jelmer Vernooij
Add more tests for fetch code.
424
0.200.878 by Jelmer Vernooij
Fix determining of unusual file modes.
425
    def test_import_tree_with_unusual_mode_file(self):
426
        base_inv = Inventory()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
427
        blob = Blob.from_string(b"bar1")
0.200.878 by Jelmer Vernooij
Fix determining of unusual file modes.
428
        tree = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
429
        tree.add(b"foo", stat.S_IFREG | 0o664, blob.id)
0.200.878 by Jelmer Vernooij
Fix determining of unusual file modes.
430
        objects = { blob.id: blob, tree.id: tree }
0.200.1152 by Jelmer Vernooij
Require dulwich 0.7.1.
431
        ret, child_modes = import_git_tree(self._texts, self._mapping,
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
432
            b"bla", b"bla", (None, tree.id), base_inv, None, b"somerevid", [],
0.200.896 by Jelmer Vernooij
Add separate function for looking up file ids.
433
            objects.__getitem__, (None, stat.S_IFDIR), DummyStoreUpdater(),
434
            self._mapping.generate_file_id)
6964.2.3 by Jelmer Vernooij
Review comments.
435
        self.assertEqual(child_modes, { "bla/foo": stat.S_IFREG | 0o664 })
0.200.878 by Jelmer Vernooij
Fix determining of unusual file modes.
436
0.200.267 by Jelmer Vernooij
Add more tests for fetch code.
437
    def test_import_tree_with_file_exe(self):
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
438
        base_inv = Inventory(root_id=None)
6973.13.2 by Jelmer Vernooij
Fix some more tests.
439
        blob = Blob.from_string(b"bar")
0.200.267 by Jelmer Vernooij
Add more tests for fetch code.
440
        tree = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
441
        tree.add(b"foo", 0o100755, blob.id)
0.200.267 by Jelmer Vernooij
Add more tests for fetch code.
442
        objects = { blob.id: blob, tree.id: tree }
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
443
        ret, child_modes = import_git_tree(self._texts, self._mapping, b"", b"",
6973.13.2 by Jelmer Vernooij
Fix some more tests.
444
                (None, tree.id), base_inv, None, b"somerevid", [],
0.200.896 by Jelmer Vernooij
Add separate function for looking up file ids.
445
            objects.__getitem__, (None, stat.S_IFDIR), DummyStoreUpdater(),
446
            self._mapping.generate_file_id)
6964.2.3 by Jelmer Vernooij
Review comments.
447
        self.assertEqual(child_modes, {})
448
        self.assertEqual(2, len(ret))
449
        self.assertEqual(None, ret[0][0])
450
        self.assertEqual("", ret[0][1])
451
        self.assertEqual(None, ret[1][0])
452
        self.assertEqual("foo", ret[1][1])
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
453
        ie = ret[0][3]
6964.2.3 by Jelmer Vernooij
Review comments.
454
        self.assertEqual("directory", ie.kind)
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
455
        ie = ret[1][3]
6964.2.3 by Jelmer Vernooij
Review comments.
456
        self.assertEqual("file", ie.kind)
457
        self.assertEqual(True, ie.executable)
0.200.1408 by Jelmer Vernooij
Remove old ie children when converting directory into tree reference.
458
459
    def test_directory_converted_to_submodule(self):
460
        base_inv = Inventory()
461
        base_inv.add_path("foo", "directory")
462
        base_inv.add_path("foo/bar", "file")
6973.13.2 by Jelmer Vernooij
Fix some more tests.
463
        othertree = Blob.from_string(b"someotherthing")
464
        blob = Blob.from_string(b"bar")
0.200.1408 by Jelmer Vernooij
Remove old ie children when converting directory into tree reference.
465
        tree = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
466
        tree.add(b"bar", 0o160000, blob.id)
0.200.1408 by Jelmer Vernooij
Remove old ie children when converting directory into tree reference.
467
        objects = { tree.id: tree }
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
468
        ret, child_modes = import_git_submodule(self._texts, self._mapping, b"foo", b"foo",
6973.13.2 by Jelmer Vernooij
Fix some more tests.
469
                (tree.id, othertree.id), base_inv, base_inv.root.file_id, b"somerevid", [],
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
470
                objects.__getitem__, (stat.S_IFDIR | 0o755, S_IFGITLINK), DummyStoreUpdater(),
0.200.1408 by Jelmer Vernooij
Remove old ie children when converting directory into tree reference.
471
                self._mapping.generate_file_id)
6964.2.3 by Jelmer Vernooij
Review comments.
472
        self.assertEqual(child_modes, {})
473
        self.assertEqual(2, len(ret))
474
        self.assertEqual(ret[0], ("foo/bar", None, base_inv.path2id("foo/bar"), None))
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
475
        self.assertEqual(ret[1][:3], ("foo", b"foo", self._mapping.generate_file_id("foo")))
0.200.1408 by Jelmer Vernooij
Remove old ie children when converting directory into tree reference.
476
        ie = ret[1][3]
6964.2.3 by Jelmer Vernooij
Review comments.
477
        self.assertEqual(ie.kind, "tree-reference")