/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
1
# Copyright (C) 2009-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
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
0.358.1 by Jelmer Vernooij
Fix FSF address.
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
17
18
"""Test the GitDir class"""
19
0.358.3 by Jelmer Vernooij
Enable absolute import.
20
from __future__ import absolute_import
21
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
22
from dulwich.repo import Repo as GitRepo
0.200.1377 by Jelmer Vernooij
Fix get_branch_reference.
23
import os
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
24
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
25
from ... import (
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
26
    controldir,
0.200.254 by Jelmer Vernooij
Fix tests.
27
    errors,
0.200.1377 by Jelmer Vernooij
Fix get_branch_reference.
28
    urlutils,
0.200.254 by Jelmer Vernooij
Fix tests.
29
    )
7385.2.2 by Jelmer Vernooij
Raise exception when requesting shared repository be created.
30
from ...transport import get_transport
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
31
from ...tests import TestSkipped
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
32
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
33
from .. import (
0.200.254 by Jelmer Vernooij
Fix tests.
34
    dir,
35
    tests,
36
    workingtree,
37
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
38
39
40
class TestGitDir(tests.TestCaseInTempDir):
41
0.200.1377 by Jelmer Vernooij
Fix get_branch_reference.
42
    def test_get_head_branch_reference(self):
43
        GitRepo.init(".")
44
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
45
        gd = controldir.ControlDir.open('.')
6964.2.3 by Jelmer Vernooij
Review comments.
46
        self.assertEqual(
0.303.3 by Jelmer Vernooij
Prefer using branch segment parameter in reference branch URLs.
47
            "%s,branch=master" %
7143.15.2 by Jelmer Vernooij
Run autopep8.
48
            urlutils.local_path_to_url(os.path.abspath(".")),
0.200.1377 by Jelmer Vernooij
Fix get_branch_reference.
49
            gd.get_branch_reference())
50
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
51
    def test_open_existing(self):
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
52
        GitRepo.init(".")
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
53
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
54
        gd = controldir.ControlDir.open('.')
0.200.148 by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir.
55
        self.assertIsInstance(gd, dir.LocalGitDir)
0.200.69 by Jelmer Vernooij
Implement GitBzrDirFormat.get_format_description.
56
7290.44.1 by Jelmer Vernooij
Don't throw an error attempting to read the parent of a ref.
57
    def test_open_ref_parent(self):
58
        r = GitRepo.init(".")
7290.44.2 by Jelmer Vernooij
Use bytestrings.
59
        cid = r.do_commit(message=b"message", ref=b'refs/heads/foo/bar')
7290.44.1 by Jelmer Vernooij
Don't throw an error attempting to read the parent of a ref.
60
        gd = controldir.ControlDir.open('.')
61
        self.assertRaises(errors.NotBranchError, gd.open_branch, 'foo')
62
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
63
    def test_open_workingtree(self):
7290.44.1 by Jelmer Vernooij
Don't throw an error attempting to read the parent of a ref.
64
        r = GitRepo.init(".")
7290.44.2 by Jelmer Vernooij
Use bytestrings.
65
        r.do_commit(message=b"message")
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
66
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
67
        gd = controldir.ControlDir.open('.')
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
68
        wt = gd.open_workingtree()
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
69
        self.assertIsInstance(wt, workingtree.GitWorkingTree)
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
70
71
    def test_open_workingtree_bare(self):
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
72
        GitRepo.init_bare(".")
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
73
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
74
        gd = controldir.ControlDir.open('.')
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
75
        self.assertRaises(errors.NoWorkingTree, gd.open_workingtree)
76
0.398.1 by Jelmer Vernooij
Support reading .git files.
77
    def test_git_file(self):
78
        gitrepo = GitRepo.init("blah", mkdir=True)
7143.15.2 by Jelmer Vernooij
Run autopep8.
79
        self.build_tree_contents(
80
            [('foo/', ), ('foo/.git', b'gitdir: ../blah/.git\n')])
0.398.1 by Jelmer Vernooij
Support reading .git files.
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
7385.2.2 by Jelmer Vernooij
Raise exception when requesting shared repository be created.
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
0.200.69 by Jelmer Vernooij
Implement GitBzrDirFormat.get_format_description.
93
0.200.977 by Jelmer Vernooij
Implement GitBzrDirFormat.__eq__.
94
class TestGitDirFormat(tests.TestCase):
0.200.69 by Jelmer Vernooij
Implement GitBzrDirFormat.get_format_description.
95
96
    def setUp(self):
97
        super(TestGitDirFormat, self).setUp()
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
98
        self.format = dir.LocalGitControlDirFormat()
0.200.69 by Jelmer Vernooij
Implement GitBzrDirFormat.get_format_description.
99
100
    def test_get_format_description(self):
6964.2.3 by Jelmer Vernooij
Review comments.
101
        self.assertEqual("Local Git Repository",
7143.15.2 by Jelmer Vernooij
Run autopep8.
102
                         self.format.get_format_description())
0.200.69 by Jelmer Vernooij
Implement GitBzrDirFormat.get_format_description.
103
0.200.977 by Jelmer Vernooij
Implement GitBzrDirFormat.__eq__.
104
    def test_eq(self):
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
105
        format2 = dir.LocalGitControlDirFormat()
6964.2.3 by Jelmer Vernooij
Review comments.
106
        self.assertEqual(self.format, format2)
107
        self.assertEqual(self.format, self.format)
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
108
        bzr_format = controldir.format_registry.make_controldir("default")
6939.3.7 by Jelmer Vernooij
Don't use deprecated assertNotEquals.
109
        self.assertNotEqual(self.format, bzr_format)