61
67
_gitrepository_class = git_repository.GitRepository
63
def __init__(self, transport, lockfiles, format):
69
def __init__(self, transport, lockfiles, gitrepo, format):
64
70
self._format = format
65
71
self.root_transport = transport
66
self.transport = transport.clone('.git')
74
self.transport = transport
76
self.transport = transport.clone('.git')
67
77
self._lockfiles = lockfiles
69
79
def get_branch_transport(self, branch_format):
82
92
def open_branch(self, ignored=None):
83
"""'crate' a branch for this dir."""
84
return git_branch.GitBranch(self, self._lockfiles)
93
"""'create' a branch for this dir."""
94
repo = self.open_repository()
95
if repo._git.heads == []:
98
head = repo._git.heads[0].commit.id
99
return git_branch.GitBranch(self, repo, head,
100
self.root_transport.base, self._lockfiles)
86
102
def open_repository(self, shared=False):
87
103
"""'open' a repository for this dir."""
88
104
return self._gitrepository_class(self, self._lockfiles)
90
106
def open_workingtree(self, recommend_upgrade=True):
91
loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
92
raise errors.bzr_errors.NoWorkingTree(loc)
108
loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
109
raise errors.bzr_errors.NoWorkingTree(loc)
111
return git_workingtree.GitWorkingTree(self, self.open_repository(),
94
114
def cloning_metadir(self):
95
115
return bzrdir.BzrDirFormat.get_default_format()
104
124
def _known_formats(self):
105
125
return set([GitBzrDirFormat()])
107
def open(self, transport, _create=False, _found=None):
127
def open(self, transport, _found=None):
108
128
"""Open this directory.
110
:param _create: create the git dir on the fly. private to GitDirFormat.
112
131
# we dont grok readonly - git isn't integrated with transport.
113
132
url = transport.base
114
133
if url.startswith('readonly+'):
115
134
url = url[len('readonly+'):]
116
if not transport.has('.git'):
137
gitrepo = git.repo.Repo(transport.local_abspath("."))
138
except errors.bzr_errors.NotLocalUrl:
117
139
raise errors.bzr_errors.NotBranchError(path=transport.base)
118
140
lockfiles = GitLockableFiles(GitLock())
119
return self._gitdir_class(transport, lockfiles, self)
141
return self._gitdir_class(transport, lockfiles, gitrepo, self)
122
144
def probe_transport(klass, transport):
134
156
raise errors.bzr_errors.NotBranchError(path=transport.base)
135
157
raise errors.bzr_errors.NotBranchError(path=transport.base)
159
def get_format_description(self):
160
return "Local Git Repository"
138
163
bzrdir.BzrDirFormat.register_control_format(GitBzrDirFormat)