forked from schacon/hg-git
-
Notifications
You must be signed in to change notification settings - Fork 1
/
__init__.py
109 lines (92 loc) · 3.05 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# git.py - git server bridge
#
# Copyright 2008 Scott Chacon <schacon at gmail dot com>
# also some code (and help) borrowed from durin42
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
'''push and pull from a Git server
This extension lets you communicate (push and pull) with a Git server.
This way you can use Git hosting for your project or collaborate with a
project that is in Git. A bridger of worlds, this plugin be.
'''
from mercurial import commands
from mercurial import hg
from mercurial.i18n import _
from git_handler import GitHandler
# support for `hg clone git://github.com/defunkt/facebox.git`
import gitrepo
hg.schemes['git'] = gitrepo
def gclone(ui, git_url, hg_repo_path=None):
# determine new repo name
if not hg_repo_path:
hg_repo_path = hg.defaultdest(git_url)
if hg_repo_path.endswith('.git'):
hg_repo_path = hg_repo_path[:-4]
hg_repo_path += '-hg'
dest_repo = hg.repository(ui, hg_repo_path, create=True)
# fetch the initial git data
git = GitHandler(dest_repo, ui)
git.remote_add('origin', git_url)
git.fetch('origin')
# checkout the tip
node = git.remote_head('origin')
hg.update(dest_repo, node)
def gpush(ui, repo, remote_name='origin', branch=None):
git = GitHandler(repo, ui)
git.push(remote_name)
def gimport(ui, repo, remote_name=None):
git = GitHandler(repo, ui)
git.import_commits(remote_name)
def gexport(ui, repo):
git = GitHandler(repo, ui)
git.export_commits()
def gremote(ui, repo, *args):
git = GitHandler(repo, ui)
if len(args) == 0:
git.remote_list()
elif len(args) < 2:
repo.ui.warn(_("must supply an action and a remote\n"))
else:
verb = args[0]
nick = args[1]
if verb == 'add':
if len(args) == 3:
git.remote_add(nick, args[2])
else:
repo.ui.warn(_("must supply a url to add as a remote\n"))
elif verb == 'rm':
git.remote_remove(nick)
elif verb == 'show':
git.remote_show(nick)
else:
repo.ui.warn(_("unrecognized command to gremote\n"))
def gclear(ui, repo):
repo.ui.status(_("clearing out the git cache data\n"))
git = GitHandler(repo, ui)
git.clear()
def gfetch(ui, repo, remote_name='origin'):
repo.ui.status(_("pulling from git url\n"))
git = GitHandler(repo, ui)
git.fetch(remote_name)
commands.norepo += " gclone"
cmdtable = {
"gclone":
(gclone, [],
_('Clone a git repository into an hg repository.'),
),
"gpush":
(gpush, [], _('hg gpush remote')),
"gimport":
(gimport, [], _('hg gimport')),
"gexport":
(gexport, [], _('hg gexport')),
"gfetch":
(gfetch, [],
#[('m', 'merge', None, _('merge automatically'))],
_('hg gfetch remote')),
"gremote":
(gremote, [], _('hg gremote add remote (url)')),
"gclear":
(gclear, [], _('Clears out the Git cached data')),
}