/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: Jelmer Vernooij
  • Date: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

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 dulwich.repo import Repo as GitRepo
 
21
import os
 
22
 
 
23
from ... import (
 
24
    controldir,
 
25
    errors,
 
26
    urlutils,
 
27
    )
 
28
from ...transport import get_transport
 
29
from ...tests import TestSkipped
 
30
 
 
31
from .. import (
 
32
    dir,
 
33
    tests,
 
34
    workingtree,
 
35
    )
22
36
 
23
37
 
24
38
class TestGitDir(tests.TestCaseInTempDir):
25
39
 
26
 
    _test_needs_features = [tests.GitCommandFeature]
 
40
    def test_get_head_branch_reference(self):
 
41
        GitRepo.init(".")
 
42
 
 
43
        gd = controldir.ControlDir.open('.')
 
44
        self.assertEqual(
 
45
            "%s,branch=master" %
 
46
            urlutils.local_path_to_url(os.path.abspath(".")),
 
47
            gd.get_branch_reference())
27
48
 
28
49
    def test_open_existing(self):
29
 
        tests.run_git('init')
 
50
        GitRepo.init(".")
30
51
 
31
 
        gd = bzrdir.BzrDir.open('.')
 
52
        gd = controldir.ControlDir.open('.')
32
53
        self.assertIsInstance(gd, dir.LocalGitDir)
33
54
 
 
55
    def test_open_ref_parent(self):
 
56
        r = GitRepo.init(".")
 
57
        cid = r.do_commit(message=b"message", ref=b'refs/heads/foo/bar')
 
58
        gd = controldir.ControlDir.open('.')
 
59
        self.assertRaises(errors.NotBranchError, gd.open_branch, 'foo')
 
60
 
34
61
    def test_open_workingtree(self):
35
 
        tests.run_git('init')
 
62
        r = GitRepo.init(".")
 
63
        r.do_commit(message=b"message")
36
64
 
37
 
        gd = bzrdir.BzrDir.open('.')
 
65
        gd = controldir.ControlDir.open('.')
38
66
        wt = gd.open_workingtree()
39
67
        self.assertIsInstance(wt, workingtree.GitWorkingTree)
40
68
 
41
69
    def test_open_workingtree_bare(self):
42
 
        tests.run_git('--bare', 'init')
 
70
        GitRepo.init_bare(".")
43
71
 
44
 
        gd = bzrdir.BzrDir.open('.')
 
72
        gd = controldir.ControlDir.open('.')
45
73
        self.assertRaises(errors.NoWorkingTree, gd.open_workingtree)
46
74
 
47
 
 
48
 
class TestGitDirFormat(tests.TestCaseInTempDir):
49
 
 
50
 
    _test_needs_features = [tests.GitCommandFeature]
 
75
    def test_git_file(self):
 
76
        gitrepo = GitRepo.init("blah", mkdir=True)
 
77
        self.build_tree_contents(
 
78
            [('foo/', ), ('foo/.git', b'gitdir: ../blah/.git\n')])
 
79
 
 
80
        gd = controldir.ControlDir.open('foo')
 
81
        self.assertEqual(gd.control_url.rstrip('/'),
 
82
                         urlutils.local_path_to_url(os.path.abspath(gitrepo.controldir())))
 
83
 
 
84
    def test_shared_repository(self):
 
85
        t = get_transport('.')
 
86
        self.assertRaises(
 
87
            errors.SharedRepositoriesUnsupported,
 
88
            dir.LocalGitControlDirFormat().initialize_on_transport_ex, t,
 
89
            shared_repo=True)
 
90
 
 
91
 
 
92
class TestGitDirFormat(tests.TestCase):
51
93
 
52
94
    def setUp(self):
53
95
        super(TestGitDirFormat, self).setUp()
54
 
        self.format = dir.LocalGitBzrDirFormat()
 
96
        self.format = dir.LocalGitControlDirFormat()
55
97
 
56
98
    def test_get_format_description(self):
57
 
        self.assertEquals("Local Git Repository",
58
 
                          self.format.get_format_description())
 
99
        self.assertEqual("Local Git Repository",
 
100
                         self.format.get_format_description())
59
101
 
 
102
    def test_eq(self):
 
103
        format2 = dir.LocalGitControlDirFormat()
 
104
        self.assertEqual(self.format, format2)
 
105
        self.assertEqual(self.format, self.format)
 
106
        bzr_format = controldir.format_registry.make_controldir("default")
 
107
        self.assertNotEqual(self.format, bzr_format)