13
14
# You should have received a copy of the GNU General Public License
14
15
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18
"""Test the GitDir class"""
19
from bzrlib import bzrdir, errors
21
from bzrlib.plugins.git import dir, tests, workingtree
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
24
40
class TestGitDir(tests.TestCaseInTempDir):
26
_test_needs_features = [tests.GitCommandFeature]
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())
28
51
def test_open_existing(self):
31
gd = bzrdir.BzrDir.open('.')
54
gd = controldir.ControlDir.open('.')
32
55
self.assertIsInstance(gd, dir.LocalGitDir)
34
57
def test_open_workingtree(self):
37
gd = bzrdir.BzrDir.open('.')
60
gd = controldir.ControlDir.open('.')
38
62
wt = gd.open_workingtree()
39
63
self.assertIsInstance(wt, workingtree.GitWorkingTree)
41
65
def test_open_workingtree_bare(self):
42
tests.run_git('--bare', 'init')
66
GitRepo.init_bare(".")
44
gd = bzrdir.BzrDir.open('.')
68
gd = controldir.ControlDir.open('.')
45
69
self.assertRaises(errors.NoWorkingTree, gd.open_workingtree)
48
class TestGitDirFormat(tests.TestCaseInTempDir):
50
_test_needs_features = [tests.GitCommandFeature]
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):
53
91
super(TestGitDirFormat, self).setUp()
54
self.format = dir.LocalGitBzrDirFormat()
92
self.format = dir.LocalGitControlDirFormat()
56
94
def test_get_format_description(self):
57
self.assertEquals("Local Git Repository",
58
self.format.get_format_description())
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)