1
# Copyright (C) 2009 Jelmer Vernooij <jelmer@samba.org>
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
from dulwich.objects import (
26
from bzrlib.bzrdir import (
29
from bzrlib.inventory import (
32
from bzrlib.repository import (
35
from bzrlib.tests import (
36
TestCaseWithTransport,
38
from bzrlib.transport import (
42
from bzrlib.plugins.git import (
45
from bzrlib.plugins.git.fetch import (
50
from bzrlib.plugins.git.mapping import (
54
from bzrlib.plugins.git.shamap import (
57
from bzrlib.plugins.git.tests import (
63
class FetchGraphWalkerTests(TestCaseWithTransport):
66
TestCaseWithTransport.setUp(self)
67
self.mapping = default_mapping
70
tree = self.make_branch_and_tree("wt")
71
graphwalker = BzrFetchGraphWalker(tree.branch.repository, self.mapping)
72
self.assertEquals(None, graphwalker.next())
75
class LocalRepositoryFetchTests(TestCaseWithTransport):
77
def make_git_repo(self, path):
83
def clone_git_repo(self, from_url, to_url):
84
oldrepos = Repository.open(from_url)
85
dir = BzrDir.create(to_url, get_rich_root_format())
86
newrepos = dir.create_repository()
87
oldrepos.copy_content_into(newrepos)
91
self.make_git_repo("d")
92
newrepos = self.clone_git_repo("d", "f")
93
self.assertEquals([], newrepos.all_revision_ids())
95
def test_single_rev(self):
96
self.make_git_repo("d")
98
bb = GitBranchBuilder()
99
bb.set_file("foobar", "foo\nbar\n", False)
100
mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
101
gitsha = bb.finish()[mark]
103
oldrepo = Repository.open("d")
104
newrepo = self.clone_git_repo("d", "f")
105
self.assertEquals([oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)], newrepo.all_revision_ids())
107
def test_executable(self):
108
self.make_git_repo("d")
110
bb = GitBranchBuilder()
111
bb.set_file("foobar", "foo\nbar\n", True)
112
bb.set_file("notexec", "foo\nbar\n", False)
113
mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
114
gitsha = bb.finish()[mark]
116
oldrepo = Repository.open("d")
117
newrepo = self.clone_git_repo("d", "f")
118
revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
119
tree = newrepo.revision_tree(revid)
120
self.assertTrue(tree.has_filename("foobar"))
121
self.assertEquals(True, tree.inventory[tree.path2id("foobar")].executable)
122
self.assertTrue(tree.has_filename("notexec"))
123
self.assertEquals(False, tree.inventory[tree.path2id("notexec")].executable)
126
class ImportObjects(TestCaseWithTransport):
129
super(ImportObjects, self).setUp()
130
self._map = DictGitShaMap()
131
factory = knit.make_file_factory(True, versionedfile.PrefixMapper())
132
self._texts = factory(self.get_transport('texts'))
134
def test_import_blob_simple(self):
135
blob = Blob.from_string("bar")
137
inv.revision_id = "somerevid"
138
import_git_blob(self._texts, BzrGitMappingv1(), "bla", blob,
139
inv, [], self._map, False)
140
self.assertEquals(set([('bla', 'somerevid')]), self._texts.keys())