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
19
from bzrlib.bzrdir import BzrDir
20
from bzrlib.repository import Repository
21
from bzrlib.tests import TestCaseWithTransport
23
from bzrlib.plugins.git import (
26
from bzrlib.plugins.git.fetch import BzrFetchGraphWalker
27
from bzrlib.plugins.git.mapping import default_mapping
28
from bzrlib.plugins.git.tests import (
34
class FetchGraphWalkerTests(TestCaseWithTransport):
37
TestCaseWithTransport.setUp(self)
38
self.mapping = default_mapping
41
tree = self.make_branch_and_tree("wt")
42
graphwalker = BzrFetchGraphWalker(tree.branch.repository, self.mapping)
43
self.assertEquals(None, graphwalker.next())
46
class LocalRepositoryFetchTests(TestCaseWithTransport):
48
def make_git_repo(self, path):
54
def clone_git_repo(self, from_url, to_url):
55
oldrepos = Repository.open(from_url)
56
dir = BzrDir.create(to_url, get_rich_root_format())
57
newrepos = dir.create_repository()
58
oldrepos.copy_content_into(newrepos)
62
self.make_git_repo("d")
63
newrepos = self.clone_git_repo("d", "f")
64
self.assertEquals([], newrepos.all_revision_ids())
66
def test_single_rev(self):
67
self.make_git_repo("d")
69
bb = GitBranchBuilder()
70
bb.set_file("foobar", "foo\nbar\n", False)
71
mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
72
gitsha = bb.finish()[mark]
74
oldrepo = Repository.open("d")
75
newrepo = self.clone_git_repo("d", "f")
76
self.assertEquals([oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)], newrepo.all_revision_ids())
78
def test_executable(self):
79
self.make_git_repo("d")
81
bb = GitBranchBuilder()
82
bb.set_file("foobar", "foo\nbar\n", True)
83
bb.set_file("notexec", "foo\nbar\n", False)
84
mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
85
gitsha = bb.finish()[mark]
87
oldrepo = Repository.open("d")
88
newrepo = self.clone_git_repo("d", "f")
89
revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
90
tree = newrepo.revision_tree(revid)
91
self.assertTrue(tree.has_filename("foobar"))
92
self.assertEquals(True, tree.inventory[tree.path2id("foobar")].executable)
93
self.assertTrue(tree.has_filename("notexec"))
94
self.assertEquals(False, tree.inventory[tree.path2id("notexec")].executable)