14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""An adapter between a Git control dir and a Bazaar BzrDir."""
17
"""An adapter between a Git control dir and a Bazaar BzrDir"""
22
from bzrlib.lazy_import import lazy_import
22
23
from bzrlib import (
28
LockWarner = getattr(lockable_files, "_LockWarner", None)
29
lazy_import(globals(), """
30
from bzrlib.lockable_files import (
30
33
from bzrlib.plugins.git import (
41
from bzrlib.plugins.git import LocalGitBzrDirFormat
40
45
class GitLock(object):
96
97
self.transport = transport.clone('.git')
97
98
self._lockfiles = lockfiles
98
self._mode_check_done = None
100
def is_control_filename(self, filename):
101
return filename == '.git' or filename.startswith('.git/')
103
100
def get_branch_transport(self, branch_format):
104
101
if branch_format is None:
110
107
get_repository_transport = get_branch_transport
111
108
get_workingtree_transport = get_branch_transport
113
def open_branch(self, ignore_fallbacks=None):
110
def open_branch(self, ignored=None):
114
111
"""'create' a branch for this dir."""
115
112
repo = self.open_repository()
116
return branch.LocalGitBranch(self, repo, "HEAD", self._lockfiles)
113
return branch.LocalGitBranch(self, repo, "HEAD", repo._git.head(), self._lockfiles)
118
115
def open_repository(self, shared=False):
119
116
"""'open' a repository for this dir."""
120
117
return self._gitrepository_class(self, self._lockfiles)
122
119
def open_workingtree(self, recommend_upgrade=True):
123
if not self._git.bare and self._git.has_index():
120
loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
121
raise errors.bzr_errors.NoWorkingTree(loc)
122
if (not self._git.bare and
123
os.path.exists(os.path.join(self._git.controldir(), "index"))):
124
124
return workingtree.GitWorkingTree(self, self.open_repository(),
125
125
self.open_branch())
126
loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
127
raise errors.bzr_errors.NoWorkingTree(loc)
129
127
def create_repository(self, shared=False):
130
128
return self.open_repository()
132
def create_branch(self):
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 errors.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 errors.bzr_errors.BzrError("Can't create working tree in a bare repo")
147
from dulwich.index import write_index
148
write_index(self.root_transport.abspath(".git/index"), [])
149
return self.open_workingtree()