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