17
17
"""An adapter between a Git control dir and a Bazaar BzrDir"""
19
from bzrlib.lazy_import import lazy_import
20
19
from bzrlib import (
26
lazy_import(globals(), """
27
from bzrlib.plugins.git import (
26
from bzrlib.plugins.git.gitlib import (
35
32
class GitLock(object):
61
55
class GitDir(bzrdir.BzrDir):
62
56
"""An adapter to the '.git' dir used by git."""
64
_gitrepository_class = git_repository.GitRepository
66
58
def __init__(self, transport, lockfiles, format):
67
59
self._format = format
68
60
self.root_transport = transport
74
66
return self.transport
75
67
if isinstance(branch_format, GitBzrDirFormat):
76
68
return self.transport
77
raise errors.bzr_errors.IncompatibleFormat(branch_format, self._format)
69
raise errors.IncompatibleFormat(branch_format, self._format)
79
71
get_repository_transport = get_branch_transport
80
72
get_workingtree_transport = get_branch_transport
85
77
def open_branch(self, ignored=None):
86
"""'create' a branch for this dir."""
87
repo = self.open_repository()
88
if repo._git.heads == []:
91
head = repo._git.heads[0].commit.id
92
return git_branch.GitBranch(self, repo, head,
93
self.root_transport.base, self._lockfiles)
78
"""'crate' a branch for this dir."""
79
return git_branch.GitBranch(self, self._lockfiles)
95
81
def open_repository(self, shared=False):
96
82
"""'open' a repository for this dir."""
97
return self._gitrepository_class(self, self._lockfiles)
83
return git_repository.GitRepository(self, self._lockfiles)
99
def open_workingtree(self, recommend_upgrade=True):
85
def open_workingtree(self):
100
86
loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
101
raise errors.bzr_errors.NoWorkingTree(loc)
103
def cloning_metadir(self):
104
return bzrdir.BzrDirFormat.get_default_format()
87
raise errors.NoWorkingTree(loc)
107
90
class GitBzrDirFormat(bzrdir.BzrDirFormat):
108
91
"""The .git directory control format."""
110
_gitdir_class = GitDir
113
94
def _known_formats(self):
114
95
return set([GitBzrDirFormat()])
122
103
url = transport.base
123
104
if url.startswith('readonly+'):
124
105
url = url[len('readonly+'):]
106
path = urlutils.local_path_from_url(url)
125
107
if not transport.has('.git'):
126
raise errors.bzr_errors.NotBranchError(path=transport.base)
108
raise errors.NotBranchError(path=transport.base)
127
109
lockfiles = GitLockableFiles(GitLock())
128
return self._gitdir_class(transport, lockfiles, self)
110
return GitDir(transport, lockfiles, self)
131
113
def probe_transport(klass, transport):
140
122
format.open(transport)
142
124
except Exception, e:
143
raise errors.bzr_errors.NotBranchError(path=transport.base)
144
raise errors.bzr_errors.NotBranchError(path=transport.base)
146
def get_format_description(self):
147
return "Local Git Repository"
125
raise errors.NotBranchError(path=transport.base)
126
raise errors.NotBranchError(path=transport.base)
150
129
bzrdir.BzrDirFormat.register_control_format(GitBzrDirFormat)