/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

Basic support for opening working trees.

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
 
20
 
19
21
from bzrlib.lazy_import import lazy_import
20
22
from bzrlib import (
21
23
    bzrdir,
28
30
    errors,
29
31
    git_branch,
30
32
    git_repository,
 
33
    git_workingtree,
31
34
    )
32
35
""")
33
36
 
63
66
 
64
67
    _gitrepository_class = git_repository.GitRepository
65
68
 
66
 
    def __init__(self, transport, lockfiles, format):
 
69
    def __init__(self, transport, lockfiles, gitrepo, format):
67
70
        self._format = format
68
71
        self.root_transport = transport
69
 
        self.transport = transport.clone('.git')
 
72
        self._git = gitrepo
 
73
        if gitrepo.bare:
 
74
            self.transport = transport
 
75
        else:
 
76
            self.transport = transport.clone('.git')
70
77
        self._lockfiles = lockfiles
71
78
 
72
79
    def get_branch_transport(self, branch_format):
97
104
        return self._gitrepository_class(self, self._lockfiles)
98
105
 
99
106
    def open_workingtree(self, recommend_upgrade=True):
100
 
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
101
 
        raise errors.bzr_errors.NoWorkingTree(loc)
 
107
        if self._git.bare:
 
108
            loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
 
109
            raise errors.bzr_errors.NoWorkingTree(loc)
 
110
        else:
 
111
            return git_workingtree.GitWorkingTree(self, self.open_repository(), 
 
112
                                                  self.open_branch())
102
113
 
103
114
    def cloning_metadir(self):
104
115
        return bzrdir.BzrDirFormat.get_default_format()
113
124
    def _known_formats(self):
114
125
        return set([GitBzrDirFormat()])
115
126
 
116
 
    def open(self, transport, _create=False, _found=None):
 
127
    def open(self, transport, _found=None):
117
128
        """Open this directory.
118
129
 
119
 
        :param _create: create the git dir on the fly. private to GitDirFormat.
120
130
        """
121
131
        # we dont grok readonly - git isn't integrated with transport.
122
132
        url = transport.base
123
133
        if url.startswith('readonly+'):
124
134
            url = url[len('readonly+'):]
125
 
        if not transport.has('.git'):
 
135
 
 
136
        try:
 
137
            gitrepo = git.repo.Repo(transport.local_abspath("."))
 
138
        except errors.bzr_errors.NotLocalUrl:
126
139
            raise errors.bzr_errors.NotBranchError(path=transport.base)
127
140
        lockfiles = GitLockableFiles(GitLock())
128
 
        return self._gitdir_class(transport, lockfiles, self)
 
141
        return self._gitdir_class(transport, lockfiles, gitrepo, self)
129
142
 
130
143
    @classmethod
131
144
    def probe_transport(klass, transport):