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 __future__ import absolute_import
21
from dulwich.client import TCPGitClient
22
from dulwich.repo import Repo
25
from ....transport import transport_server_registry
26
from ....tests import (
28
TestCaseWithTransport,
31
from ..server import (
36
class TestPresent(TestCase):
38
def test_present(self):
39
# Just test that the server is registered.
40
transport_server_registry.get('git')
43
class GitServerTestCase(TestCaseWithTransport):
45
def start_server(self, t):
46
backend = BzrBackend(t)
47
server = BzrTCPGitServer(backend, 'localhost', port=0)
48
self.addCleanup(server.shutdown)
49
thread = threading.Thread(target=server.serve).start()
51
_, port = self._server.socket.getsockname()
55
class TestPlainFetch(GitServerTestCase):
57
def test_fetch_simple(self):
58
wt = self.make_branch_and_tree('t')
59
self.build_tree(['t/foo'])
61
revid = wt.commit(message="some data")
62
wt.branch.tags.set_tag("atag", revid)
63
t = self.get_transport('t')
64
port = self.start_server(t)
65
c = TCPGitClient('localhost', port=port)
66
gitrepo = Repo.init('gitrepo', mkdir=True)
67
result = c.fetch('/', gitrepo)
69
set(result.refs.keys()),
70
set(["refs/tags/atag", "HEAD"]))
72
def test_fetch_nothing(self):
73
wt = self.make_branch_and_tree('t')
74
self.build_tree(['t/foo'])
76
revid = wt.commit(message="some data")
77
wt.branch.tags.set_tag("atag", revid)
78
t = self.get_transport('t')
79
port = self.start_server(t)
80
c = TCPGitClient('localhost', port=port)
81
gitrepo = Repo.init('gitrepo', mkdir=True)
82
result = c.fetch('/', gitrepo, determine_wants=lambda x: [])
84
set(result.refs.keys()),
85
set(["refs/tags/atag", "HEAD"]))