Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
hggitforge
Commits
80595e0b7385
Commit
c9142ab4
authored
Oct 13, 2020
by
Elouan Martinet
Browse files
Move Git repository in .hg directory
parent
04f36a7bd971
Changes
1
Hide whitespace changes
Inline
Side-by-side
hggithub.py
View file @
80595e0b
...
...
@@ -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
(
"
\n
"
)
fobj
.
write
(
"[gitrepo]
\n
"
)
fobj
.
write
(
"gitrepo = {}
\n
"
.
format
(
git_repo
))
with
open
(
hgrc_path
,
"w+"
)
as
fobj
:
fobj
.
write
(
"""
\
[paths]
default = .hg/git.git
[gitrepo]
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):
)
else
:
os
.
mkdir
(
destination
)
os
.
mkdir
(
hg_repo
)
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
)
update_hgrc
(
destination
)
@
command
(
"ghclone"
,
[],
_
(
"git_path working_directory"
),
norepo
=
True
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment