/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/git/tests/test_dir.py

  • Committer: Vincent Ladeuil
  • Date: 2019-11-19 18:10:28 UTC
  • mfrom: (7290.1.43 work)
  • mto: This revision was merged to the branch mainline in revision 7414.
  • Revision ID: v.ladeuil+brz@free.fr-20191119181028-rgajksejntz3vwil
MergeĀ lp:brz/3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009-2018 Jelmer Vernooij <jelmer@jelmer.uk>
1
2
# Copyright (C) 2007 Canonical Ltd
2
3
#
3
4
# This program is free software; you can redistribute it and/or modify
12
13
#
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
16
17
 
17
18
"""Test the GitDir class"""
18
19
 
19
 
from bzrlib import bzrdir, errors
20
 
 
21
 
from bzrlib.plugins.git import dir, tests, workingtree
 
20
from __future__ import absolute_import
 
21
 
 
22
from dulwich.repo import Repo as GitRepo
 
23
import os
 
24
 
 
25
from ... import (
 
26
    controldir,
 
27
    errors,
 
28
    urlutils,
 
29
    )
 
30
from ...transport import get_transport
 
31
from ...tests import TestSkipped
 
32
 
 
33
from .. import (
 
34
    dir,
 
35
    tests,
 
36
    workingtree,
 
37
    )
22
38
 
23
39
 
24
40
class TestGitDir(tests.TestCaseInTempDir):
25
41
 
26
 
    _test_needs_features = [tests.GitCommandFeature]
 
42
    def test_get_head_branch_reference(self):
 
43
        GitRepo.init(".")
 
44
 
 
45
        gd = controldir.ControlDir.open('.')
 
46
        self.assertEqual(
 
47
            "%s,branch=master" %
 
48
            urlutils.local_path_to_url(os.path.abspath(".")),
 
49
            gd.get_branch_reference())
27
50
 
28
51
    def test_open_existing(self):
29
 
        tests.run_git('init')
 
52
        GitRepo.init(".")
30
53
 
31
 
        gd = bzrdir.BzrDir.open('.')
 
54
        gd = controldir.ControlDir.open('.')
32
55
        self.assertIsInstance(gd, dir.LocalGitDir)
33
56
 
34
57
    def test_open_workingtree(self):
35
 
        tests.run_git('init')
 
58
        GitRepo.init(".")
36
59
 
37
 
        gd = bzrdir.BzrDir.open('.')
 
60
        gd = controldir.ControlDir.open('.')
 
61
        raise TestSkipped
38
62
        wt = gd.open_workingtree()
39
63
        self.assertIsInstance(wt, workingtree.GitWorkingTree)
40
64
 
41
65
    def test_open_workingtree_bare(self):
42
 
        tests.run_git('--bare', 'init')
 
66
        GitRepo.init_bare(".")
43
67
 
44
 
        gd = bzrdir.BzrDir.open('.')
 
68
        gd = controldir.ControlDir.open('.')
45
69
        self.assertRaises(errors.NoWorkingTree, gd.open_workingtree)
46
70
 
47
 
 
48
 
class TestGitDirFormat(tests.TestCaseInTempDir):
49
 
 
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')])
 
75
 
 
76
        gd = controldir.ControlDir.open('foo')
 
77
        self.assertEqual(gd.control_url.rstrip('/'),
 
78
                         urlutils.local_path_to_url(os.path.abspath(gitrepo.controldir())))
 
79
 
 
80
    def test_shared_repository(self):
 
81
        t = get_transport('.')
 
82
        self.assertRaises(
 
83
            errors.SharedRepositoriesUnsupported,
 
84
            dir.LocalGitControlDirFormat().initialize_on_transport_ex, t,
 
85
            shared_repo=True)
 
86
 
 
87
 
 
88
class TestGitDirFormat(tests.TestCase):
51
89
 
52
90
    def setUp(self):
53
91
        super(TestGitDirFormat, self).setUp()
54
 
        self.format = dir.LocalGitBzrDirFormat()
 
92
        self.format = dir.LocalGitControlDirFormat()
55
93
 
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())
59
97
 
 
98
    def test_eq(self):
 
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)