Commit c9142ab4 authored by Elouan Martinet's avatar Elouan Martinet
Browse files

Move Git repository in .hg directory

parent 04f36a7bd971
......@@ -4,6 +4,7 @@ Add some usefull command to work with github
import os
import os.path as osp
from shutil import move
from mercurial import registrar, error
from mercurial.i18n import _
......@@ -37,18 +38,23 @@ def hg_clone(path, destination):
cmd("Publishing master bookmark", ["hg", "phase", "-p", "master"], cwd=destination)
def update_hgrc(git_repo, hg_repo):
def update_hgrc(hg_repo):
hgrc_path = osp.join(hg_repo, ".hg", "hgrc")
with open(hgrc_path, "a") as fobj:
fobj.write("gitrepo = {}\n".format(git_repo))
with open(hgrc_path, "w+") as fobj:
default = .hg/git.git
gitrepo = .hg/git.git
def _ghclone(path_url, destination):
project_name = osp.split(destination)[-1]
git_repo = osp.abspath(osp.join(destination, "git_{}".format(project_name)))
hg_repo = osp.abspath(osp.join(destination, "hg_{}".format(project_name)))
working_dir, project_name = osp.split(destination)
git_repo = osp.abspath(osp.join(working_dir, ".%s.git" % project_name))
if osp.isdir(destination):
raise ValueError(
"Destination directory {} for hg repository should not exist".format(
......@@ -57,10 +63,11 @@ def _ghclone(path_url, destination):
git_clone(path_url, git_repo)
hg_clone(git_repo, hg_repo)
update_hgrc(git_repo, hg_repo)
hg_clone(git_repo, destination)
final_git_repo = osp.abspath(osp.join(destination, ".hg", "git.git"))
move(git_repo, final_git_repo)
@command("ghclone", [], _("git_path working_directory"), norepo=True)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment