/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

[merge] robertc's integration, updated tests to check for retcode=3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009-2018 Jelmer Vernooij <jelmer@jelmer.uk>
2
 
# Copyright (C) 2007 Canonical Ltd
3
 
#
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.
8
 
#
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.
13
 
#
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
17
 
 
18
 
"""Test the GitDir class"""
19
 
 
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
 
    )
38
 
 
39
 
 
40
 
class TestGitDir(tests.TestCaseInTempDir):
41
 
 
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())
50
 
 
51
 
    def test_open_existing(self):
52
 
        GitRepo.init(".")
53
 
 
54
 
        gd = controldir.ControlDir.open('.')
55
 
        self.assertIsInstance(gd, dir.LocalGitDir)
56
 
 
57
 
    def test_open_ref_parent(self):
58
 
        r = GitRepo.init(".")
59
 
        cid = r.do_commit(message=b"message", ref=b'refs/heads/foo/bar')
60
 
        gd = controldir.ControlDir.open('.')
61
 
        self.assertRaises(errors.NotBranchError, gd.open_branch, 'foo')
62
 
 
63
 
    def test_open_workingtree(self):
64
 
        r = GitRepo.init(".")
65
 
        r.do_commit(message=b"message")
66
 
 
67
 
        gd = controldir.ControlDir.open('.')
68
 
        wt = gd.open_workingtree()
69
 
        self.assertIsInstance(wt, workingtree.GitWorkingTree)
70
 
 
71
 
    def test_open_workingtree_bare(self):
72
 
        GitRepo.init_bare(".")
73
 
 
74
 
        gd = controldir.ControlDir.open('.')
75
 
        self.assertRaises(errors.NoWorkingTree, gd.open_workingtree)
76
 
 
77
 
    def test_git_file(self):
78
 
        gitrepo = GitRepo.init("blah", mkdir=True)
79
 
        self.build_tree_contents(
80
 
            [('foo/', ), ('foo/.git', b'gitdir: ../blah/.git\n')])
81
 
 
82
 
        gd = controldir.ControlDir.open('foo')
83
 
        self.assertEqual(gd.control_url.rstrip('/'),
84
 
                         urlutils.local_path_to_url(os.path.abspath(gitrepo.controldir())))
85
 
 
86
 
    def test_shared_repository(self):
87
 
        t = get_transport('.')
88
 
        self.assertRaises(
89
 
            errors.SharedRepositoriesUnsupported,
90
 
            dir.LocalGitControlDirFormat().initialize_on_transport_ex, t,
91
 
            shared_repo=True)
92
 
 
93
 
 
94
 
class TestGitDirFormat(tests.TestCase):
95
 
 
96
 
    def setUp(self):
97
 
        super(TestGitDirFormat, self).setUp()
98
 
        self.format = dir.LocalGitControlDirFormat()
99
 
 
100
 
    def test_get_format_description(self):
101
 
        self.assertEqual("Local Git Repository",
102
 
                         self.format.get_format_description())
103
 
 
104
 
    def test_eq(self):
105
 
        format2 = dir.LocalGitControlDirFormat()
106
 
        self.assertEqual(self.format, format2)
107
 
        self.assertEqual(self.format, self.format)
108
 
        bzr_format = controldir.format_registry.make_controldir("default")
109
 
        self.assertNotEqual(self.format, bzr_format)