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

Add a wrapper function for running commands

parent 62b4d4c14962
......@@ -8,24 +8,33 @@ import os.path as osp
from mercurial import registrar, error
from mercurial.i18n import _
from subprocess import call
from subprocess import check_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,
)
Markdown is supported
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