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

Initial commit

parents
__pycache__
*.pyc
"""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)
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