1
# Copyright (C) 2011-2018 Jelmer Vernooij <jelmer@jelmer.uk>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Test for git server."""
19
from dulwich.client import TCPGitClient
20
from dulwich.repo import Repo
23
from ...transport import transport_server_registry
24
from ...tests import (
26
TestCaseWithTransport,
29
from ..server import (
35
class TestPresent(TestCase):
37
def test_present(self):
38
# Just test that the server is registered.
39
transport_server_registry.get('git')
42
class GitServerTestCase(TestCaseWithTransport):
44
def start_server(self, t):
45
backend = BzrBackend(t)
46
server = BzrTCPGitServer(backend, 'localhost', port=0)
47
self.addCleanup(server.shutdown)
48
thread = threading.Thread(target=server.serve).start()
50
_, port = self._server.socket.getsockname()
54
class TestPlainFetch(GitServerTestCase):
56
def test_fetch_from_native_git(self):
57
wt = self.make_branch_and_tree('t', format='git')
58
self.build_tree(['t/foo'])
60
revid = wt.commit(message="some data")
61
wt.branch.tags.set_tag("atag", revid)
62
t = self.get_transport('t')
63
port = self.start_server(t)
64
c = TCPGitClient('localhost', port=port)
65
gitrepo = Repo.init('gitrepo', mkdir=True)
66
result = c.fetch('/', gitrepo)
68
set(result.refs.keys()),
69
set([b"refs/tags/atag", b'refs/heads/master', b"HEAD"]))
71
def test_fetch_nothing(self):
72
wt = self.make_branch_and_tree('t')
73
self.build_tree(['t/foo'])
75
revid = wt.commit(message="some data")
76
wt.branch.tags.set_tag("atag", revid)
77
t = self.get_transport('t')
78
port = self.start_server(t)
79
c = TCPGitClient('localhost', port=port)
80
gitrepo = Repo.init('gitrepo', mkdir=True)
81
result = c.fetch('/', gitrepo, determine_wants=lambda x: [])
83
set(result.refs.keys()),
84
set([b"refs/tags/atag", b"HEAD"]))
86
def test_fetch_from_non_git(self):
87
wt = self.make_branch_and_tree('t', format='bzr')
88
self.build_tree(['t/foo'])
90
revid = wt.commit(message="some data")
91
wt.branch.tags.set_tag("atag", revid)
92
t = self.get_transport('t')
93
port = self.start_server(t)
94
c = TCPGitClient('localhost', port=port)
95
gitrepo = Repo.init('gitrepo', mkdir=True)
96
result = c.fetch('/', gitrepo)
98
set(result.refs.keys()),
99
set([b"refs/tags/atag", b"HEAD"]))