Skip to content
Snippets Groups Projects
Commit 216426df9b7f authored by Georges Racinet's avatar Georges Racinet :squid:
Browse files

HeptapodGitHandler: Git repo move for native Mercurial now a separate method

We will soon make it called only when needed (not as part of the regular
`gitlab-mirror` command).
parent e298d64aee8d
No related branches found
No related tags found
1 merge request!110Native Mercurial: stop converting to Git by default
......@@ -63,8 +63,24 @@
if main_repo is None:
main_repo = self.repo
old_gitdir = re.sub(br'\.hg$', b'', main_repo.root) + b'.git'
self.gitdir = re.sub(br'\.hg$', b'', main_repo.root) + b'.git'
if self.repo.ui.configbool(b'heptapod', b'native'):
self.native_project_ensure_set_git_dir()
self.unfiltered_repo = self.repo.unfiltered()
self._default_git_ref = None
def native_project_ensure_set_git_dir(self):
"""Ensure existence of the auxiliary git repo for native Projects.
Even native Mercurial projects can have auxiliary Git repositories,
for mirroring to Git, although they are not alongside the Mercurial
repository and are managed in a different way (see heptapod#1963).
This makes sure that any Git repository for a native project is moved
over to the proper location.
"""
storages_root = self.repo.ui.config(b'heptapod', b'repositories-root')
git_repos_root = os.path.join(storages_root,
b'+hgitaly', b'hg-git')
os.makedirs(git_repos_root, mode=0o700, exist_ok=True)
......@@ -67,16 +83,9 @@
storages_root = self.repo.ui.config(b'heptapod', b'repositories-root')
git_repos_root = os.path.join(storages_root,
b'+hgitaly', b'hg-git')
os.makedirs(git_repos_root, mode=0o700, exist_ok=True)
if self.repo.ui.configbool(b'heptapod', b'native'):
rel_path = os.path.relpath(old_gitdir, storages_root)
self.gitdir = os.path.join(git_repos_root, rel_path)
os.makedirs(os.path.dirname(self.gitdir),
mode=0o700,
exist_ok=True)
if (
os.path.exists(old_gitdir)
and not os.path.exists(self.gitdir)
):
os.rename(old_gitdir, self.gitdir)
# After instantiation, `self.gitdir` is the proper one for
# legacy (hg-git based) projects
old_gitdir = self.gitdir
......@@ -82,4 +91,4 @@
else:
self.gitdir = old_gitdir
rel_path = os.path.relpath(old_gitdir, storages_root)
self.gitdir = os.path.join(git_repos_root, rel_path)
......@@ -85,6 +94,10 @@
self.unfiltered_repo = self.repo.unfiltered()
self._default_git_ref = None
os.makedirs(os.path.dirname(self.gitdir),
mode=0o700,
exist_ok=True)
if os.path.exists(old_gitdir) and not os.path.exists(self.gitdir):
os.rename(old_gitdir, self.gitdir)
@property
def gitlab_refs(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment