1
# Copyright (C) 2009-2018 Jelmer Vernooij <jelmer@jelmer.uk>
2
# Copyright (C) 2007 Canonical Ltd
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Test the GitDir class"""
20
from __future__ import absolute_import
22
from dulwich.repo import Repo as GitRepo
30
from ...transport import get_transport
31
from ...tests import TestSkipped
40
class TestGitDir(tests.TestCaseInTempDir):
42
def test_get_head_branch_reference(self):
45
gd = controldir.ControlDir.open('.')
48
urlutils.local_path_to_url(os.path.abspath(".")),
49
gd.get_branch_reference())
51
def test_open_existing(self):
54
gd = controldir.ControlDir.open('.')
55
self.assertIsInstance(gd, dir.LocalGitDir)
57
def test_open_workingtree(self):
60
gd = controldir.ControlDir.open('.')
62
wt = gd.open_workingtree()
63
self.assertIsInstance(wt, workingtree.GitWorkingTree)
65
def test_open_workingtree_bare(self):
66
GitRepo.init_bare(".")
68
gd = controldir.ControlDir.open('.')
69
self.assertRaises(errors.NoWorkingTree, gd.open_workingtree)
71
def test_git_file(self):
72
gitrepo = GitRepo.init("blah", mkdir=True)
73
self.build_tree_contents(
74
[('foo/', ), ('foo/.git', b'gitdir: ../blah/.git\n')])
76
gd = controldir.ControlDir.open('foo')
77
self.assertEqual(gd.control_url.rstrip('/'),
78
urlutils.local_path_to_url(os.path.abspath(gitrepo.controldir())))
80
def test_shared_repository(self):
81
t = get_transport('.')
83
errors.SharedRepositoriesUnsupported,
84
dir.LocalGitControlDirFormat().initialize_on_transport_ex, t,
88
class TestGitDirFormat(tests.TestCase):
91
super(TestGitDirFormat, self).setUp()
92
self.format = dir.LocalGitControlDirFormat()
94
def test_get_format_description(self):
95
self.assertEqual("Local Git Repository",
96
self.format.get_format_description())
99
format2 = dir.LocalGitControlDirFormat()
100
self.assertEqual(self.format, format2)
101
self.assertEqual(self.format, self.format)
102
bzr_format = controldir.format_registry.make_controldir("default")
103
self.assertNotEqual(self.format, bzr_format)