4
# Copyright (C) 2011 Jelmer Vernooij <jelmer@apache.org>
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
from cStringIO import StringIO
23
from dulwich.repo import Repo
25
from ....tests import (
26
TestCaseWithTransport,
30
from ..object_store import get_object_store
31
from ..git_remote_helper import (
39
def map_to_git_sha1(dir, bzr_revid):
40
object_store = get_object_store(dir.open_repository())
41
object_store.lock_read()
43
return object_store._lookup_revision_sha1(bzr_revid)
48
class OpenLocalDirTests(TestCaseWithTransport):
50
def test_from_env(self):
51
self.make_branch_and_tree('bla', format='git')
52
self.overrideEnv('GIT_DIR', os.path.join(self.test_dir, 'bla'))
55
def test_from_env_dir(self):
56
self.make_branch_and_tree('bla', format='git')
57
self.overrideEnv('GIT_DIR', os.path.join(self.test_dir, 'bla', '.git'))
60
def test_from_dir(self):
61
self.make_branch_and_tree('.', format='git')
65
class FetchTests(TestCaseWithTransport):
68
super(FetchTests, self).setUp()
69
self.local_dir = self.make_branch_and_tree('local', format='git').controldir
70
self.remote_tree = self.make_branch_and_tree('remote')
71
self.remote_dir = self.remote_tree.controldir
72
self.shortname = 'bzr'
74
def fetch(self, wants):
76
fetch(outf, wants, self.shortname, self.remote_dir, self.local_dir)
77
return outf.getvalue()
79
def test_no_wants(self):
81
self.assertEquals("\n", r)
83
def test_simple(self):
84
self.build_tree(['remote/foo'])
85
self.remote_tree.add("foo")
86
revid = self.remote_tree.commit("msg")
87
git_sha1 = map_to_git_sha1(self.remote_dir, revid)
88
out = self.fetch([(git_sha1, 'HEAD')])
89
self.assertEquals(out, "\n")
91
self.assertTrue(git_sha1 in r.object_store)
92
self.assertEquals({'HEAD': '0000000000000000000000000000000000000000'}, r.get_refs())
95
class RemoteHelperTests(TestCaseWithTransport):
98
super(RemoteHelperTests, self).setUp()
99
self.local_dir = self.make_branch_and_tree('local', format='git').controldir
100
self.remote_tree = self.make_branch_and_tree('remote')
101
self.remote_dir = self.remote_tree.controldir
102
self.shortname = 'bzr'
103
self.helper = RemoteHelper(self.local_dir, self.shortname, self.remote_dir)
105
def test_capabilities(self):
107
self.helper.cmd_capabilities(f, [])
108
capabs = f.getvalue()
109
base = "fetch\noption\npush\n"
110
self.assertTrue(capabs in (base+"\n", base+"import\n\n"), capabs)
112
def test_option(self):
114
self.helper.cmd_option(f, [])
115
self.assertEquals("unsupported\n", f.getvalue())
117
def test_list_basic(self):
119
self.helper.cmd_list(f, [])
121
'0000000000000000000000000000000000000000 HEAD\n\n',
124
def test_import(self):
125
if fastexporter is None:
126
raise TestSkipped("bzr-fastimport not available")
127
self.build_tree_contents([("remote/afile", "somecontent")])
128
self.remote_tree.add(["afile"])
129
self.remote_tree.commit("A commit message", timestamp=1330445983,
130
timezone=0, committer='Somebody <jrandom@example.com>')
132
self.helper.cmd_import(f, ["import", "refs/heads/master"])
134
'commit refs/heads/master\n'
136
'committer Somebody <jrandom@example.com> 1330445983 +0000\n'
139
'M 644 inline afile\n'