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
a9d2fa9ae783
Commit
b5e62957
authored
Oct 13, 2020
by
Alexandre Richardson
Committed by
Elouan Martinet
Oct 13, 2020
Browse files
Initial commit
parents
Changes
2
Hide whitespace changes
Inline
Side-by-side
.gitignore
0 → 100644
View file @
a9d2fa9a
__pycache__
*.pyc
hggithub.py
0 → 100644
View file @
a9d2fa9a
"""hggithub
Add some usefull command to work with github
"""
import
os
import
os.path
as
osp
from
mercurial
import
registrar
,
error
from
mercurial.i18n
import
_
from
subprocess
import
call
cmdtable
=
{}
command
=
registrar
.
command
(
cmdtable
)
def
git_clone
(
path_url
,
destination
):
ret_code
=
call
([
'git'
,
'clone'
,
path_url
,
destination
,
'--bare'
])
print
(
ret_code
)
def
hg_clone
(
path
,
destination
):
ret_code
=
call
([
'hg'
,
'clone'
,
path
,
destination
])
print
(
ret_code
)
ret_code
=
call
([
'hg'
,
'phase'
,
'-p'
,
'master'
],
cwd
=
destination
)
print
(
ret_code
)
def
update_hgrc
(
git_repo
,
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
))
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
)))
if
osp
.
isdir
(
destination
):
raise
ValueError
(
'Destination directory {} for hg repository should not exist'
.
format
(
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
)
@
command
(
'ghclone'
,
[],
_
(
'git_path working_directory'
),
norepo
=
True
)
def
ghclone
(
ui
,
git_url
,
working_directory
,
**
opts
):
"""Prepare working directory to work with github"""
_ghclone
(
git_url
,
working_directory
)
@
command
(
'ghpull'
,
[],
_
(
''
))
def
ghpull
(
ui
,
repo
,
**
opts
):
"""Prepare working directory to work with github"""
git_repo
=
ui
.
config
(
'gitrepo'
,
'gitrepo'
)
ret_code
=
call
([
'git'
,
'fetch'
,
'-q'
,
'origin'
,
'master:master'
],
cwd
=
git_repo
)
ret_code
=
call
([
'hg'
,
'pull'
])
ret_code
=
call
([
'hg'
,
'phase'
,
'-p'
,
'master'
])
@
command
(
'ghpush'
,
[],
_
(
'bookmark'
))
def
ghpush
(
ui
,
repo
,
bookmark
,
**
opts
):
"""Prepare working directory to work with github"""
git_repo
=
ui
.
config
(
'gitrepo'
,
'gitrepo'
)
ret_code
=
call
([
'hg'
,
'push'
,
'-B'
,
bookmark
,
'-f'
])
#ret_code = call(['git', 'push', '--set-upstream',
# 'origin', bookmark, '--force-with-lease'], cwd=git_repo)
ret_code
=
call
([
'git'
,
'push'
,
'--set-upstream'
,
'origin'
,
bookmark
,
'-f'
],
cwd
=
git_repo
)
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