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
04f36a7bd971
Commit
dee97db4
authored
Oct 13, 2020
by
Elouan Martinet
Browse files
Add a wrapper function for running commands
parent
62b4d4c14962
Changes
1
Hide whitespace changes
Inline
Side-by-side
hggithub.py
View file @
04f36a7b
...
...
@@ -8,24 +8,33 @@ import os.path as osp
from
mercurial
import
registrar
,
error
from
mercurial.i18n
import
_
from
subprocess
import
c
all
from
subprocess
import
c
heck_output
,
CalledProcessError
,
STDOUT
cmdtable
=
{}
command
=
registrar
.
command
(
cmdtable
)
def
cmd
(
description
,
*
args
,
**
kwargs
):
print
(
description
)
try
:
kwargs
[
"stderr"
]
=
STDOUT
check_output
(
*
args
,
**
kwargs
)
except
CalledProcessError
as
ex
:
print
(
ex
.
output
)
print
(
"Command exited with code %d"
%
ex
.
returncode
)
raise
def
git_clone
(
path_url
,
destination
):
ret_code
=
call
([
"git"
,
"clone"
,
path_url
,
destination
,
"--bare"
])
print
(
ret_code
)
cmd
(
"Cloning Git repository"
,
[
"git"
,
"clone"
,
path_url
,
destination
,
"--bare"
])
def
hg_clone
(
path
,
destination
):
ret_code
=
call
(
[
"hg"
,
"clone"
,
"--config"
,
"phases.new-commit=draft"
,
path
,
destination
]
cmd
(
"Creating Mercurial repository"
,
[
"hg"
,
"clone"
,
"--config"
,
"phases.new-commit=draft"
,
path
,
destination
],
)
print
(
ret_code
)
ret_code
=
call
([
"hg"
,
"phase"
,
"-p"
,
"master"
],
cwd
=
destination
)
print
(
ret_code
)
cmd
(
"Publishing master bookmark"
,
[
"hg"
,
"phase"
,
"-p"
,
"master"
],
cwd
=
destination
)
def
update_hgrc
(
git_repo
,
hg_repo
):
...
...
@@ -64,19 +73,25 @@ def ghclone(ui, git_url, working_directory, **opts):
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"
])
cmd
(
"Fetching remote Git repository"
,
[
"git"
,
"fetch"
,
"-q"
,
"origin"
,
"master:master"
],
cwd
=
git_repo
,
)
cmd
(
"Updating Mercurial repository"
,
[
"hg"
,
"pull"
])
cmd
(
"Publishing master bookmark"
,
[
"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
(
cmd
(
"Pushing bookmark to local Git repository"
,
[
"hg"
,
"push"
,
"-B"
,
bookmark
,
"-f"
]
)
# TODO use --force-with-lease if possible
cmd
(
"Publish Git branch to remote Git repository"
,
[
"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