Commit b5e62957 authored by Alexandre Richardson's avatar Alexandre Richardson Committed by Elouan Martinet
Browse files

Initial commit

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'])
def hg_clone(path, destination):
ret_code = call(['hg', 'clone', path, destination])
ret_code = call(['hg', 'phase', '-p', 'master'], cwd=destination)
def update_hgrc(git_repo, hg_repo):
hgrc_path = osp.join(hg_repo, '.hg', 'hgrc')
with open(hgrc_path, 'a') as fobj:
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))
git_clone(path_url, git_repo)
hg_clone(git_repo, hg_repo)
update_hgrc(git_repo, hg_repo)
_('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)
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'])
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)
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