81
84
class LocalGitDir(GitDir):
82
85
"""An adapter to the '.git' dir used by git."""
84
def _get_gitrepository_class(self):
85
from bzrlib.plugins.git.repository import LocalGitRepository
86
return LocalGitRepository
88
_gitrepository_class = property(_get_gitrepository_class)
87
_gitrepository_class = repository.LocalGitRepository
90
89
def __init__(self, transport, lockfiles, gitrepo, format):
91
90
self._format = format
106
105
return self.transport
107
106
if isinstance(branch_format, LocalGitBzrDirFormat):
108
107
return self.transport
109
raise bzr_errors.IncompatibleFormat(branch_format, self._format)
108
raise errors.bzr_errors.IncompatibleFormat(branch_format, self._format)
111
110
get_repository_transport = get_branch_transport
112
111
get_workingtree_transport = get_branch_transport
114
113
def open_branch(self, ignore_fallbacks=None):
115
114
"""'create' a branch for this dir."""
116
115
repo = self.open_repository()
117
from bzrlib.plugins.git.branch import LocalGitBranch
118
return LocalGitBranch(self, repo, "HEAD", self._lockfiles)
116
return branch.LocalGitBranch(self, repo, "HEAD", self._lockfiles)
120
118
def open_repository(self, shared=False):
121
119
"""'open' a repository for this dir."""
122
120
return self._gitrepository_class(self, self._lockfiles)
124
122
def open_workingtree(self, recommend_upgrade=True):
125
if not self._git.bare and self._git.has_index():
126
from bzrlib.plugins.git.workingtree import GitWorkingTree
127
return GitWorkingTree(self, self.open_repository(),
123
if (not self._git.bare and
124
os.path.exists(os.path.join(self._git.controldir(), "index"))):
125
return workingtree.GitWorkingTree(self, self.open_repository(),
128
126
self.open_branch())
129
127
loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
130
raise bzr_errors.NoWorkingTree(loc)
128
raise errors.bzr_errors.NoWorkingTree(loc)
132
130
def create_repository(self, shared=False):
133
131
return self.open_repository()
135
133
def create_branch(self):
136
134
return self.open_branch()
138
def backup_bzrdir(self):
140
self.root_transport.copy_tree(".git", ".git.backup")
141
return (self.root_transport.abspath(".git"),
142
self.root_transport.abspath(".git.backup"))
144
raise bzr_errors.BzrError("Unable to backup bare repositories")
146
def create_workingtree(self, revision_id=None, from_branch=None,
147
accelerator_tree=None, hardlink=False):
149
raise bzr_errors.BzrError("Can't create working tree in a bare repo")
150
from dulwich.index import write_index
151
from dulwich.pack import SHA1Writer
152
f = open(self.transport.local_abspath("index"), 'w+')
158
return self.open_workingtree()