/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 git_dir.py

Add blackbox test for info.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""An adapter between a Git control dir and a Bazaar BzrDir"""
18
18
 
19
 
import git, os
20
 
 
21
 
import bzrlib
22
19
from bzrlib.lazy_import import lazy_import
23
20
from bzrlib import (
24
21
    bzrdir,
27
24
    )
28
25
 
29
26
lazy_import(globals(), """
30
 
from bzrlib.lockable_files import TransportLock
31
27
from bzrlib.plugins.git import (
32
28
    errors,
33
 
    branch,
34
 
    repository,
35
 
    workingtree,
 
29
    git_branch,
 
30
    git_repository,
36
31
    )
37
32
""")
38
33
 
40
35
class GitLock(object):
41
36
    """A lock that thunks through to Git."""
42
37
 
43
 
    def lock_write(self, token=None):
 
38
    def lock_write(self):
44
39
        pass
45
40
 
46
41
    def lock_read(self):
49
44
    def unlock(self):
50
45
        pass
51
46
 
52
 
    def peek(self):
53
 
        pass
54
 
 
55
47
 
56
48
class GitLockableFiles(lockable_files.LockableFiles):
57
49
    """Git specific lockable files abstraction."""
66
58
class GitDir(bzrdir.BzrDir):
67
59
    """An adapter to the '.git' dir used by git."""
68
60
 
69
 
    _gitrepository_class = repository.GitRepository
 
61
    _gitrepository_class = git_repository.GitRepository
70
62
 
71
 
    def __init__(self, transport, lockfiles, gitrepo, format):
 
63
    def __init__(self, transport, lockfiles, format):
72
64
        self._format = format
73
65
        self.root_transport = transport
74
 
        self._git = gitrepo
75
 
        if gitrepo.bare:
76
 
            self.transport = transport
77
 
        else:
78
 
            self.transport = transport.clone('.git')
 
66
        self.transport = transport.clone('.git')
79
67
        self._lockfiles = lockfiles
80
68
 
81
69
    def get_branch_transport(self, branch_format):
98
86
            head = None
99
87
        else:
100
88
            head = repo._git.heads[0].commit.id
101
 
        return branch.GitBranch(self, repo, head, 
 
89
        return git_branch.GitBranch(self, repo, head, 
102
90
                                    self.root_transport.base, self._lockfiles)
103
91
 
104
92
    def open_repository(self, shared=False):
106
94
        return self._gitrepository_class(self, self._lockfiles)
107
95
 
108
96
    def open_workingtree(self, recommend_upgrade=True):
109
 
        if self._git.bare:
110
 
            loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
111
 
            raise errors.bzr_errors.NoWorkingTree(loc)
112
 
        else:
113
 
            return workingtree.GitWorkingTree(self, self.open_repository(), 
114
 
                                                  self.open_branch())
115
 
 
116
 
    def cloning_metadir(self, stacked=False):
117
 
        if stacked:
118
 
            return bzrlib.bzrdir.format_registry.make_bzrdir("pack-0.92")
119
 
        else:
120
 
            return bzrlib.bzrdir.format_registry.make_bzrdir("1.6")
121
 
 
122
 
    def create_repository(self, shared=False):
123
 
        return self.open_repository()
 
97
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
 
98
        raise errors.bzr_errors.NoWorkingTree(loc)
 
99
 
 
100
    def cloning_metadir(self):
 
101
        return bzrdir.BzrDirFormat.get_default_format()
124
102
 
125
103
 
126
104
class GitBzrDirFormat(bzrdir.BzrDirFormat):
127
105
    """The .git directory control format."""
128
106
 
129
107
    _gitdir_class = GitDir
130
 
    _lock_class = TransportLock
131
108
 
132
109
    @classmethod
133
110
    def _known_formats(self):
134
111
        return set([GitBzrDirFormat()])
135
112
 
136
 
    def open(self, transport, _found=None):
 
113
    def open(self, transport, _create=False, _found=None):
137
114
        """Open this directory.
138
115
 
 
116
        :param _create: create the git dir on the fly. private to GitDirFormat.
139
117
        """
140
118
        # we dont grok readonly - git isn't integrated with transport.
141
119
        url = transport.base
142
120
        if url.startswith('readonly+'):
143
121
            url = url[len('readonly+'):]
144
 
 
145
 
        try:
146
 
            gitrepo = git.repo.Repo(transport.local_abspath("."))
147
 
        except errors.bzr_errors.NotLocalUrl:
 
122
        if not transport.has('.git'):
148
123
            raise errors.bzr_errors.NotBranchError(path=transport.base)
149
124
        lockfiles = GitLockableFiles(GitLock())
150
 
        return self._gitdir_class(transport, lockfiles, gitrepo, self)
 
125
        return self._gitdir_class(transport, lockfiles, self)
151
126
 
152
127
    @classmethod
153
128
    def probe_transport(klass, transport):
165
140
            raise errors.bzr_errors.NotBranchError(path=transport.base)
166
141
        raise errors.bzr_errors.NotBranchError(path=transport.base)
167
142
 
168
 
    def get_format_description(self):
169
 
        return "Local Git Repository"
170
 
 
171
 
    def get_format_string(self):
172
 
        return "Local Git Repository"
173
 
 
174
 
    def initialize_on_transport(self, transport):
175
 
        from bzrlib.transport.local import LocalTransport
176
 
 
177
 
        if not isinstance(transport, LocalTransport):
178
 
            raise NotImplementedError(self.initialize, 
179
 
                "Can't create Git Repositories/branches on "
180
 
                "non-local transports")
181
 
 
182
 
        git.repo.Repo.create(transport.local_abspath(".")) 
183
 
        return self.open(transport)
184
 
 
185
143
 
186
144
bzrdir.BzrDirFormat.register_control_format(GitBzrDirFormat)