##// END OF EJS Templates
githelp: format with %d if an integer...
Gregory Szorc -
r41460:873a28d7 default
parent child Browse files
Show More
@@ -1,1092 +1,1097 b''
1 # githelp.py - Try to map Git commands to Mercurial equivalents.
1 # githelp.py - Try to map Git commands to Mercurial equivalents.
2 #
2 #
3 # Copyright 2013 Facebook, Inc.
3 # Copyright 2013 Facebook, Inc.
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7 """try mapping git commands to Mercurial commands
7 """try mapping git commands to Mercurial commands
8
8
9 Tries to map a given git command to a Mercurial command:
9 Tries to map a given git command to a Mercurial command:
10
10
11 $ hg githelp -- git checkout master
11 $ hg githelp -- git checkout master
12 hg update master
12 hg update master
13
13
14 If an unknown command or parameter combination is detected, an error is
14 If an unknown command or parameter combination is detected, an error is
15 produced.
15 produced.
16 """
16 """
17
17
18 from __future__ import absolute_import
18 from __future__ import absolute_import
19
19
20 import getopt
20 import getopt
21 import re
21 import re
22
22
23 from mercurial.i18n import _
23 from mercurial.i18n import _
24 from mercurial import (
24 from mercurial import (
25 encoding,
25 encoding,
26 error,
26 error,
27 fancyopts,
27 fancyopts,
28 pycompat,
28 pycompat,
29 registrar,
29 registrar,
30 scmutil,
30 scmutil,
31 )
31 )
32 from mercurial.utils import (
32 from mercurial.utils import (
33 procutil,
33 procutil,
34 )
34 )
35
35
36 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
36 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
37 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
37 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
38 # be specifying the version(s) of Mercurial they are tested with, or
38 # be specifying the version(s) of Mercurial they are tested with, or
39 # leave the attribute unspecified.
39 # leave the attribute unspecified.
40 testedwith = 'ships-with-hg-core'
40 testedwith = 'ships-with-hg-core'
41
41
42 cmdtable = {}
42 cmdtable = {}
43 command = registrar.command(cmdtable)
43 command = registrar.command(cmdtable)
44
44
45 def convert(s):
45 def convert(s):
46 if s.startswith("origin/"):
46 if s.startswith("origin/"):
47 return s[7:]
47 return s[7:]
48 if 'HEAD' in s:
48 if 'HEAD' in s:
49 s = s.replace('HEAD', '.')
49 s = s.replace('HEAD', '.')
50 # HEAD~ in git is .~1 in mercurial
50 # HEAD~ in git is .~1 in mercurial
51 s = re.sub('~$', '~1', s)
51 s = re.sub('~$', '~1', s)
52 return s
52 return s
53
53
54 @command('githelp|git', [
54 @command('githelp|git', [
55 ], _('hg githelp'),
55 ], _('hg githelp'),
56 helpcategory=command.CATEGORY_HELP, helpbasic=True)
56 helpcategory=command.CATEGORY_HELP, helpbasic=True)
57 def githelp(ui, repo, *args, **kwargs):
57 def githelp(ui, repo, *args, **kwargs):
58 '''suggests the Mercurial equivalent of the given git command
58 '''suggests the Mercurial equivalent of the given git command
59
59
60 Usage: hg githelp -- <git command>
60 Usage: hg githelp -- <git command>
61 '''
61 '''
62
62
63 if len(args) == 0 or (len(args) == 1 and args[0] =='git'):
63 if len(args) == 0 or (len(args) == 1 and args[0] =='git'):
64 raise error.Abort(_('missing git command - '
64 raise error.Abort(_('missing git command - '
65 'usage: hg githelp -- <git command>'))
65 'usage: hg githelp -- <git command>'))
66
66
67 if args[0] == 'git':
67 if args[0] == 'git':
68 args = args[1:]
68 args = args[1:]
69
69
70 cmd = args[0]
70 cmd = args[0]
71 if not cmd in gitcommands:
71 if not cmd in gitcommands:
72 raise error.Abort(_("error: unknown git command %s") % (cmd))
72 raise error.Abort(_("error: unknown git command %s") % (cmd))
73
73
74 ui.pager('githelp')
74 ui.pager('githelp')
75 args = args[1:]
75 args = args[1:]
76 return gitcommands[cmd](ui, repo, *args, **kwargs)
76 return gitcommands[cmd](ui, repo, *args, **kwargs)
77
77
78 def parseoptions(ui, cmdoptions, args):
78 def parseoptions(ui, cmdoptions, args):
79 cmdoptions = list(cmdoptions)
79 cmdoptions = list(cmdoptions)
80 opts = {}
80 opts = {}
81 args = list(args)
81 args = list(args)
82 while True:
82 while True:
83 try:
83 try:
84 args = fancyopts.fancyopts(list(args), cmdoptions, opts, True)
84 args = fancyopts.fancyopts(list(args), cmdoptions, opts, True)
85 break
85 break
86 except getopt.GetoptError as ex:
86 except getopt.GetoptError as ex:
87 if r"requires argument" in ex.msg:
87 if r"requires argument" in ex.msg:
88 raise
88 raise
89 if (r'--' + ex.opt) in ex.msg:
89 if (r'--' + ex.opt) in ex.msg:
90 flag = '--' + pycompat.bytestr(ex.opt)
90 flag = '--' + pycompat.bytestr(ex.opt)
91 elif (r'-' + ex.opt) in ex.msg:
91 elif (r'-' + ex.opt) in ex.msg:
92 flag = '-' + pycompat.bytestr(ex.opt)
92 flag = '-' + pycompat.bytestr(ex.opt)
93 else:
93 else:
94 raise error.Abort(_("unknown option %s") %
94 raise error.Abort(_("unknown option %s") %
95 pycompat.bytestr(ex.opt))
95 pycompat.bytestr(ex.opt))
96 try:
96 try:
97 args.remove(flag)
97 args.remove(flag)
98 except Exception:
98 except Exception:
99 msg = _("unknown option '%s' packed with other options")
99 msg = _("unknown option '%s' packed with other options")
100 hint = _("please try passing the option as its own flag: -%s")
100 hint = _("please try passing the option as its own flag: -%s")
101 raise error.Abort(msg % pycompat.bytestr(ex.opt),
101 raise error.Abort(msg % pycompat.bytestr(ex.opt),
102 hint=hint % pycompat.bytestr(ex.opt))
102 hint=hint % pycompat.bytestr(ex.opt))
103
103
104 ui.warn(_("ignoring unknown option %s\n") % flag)
104 ui.warn(_("ignoring unknown option %s\n") % flag)
105
105
106 args = list([convert(x) for x in args])
106 args = list([convert(x) for x in args])
107 opts = dict([(k, convert(v)) if isinstance(v, str) else (k, v)
107 opts = dict([(k, convert(v)) if isinstance(v, str) else (k, v)
108 for k, v in opts.iteritems()])
108 for k, v in opts.iteritems()])
109
109
110 return args, opts
110 return args, opts
111
111
112 class Command(object):
112 class Command(object):
113 def __init__(self, name):
113 def __init__(self, name):
114 self.name = name
114 self.name = name
115 self.args = []
115 self.args = []
116 self.opts = {}
116 self.opts = {}
117
117
118 def __bytes__(self):
118 def __bytes__(self):
119 cmd = "hg " + self.name
119 cmd = "hg " + self.name
120 if self.opts:
120 if self.opts:
121 for k, values in sorted(self.opts.iteritems()):
121 for k, values in sorted(self.opts.iteritems()):
122 for v in values:
122 for v in values:
123 if v:
123 if v:
124 cmd += " %s %s" % (k, v)
124 if isinstance(v, int):
125 fmt = ' %s %d'
126 else:
127 fmt = ' %s %s'
128
129 cmd += fmt % (k, v)
125 else:
130 else:
126 cmd += " %s" % (k,)
131 cmd += " %s" % (k,)
127 if self.args:
132 if self.args:
128 cmd += " "
133 cmd += " "
129 cmd += " ".join(self.args)
134 cmd += " ".join(self.args)
130 return cmd
135 return cmd
131
136
132 __str__ = encoding.strmethod(__bytes__)
137 __str__ = encoding.strmethod(__bytes__)
133
138
134 def append(self, value):
139 def append(self, value):
135 self.args.append(value)
140 self.args.append(value)
136
141
137 def extend(self, values):
142 def extend(self, values):
138 self.args.extend(values)
143 self.args.extend(values)
139
144
140 def __setitem__(self, key, value):
145 def __setitem__(self, key, value):
141 values = self.opts.setdefault(key, [])
146 values = self.opts.setdefault(key, [])
142 values.append(value)
147 values.append(value)
143
148
144 def __and__(self, other):
149 def __and__(self, other):
145 return AndCommand(self, other)
150 return AndCommand(self, other)
146
151
147 class AndCommand(object):
152 class AndCommand(object):
148 def __init__(self, left, right):
153 def __init__(self, left, right):
149 self.left = left
154 self.left = left
150 self.right = right
155 self.right = right
151
156
152 def __str__(self):
157 def __str__(self):
153 return "%s && %s" % (self.left, self.right)
158 return "%s && %s" % (self.left, self.right)
154
159
155 def __and__(self, other):
160 def __and__(self, other):
156 return AndCommand(self, other)
161 return AndCommand(self, other)
157
162
158 def add(ui, repo, *args, **kwargs):
163 def add(ui, repo, *args, **kwargs):
159 cmdoptions = [
164 cmdoptions = [
160 ('A', 'all', None, ''),
165 ('A', 'all', None, ''),
161 ('p', 'patch', None, ''),
166 ('p', 'patch', None, ''),
162 ]
167 ]
163 args, opts = parseoptions(ui, cmdoptions, args)
168 args, opts = parseoptions(ui, cmdoptions, args)
164
169
165 if (opts.get('patch')):
170 if (opts.get('patch')):
166 ui.status(_("note: Mercurial will commit when complete, "
171 ui.status(_("note: Mercurial will commit when complete, "
167 "as there is no staging area in Mercurial\n\n"))
172 "as there is no staging area in Mercurial\n\n"))
168 cmd = Command('commit --interactive')
173 cmd = Command('commit --interactive')
169 else:
174 else:
170 cmd = Command("add")
175 cmd = Command("add")
171
176
172 if not opts.get('all'):
177 if not opts.get('all'):
173 cmd.extend(args)
178 cmd.extend(args)
174 else:
179 else:
175 ui.status(_("note: use hg addremove to remove files that have "
180 ui.status(_("note: use hg addremove to remove files that have "
176 "been deleted\n\n"))
181 "been deleted\n\n"))
177
182
178 ui.status((bytes(cmd)), "\n")
183 ui.status((bytes(cmd)), "\n")
179
184
180 def am(ui, repo, *args, **kwargs):
185 def am(ui, repo, *args, **kwargs):
181 cmdoptions=[
186 cmdoptions=[
182 ]
187 ]
183 args, opts = parseoptions(ui, cmdoptions, args)
188 args, opts = parseoptions(ui, cmdoptions, args)
184 cmd = Command('import')
189 cmd = Command('import')
185 ui.status(bytes(cmd), "\n")
190 ui.status(bytes(cmd), "\n")
186
191
187 def apply(ui, repo, *args, **kwargs):
192 def apply(ui, repo, *args, **kwargs):
188 cmdoptions = [
193 cmdoptions = [
189 ('p', 'p', int, ''),
194 ('p', 'p', int, ''),
190 ]
195 ]
191 args, opts = parseoptions(ui, cmdoptions, args)
196 args, opts = parseoptions(ui, cmdoptions, args)
192
197
193 cmd = Command('import --no-commit')
198 cmd = Command('import --no-commit')
194 if (opts.get('p')):
199 if (opts.get('p')):
195 cmd['-p'] = opts.get('p')
200 cmd['-p'] = opts.get('p')
196 cmd.extend(args)
201 cmd.extend(args)
197
202
198 ui.status((bytes(cmd)), "\n")
203 ui.status((bytes(cmd)), "\n")
199
204
200 def bisect(ui, repo, *args, **kwargs):
205 def bisect(ui, repo, *args, **kwargs):
201 ui.status(_("see 'hg help bisect' for how to use bisect\n\n"))
206 ui.status(_("see 'hg help bisect' for how to use bisect\n\n"))
202
207
203 def blame(ui, repo, *args, **kwargs):
208 def blame(ui, repo, *args, **kwargs):
204 cmdoptions = [
209 cmdoptions = [
205 ]
210 ]
206 args, opts = parseoptions(ui, cmdoptions, args)
211 args, opts = parseoptions(ui, cmdoptions, args)
207 cmd = Command('annotate -udl')
212 cmd = Command('annotate -udl')
208 cmd.extend([convert(v) for v in args])
213 cmd.extend([convert(v) for v in args])
209 ui.status((bytes(cmd)), "\n")
214 ui.status((bytes(cmd)), "\n")
210
215
211 def branch(ui, repo, *args, **kwargs):
216 def branch(ui, repo, *args, **kwargs):
212 cmdoptions = [
217 cmdoptions = [
213 ('', 'set-upstream', None, ''),
218 ('', 'set-upstream', None, ''),
214 ('', 'set-upstream-to', '', ''),
219 ('', 'set-upstream-to', '', ''),
215 ('d', 'delete', None, ''),
220 ('d', 'delete', None, ''),
216 ('D', 'delete', None, ''),
221 ('D', 'delete', None, ''),
217 ('m', 'move', None, ''),
222 ('m', 'move', None, ''),
218 ('M', 'move', None, ''),
223 ('M', 'move', None, ''),
219 ]
224 ]
220 args, opts = parseoptions(ui, cmdoptions, args)
225 args, opts = parseoptions(ui, cmdoptions, args)
221
226
222 cmd = Command("bookmark")
227 cmd = Command("bookmark")
223
228
224 if opts.get('set_upstream') or opts.get('set_upstream_to'):
229 if opts.get('set_upstream') or opts.get('set_upstream_to'):
225 ui.status(_("Mercurial has no concept of upstream branches\n"))
230 ui.status(_("Mercurial has no concept of upstream branches\n"))
226 return
231 return
227 elif opts.get('delete'):
232 elif opts.get('delete'):
228 cmd = Command("strip")
233 cmd = Command("strip")
229 for branch in args:
234 for branch in args:
230 cmd['-B'] = branch
235 cmd['-B'] = branch
231 else:
236 else:
232 cmd['-B'] = None
237 cmd['-B'] = None
233 elif opts.get('move'):
238 elif opts.get('move'):
234 if len(args) > 0:
239 if len(args) > 0:
235 if len(args) > 1:
240 if len(args) > 1:
236 old = args.pop(0)
241 old = args.pop(0)
237 else:
242 else:
238 # shell command to output the active bookmark for the active
243 # shell command to output the active bookmark for the active
239 # revision
244 # revision
240 old = '`hg log -T"{activebookmark}" -r .`'
245 old = '`hg log -T"{activebookmark}" -r .`'
241 else:
246 else:
242 raise error.Abort(_('missing newbranch argument'))
247 raise error.Abort(_('missing newbranch argument'))
243 new = args[0]
248 new = args[0]
244 cmd['-m'] = old
249 cmd['-m'] = old
245 cmd.append(new)
250 cmd.append(new)
246 else:
251 else:
247 if len(args) > 1:
252 if len(args) > 1:
248 cmd['-r'] = args[1]
253 cmd['-r'] = args[1]
249 cmd.append(args[0])
254 cmd.append(args[0])
250 elif len(args) == 1:
255 elif len(args) == 1:
251 cmd.append(args[0])
256 cmd.append(args[0])
252 ui.status((bytes(cmd)), "\n")
257 ui.status((bytes(cmd)), "\n")
253
258
254 def ispath(repo, string):
259 def ispath(repo, string):
255 """
260 """
256 The first argument to git checkout can either be a revision or a path. Let's
261 The first argument to git checkout can either be a revision or a path. Let's
257 generally assume it's a revision, unless it's obviously a path. There are
262 generally assume it's a revision, unless it's obviously a path. There are
258 too many ways to spell revisions in git for us to reasonably catch all of
263 too many ways to spell revisions in git for us to reasonably catch all of
259 them, so let's be conservative.
264 them, so let's be conservative.
260 """
265 """
261 if scmutil.isrevsymbol(repo, string):
266 if scmutil.isrevsymbol(repo, string):
262 # if it's definitely a revision let's not even check if a file of the
267 # if it's definitely a revision let's not even check if a file of the
263 # same name exists.
268 # same name exists.
264 return False
269 return False
265
270
266 cwd = repo.getcwd()
271 cwd = repo.getcwd()
267 if cwd == '':
272 if cwd == '':
268 repopath = string
273 repopath = string
269 else:
274 else:
270 repopath = cwd + '/' + string
275 repopath = cwd + '/' + string
271
276
272 exists = repo.wvfs.exists(repopath)
277 exists = repo.wvfs.exists(repopath)
273 if exists:
278 if exists:
274 return True
279 return True
275
280
276 manifest = repo['.'].manifest()
281 manifest = repo['.'].manifest()
277
282
278 didexist = (repopath in manifest) or manifest.hasdir(repopath)
283 didexist = (repopath in manifest) or manifest.hasdir(repopath)
279
284
280 return didexist
285 return didexist
281
286
282 def checkout(ui, repo, *args, **kwargs):
287 def checkout(ui, repo, *args, **kwargs):
283 cmdoptions = [
288 cmdoptions = [
284 ('b', 'branch', '', ''),
289 ('b', 'branch', '', ''),
285 ('B', 'branch', '', ''),
290 ('B', 'branch', '', ''),
286 ('f', 'force', None, ''),
291 ('f', 'force', None, ''),
287 ('p', 'patch', None, ''),
292 ('p', 'patch', None, ''),
288 ]
293 ]
289 paths = []
294 paths = []
290 if '--' in args:
295 if '--' in args:
291 sepindex = args.index('--')
296 sepindex = args.index('--')
292 paths.extend(args[sepindex + 1:])
297 paths.extend(args[sepindex + 1:])
293 args = args[:sepindex]
298 args = args[:sepindex]
294
299
295 args, opts = parseoptions(ui, cmdoptions, args)
300 args, opts = parseoptions(ui, cmdoptions, args)
296
301
297 rev = None
302 rev = None
298 if args and ispath(repo, args[0]):
303 if args and ispath(repo, args[0]):
299 paths = args + paths
304 paths = args + paths
300 elif args:
305 elif args:
301 rev = args[0]
306 rev = args[0]
302 paths = args[1:] + paths
307 paths = args[1:] + paths
303
308
304 cmd = Command('update')
309 cmd = Command('update')
305
310
306 if opts.get('force'):
311 if opts.get('force'):
307 if paths or rev:
312 if paths or rev:
308 cmd['-C'] = None
313 cmd['-C'] = None
309
314
310 if opts.get('patch'):
315 if opts.get('patch'):
311 cmd = Command('revert')
316 cmd = Command('revert')
312 cmd['-i'] = None
317 cmd['-i'] = None
313
318
314 if opts.get('branch'):
319 if opts.get('branch'):
315 if len(args) == 0:
320 if len(args) == 0:
316 cmd = Command('bookmark')
321 cmd = Command('bookmark')
317 cmd.append(opts.get('branch'))
322 cmd.append(opts.get('branch'))
318 else:
323 else:
319 cmd.append(args[0])
324 cmd.append(args[0])
320 bookcmd = Command('bookmark')
325 bookcmd = Command('bookmark')
321 bookcmd.append(opts.get('branch'))
326 bookcmd.append(opts.get('branch'))
322 cmd = cmd & bookcmd
327 cmd = cmd & bookcmd
323 # if there is any path argument supplied, use revert instead of update
328 # if there is any path argument supplied, use revert instead of update
324 elif len(paths) > 0:
329 elif len(paths) > 0:
325 ui.status(_("note: use --no-backup to avoid creating .orig files\n\n"))
330 ui.status(_("note: use --no-backup to avoid creating .orig files\n\n"))
326 cmd = Command('revert')
331 cmd = Command('revert')
327 if opts.get('patch'):
332 if opts.get('patch'):
328 cmd['-i'] = None
333 cmd['-i'] = None
329 if rev:
334 if rev:
330 cmd['-r'] = rev
335 cmd['-r'] = rev
331 cmd.extend(paths)
336 cmd.extend(paths)
332 elif rev:
337 elif rev:
333 if opts.get('patch'):
338 if opts.get('patch'):
334 cmd['-r'] = rev
339 cmd['-r'] = rev
335 else:
340 else:
336 cmd.append(rev)
341 cmd.append(rev)
337 elif opts.get('force'):
342 elif opts.get('force'):
338 cmd = Command('revert')
343 cmd = Command('revert')
339 cmd['--all'] = None
344 cmd['--all'] = None
340 else:
345 else:
341 raise error.Abort(_("a commit must be specified"))
346 raise error.Abort(_("a commit must be specified"))
342
347
343 ui.status((bytes(cmd)), "\n")
348 ui.status((bytes(cmd)), "\n")
344
349
345 def cherrypick(ui, repo, *args, **kwargs):
350 def cherrypick(ui, repo, *args, **kwargs):
346 cmdoptions = [
351 cmdoptions = [
347 ('', 'continue', None, ''),
352 ('', 'continue', None, ''),
348 ('', 'abort', None, ''),
353 ('', 'abort', None, ''),
349 ('e', 'edit', None, ''),
354 ('e', 'edit', None, ''),
350 ]
355 ]
351 args, opts = parseoptions(ui, cmdoptions, args)
356 args, opts = parseoptions(ui, cmdoptions, args)
352
357
353 cmd = Command('graft')
358 cmd = Command('graft')
354
359
355 if opts.get('edit'):
360 if opts.get('edit'):
356 cmd['--edit'] = None
361 cmd['--edit'] = None
357 if opts.get('continue'):
362 if opts.get('continue'):
358 cmd['--continue'] = None
363 cmd['--continue'] = None
359 elif opts.get('abort'):
364 elif opts.get('abort'):
360 ui.status(_("note: hg graft does not have --abort\n\n"))
365 ui.status(_("note: hg graft does not have --abort\n\n"))
361 return
366 return
362 else:
367 else:
363 cmd.extend(args)
368 cmd.extend(args)
364
369
365 ui.status((bytes(cmd)), "\n")
370 ui.status((bytes(cmd)), "\n")
366
371
367 def clean(ui, repo, *args, **kwargs):
372 def clean(ui, repo, *args, **kwargs):
368 cmdoptions = [
373 cmdoptions = [
369 ('d', 'd', None, ''),
374 ('d', 'd', None, ''),
370 ('f', 'force', None, ''),
375 ('f', 'force', None, ''),
371 ('x', 'x', None, ''),
376 ('x', 'x', None, ''),
372 ]
377 ]
373 args, opts = parseoptions(ui, cmdoptions, args)
378 args, opts = parseoptions(ui, cmdoptions, args)
374
379
375 cmd = Command('purge')
380 cmd = Command('purge')
376 if opts.get('x'):
381 if opts.get('x'):
377 cmd['--all'] = None
382 cmd['--all'] = None
378 cmd.extend(args)
383 cmd.extend(args)
379
384
380 ui.status((bytes(cmd)), "\n")
385 ui.status((bytes(cmd)), "\n")
381
386
382 def clone(ui, repo, *args, **kwargs):
387 def clone(ui, repo, *args, **kwargs):
383 cmdoptions = [
388 cmdoptions = [
384 ('', 'bare', None, ''),
389 ('', 'bare', None, ''),
385 ('n', 'no-checkout', None, ''),
390 ('n', 'no-checkout', None, ''),
386 ('b', 'branch', '', ''),
391 ('b', 'branch', '', ''),
387 ]
392 ]
388 args, opts = parseoptions(ui, cmdoptions, args)
393 args, opts = parseoptions(ui, cmdoptions, args)
389
394
390 if len(args) == 0:
395 if len(args) == 0:
391 raise error.Abort(_("a repository to clone must be specified"))
396 raise error.Abort(_("a repository to clone must be specified"))
392
397
393 cmd = Command('clone')
398 cmd = Command('clone')
394 cmd.append(args[0])
399 cmd.append(args[0])
395 if len(args) > 1:
400 if len(args) > 1:
396 cmd.append(args[1])
401 cmd.append(args[1])
397
402
398 if opts.get('bare'):
403 if opts.get('bare'):
399 cmd['-U'] = None
404 cmd['-U'] = None
400 ui.status(_("note: Mercurial does not have bare clones. "
405 ui.status(_("note: Mercurial does not have bare clones. "
401 "-U will clone the repo without checking out a commit\n\n"))
406 "-U will clone the repo without checking out a commit\n\n"))
402 elif opts.get('no_checkout'):
407 elif opts.get('no_checkout'):
403 cmd['-U'] = None
408 cmd['-U'] = None
404
409
405 if opts.get('branch'):
410 if opts.get('branch'):
406 cocmd = Command("update")
411 cocmd = Command("update")
407 cocmd.append(opts.get('branch'))
412 cocmd.append(opts.get('branch'))
408 cmd = cmd & cocmd
413 cmd = cmd & cocmd
409
414
410 ui.status((bytes(cmd)), "\n")
415 ui.status((bytes(cmd)), "\n")
411
416
412 def commit(ui, repo, *args, **kwargs):
417 def commit(ui, repo, *args, **kwargs):
413 cmdoptions = [
418 cmdoptions = [
414 ('a', 'all', None, ''),
419 ('a', 'all', None, ''),
415 ('m', 'message', '', ''),
420 ('m', 'message', '', ''),
416 ('p', 'patch', None, ''),
421 ('p', 'patch', None, ''),
417 ('C', 'reuse-message', '', ''),
422 ('C', 'reuse-message', '', ''),
418 ('F', 'file', '', ''),
423 ('F', 'file', '', ''),
419 ('', 'author', '', ''),
424 ('', 'author', '', ''),
420 ('', 'date', '', ''),
425 ('', 'date', '', ''),
421 ('', 'amend', None, ''),
426 ('', 'amend', None, ''),
422 ('', 'no-edit', None, ''),
427 ('', 'no-edit', None, ''),
423 ]
428 ]
424 args, opts = parseoptions(ui, cmdoptions, args)
429 args, opts = parseoptions(ui, cmdoptions, args)
425
430
426 cmd = Command('commit')
431 cmd = Command('commit')
427 if opts.get('patch'):
432 if opts.get('patch'):
428 cmd = Command('commit --interactive')
433 cmd = Command('commit --interactive')
429
434
430 if opts.get('amend'):
435 if opts.get('amend'):
431 if opts.get('no_edit'):
436 if opts.get('no_edit'):
432 cmd = Command('amend')
437 cmd = Command('amend')
433 else:
438 else:
434 cmd['--amend'] = None
439 cmd['--amend'] = None
435
440
436 if opts.get('reuse_message'):
441 if opts.get('reuse_message'):
437 cmd['-M'] = opts.get('reuse_message')
442 cmd['-M'] = opts.get('reuse_message')
438
443
439 if opts.get('message'):
444 if opts.get('message'):
440 cmd['-m'] = "'%s'" % (opts.get('message'),)
445 cmd['-m'] = "'%s'" % (opts.get('message'),)
441
446
442 if opts.get('all'):
447 if opts.get('all'):
443 ui.status(_("note: Mercurial doesn't have a staging area, "
448 ui.status(_("note: Mercurial doesn't have a staging area, "
444 "so there is no --all. -A will add and remove files "
449 "so there is no --all. -A will add and remove files "
445 "for you though.\n\n"))
450 "for you though.\n\n"))
446
451
447 if opts.get('file'):
452 if opts.get('file'):
448 cmd['-l'] = opts.get('file')
453 cmd['-l'] = opts.get('file')
449
454
450 if opts.get('author'):
455 if opts.get('author'):
451 cmd['-u'] = opts.get('author')
456 cmd['-u'] = opts.get('author')
452
457
453 if opts.get('date'):
458 if opts.get('date'):
454 cmd['-d'] = opts.get('date')
459 cmd['-d'] = opts.get('date')
455
460
456 cmd.extend(args)
461 cmd.extend(args)
457
462
458 ui.status((bytes(cmd)), "\n")
463 ui.status((bytes(cmd)), "\n")
459
464
460 def deprecated(ui, repo, *args, **kwargs):
465 def deprecated(ui, repo, *args, **kwargs):
461 ui.warn(_('this command has been deprecated in the git project, '
466 ui.warn(_('this command has been deprecated in the git project, '
462 'thus isn\'t supported by this tool\n\n'))
467 'thus isn\'t supported by this tool\n\n'))
463
468
464 def diff(ui, repo, *args, **kwargs):
469 def diff(ui, repo, *args, **kwargs):
465 cmdoptions = [
470 cmdoptions = [
466 ('a', 'all', None, ''),
471 ('a', 'all', None, ''),
467 ('', 'cached', None, ''),
472 ('', 'cached', None, ''),
468 ('R', 'reverse', None, ''),
473 ('R', 'reverse', None, ''),
469 ]
474 ]
470 args, opts = parseoptions(ui, cmdoptions, args)
475 args, opts = parseoptions(ui, cmdoptions, args)
471
476
472 cmd = Command('diff')
477 cmd = Command('diff')
473
478
474 if opts.get('cached'):
479 if opts.get('cached'):
475 ui.status(_('note: Mercurial has no concept of a staging area, '
480 ui.status(_('note: Mercurial has no concept of a staging area, '
476 'so --cached does nothing\n\n'))
481 'so --cached does nothing\n\n'))
477
482
478 if opts.get('reverse'):
483 if opts.get('reverse'):
479 cmd['--reverse'] = None
484 cmd['--reverse'] = None
480
485
481 for a in list(args):
486 for a in list(args):
482 args.remove(a)
487 args.remove(a)
483 try:
488 try:
484 repo.revs(a)
489 repo.revs(a)
485 cmd['-r'] = a
490 cmd['-r'] = a
486 except Exception:
491 except Exception:
487 cmd.append(a)
492 cmd.append(a)
488
493
489 ui.status((bytes(cmd)), "\n")
494 ui.status((bytes(cmd)), "\n")
490
495
491 def difftool(ui, repo, *args, **kwargs):
496 def difftool(ui, repo, *args, **kwargs):
492 ui.status(_('Mercurial does not enable external difftool by default. You '
497 ui.status(_('Mercurial does not enable external difftool by default. You '
493 'need to enable the extdiff extension in your .hgrc file by adding\n'
498 'need to enable the extdiff extension in your .hgrc file by adding\n'
494 'extdiff =\n'
499 'extdiff =\n'
495 'to the [extensions] section and then running\n\n'
500 'to the [extensions] section and then running\n\n'
496 'hg extdiff -p <program>\n\n'
501 'hg extdiff -p <program>\n\n'
497 'See \'hg help extdiff\' and \'hg help -e extdiff\' for more '
502 'See \'hg help extdiff\' and \'hg help -e extdiff\' for more '
498 'information.\n'))
503 'information.\n'))
499
504
500 def fetch(ui, repo, *args, **kwargs):
505 def fetch(ui, repo, *args, **kwargs):
501 cmdoptions = [
506 cmdoptions = [
502 ('', 'all', None, ''),
507 ('', 'all', None, ''),
503 ('f', 'force', None, ''),
508 ('f', 'force', None, ''),
504 ]
509 ]
505 args, opts = parseoptions(ui, cmdoptions, args)
510 args, opts = parseoptions(ui, cmdoptions, args)
506
511
507 cmd = Command('pull')
512 cmd = Command('pull')
508
513
509 if len(args) > 0:
514 if len(args) > 0:
510 cmd.append(args[0])
515 cmd.append(args[0])
511 if len(args) > 1:
516 if len(args) > 1:
512 ui.status(_("note: Mercurial doesn't have refspecs. "
517 ui.status(_("note: Mercurial doesn't have refspecs. "
513 "-r can be used to specify which commits you want to "
518 "-r can be used to specify which commits you want to "
514 "pull. -B can be used to specify which bookmark you "
519 "pull. -B can be used to specify which bookmark you "
515 "want to pull.\n\n"))
520 "want to pull.\n\n"))
516 for v in args[1:]:
521 for v in args[1:]:
517 if v in repo._bookmarks:
522 if v in repo._bookmarks:
518 cmd['-B'] = v
523 cmd['-B'] = v
519 else:
524 else:
520 cmd['-r'] = v
525 cmd['-r'] = v
521
526
522 ui.status((bytes(cmd)), "\n")
527 ui.status((bytes(cmd)), "\n")
523
528
524 def grep(ui, repo, *args, **kwargs):
529 def grep(ui, repo, *args, **kwargs):
525 cmdoptions = [
530 cmdoptions = [
526 ]
531 ]
527 args, opts = parseoptions(ui, cmdoptions, args)
532 args, opts = parseoptions(ui, cmdoptions, args)
528
533
529 cmd = Command('grep')
534 cmd = Command('grep')
530
535
531 # For basic usage, git grep and hg grep are the same. They both have the
536 # For basic usage, git grep and hg grep are the same. They both have the
532 # pattern first, followed by paths.
537 # pattern first, followed by paths.
533 cmd.extend(args)
538 cmd.extend(args)
534
539
535 ui.status((bytes(cmd)), "\n")
540 ui.status((bytes(cmd)), "\n")
536
541
537 def init(ui, repo, *args, **kwargs):
542 def init(ui, repo, *args, **kwargs):
538 cmdoptions = [
543 cmdoptions = [
539 ]
544 ]
540 args, opts = parseoptions(ui, cmdoptions, args)
545 args, opts = parseoptions(ui, cmdoptions, args)
541
546
542 cmd = Command('init')
547 cmd = Command('init')
543
548
544 if len(args) > 0:
549 if len(args) > 0:
545 cmd.append(args[0])
550 cmd.append(args[0])
546
551
547 ui.status((bytes(cmd)), "\n")
552 ui.status((bytes(cmd)), "\n")
548
553
549 def log(ui, repo, *args, **kwargs):
554 def log(ui, repo, *args, **kwargs):
550 cmdoptions = [
555 cmdoptions = [
551 ('', 'follow', None, ''),
556 ('', 'follow', None, ''),
552 ('', 'decorate', None, ''),
557 ('', 'decorate', None, ''),
553 ('n', 'number', '', ''),
558 ('n', 'number', '', ''),
554 ('1', '1', None, ''),
559 ('1', '1', None, ''),
555 ('', 'pretty', '', ''),
560 ('', 'pretty', '', ''),
556 ('', 'format', '', ''),
561 ('', 'format', '', ''),
557 ('', 'oneline', None, ''),
562 ('', 'oneline', None, ''),
558 ('', 'stat', None, ''),
563 ('', 'stat', None, ''),
559 ('', 'graph', None, ''),
564 ('', 'graph', None, ''),
560 ('p', 'patch', None, ''),
565 ('p', 'patch', None, ''),
561 ]
566 ]
562 args, opts = parseoptions(ui, cmdoptions, args)
567 args, opts = parseoptions(ui, cmdoptions, args)
563 ui.status(_('note: -v prints the entire commit message like Git does. To '
568 ui.status(_('note: -v prints the entire commit message like Git does. To '
564 'print just the first line, drop the -v.\n\n'))
569 'print just the first line, drop the -v.\n\n'))
565 ui.status(_("note: see hg help revset for information on how to filter "
570 ui.status(_("note: see hg help revset for information on how to filter "
566 "log output\n\n"))
571 "log output\n\n"))
567
572
568 cmd = Command('log')
573 cmd = Command('log')
569 cmd['-v'] = None
574 cmd['-v'] = None
570
575
571 if opts.get('number'):
576 if opts.get('number'):
572 cmd['-l'] = opts.get('number')
577 cmd['-l'] = opts.get('number')
573 if opts.get('1'):
578 if opts.get('1'):
574 cmd['-l'] = '1'
579 cmd['-l'] = '1'
575 if opts.get('stat'):
580 if opts.get('stat'):
576 cmd['--stat'] = None
581 cmd['--stat'] = None
577 if opts.get('graph'):
582 if opts.get('graph'):
578 cmd['-G'] = None
583 cmd['-G'] = None
579 if opts.get('patch'):
584 if opts.get('patch'):
580 cmd['-p'] = None
585 cmd['-p'] = None
581
586
582 if opts.get('pretty') or opts.get('format') or opts.get('oneline'):
587 if opts.get('pretty') or opts.get('format') or opts.get('oneline'):
583 format = opts.get('format', '')
588 format = opts.get('format', '')
584 if 'format:' in format:
589 if 'format:' in format:
585 ui.status(_("note: --format format:??? equates to Mercurial's "
590 ui.status(_("note: --format format:??? equates to Mercurial's "
586 "--template. See hg help templates for more info.\n\n"))
591 "--template. See hg help templates for more info.\n\n"))
587 cmd['--template'] = '???'
592 cmd['--template'] = '???'
588 else:
593 else:
589 ui.status(_("note: --pretty/format/oneline equate to Mercurial's "
594 ui.status(_("note: --pretty/format/oneline equate to Mercurial's "
590 "--style or --template. See hg help templates for "
595 "--style or --template. See hg help templates for "
591 "more info.\n\n"))
596 "more info.\n\n"))
592 cmd['--style'] = '???'
597 cmd['--style'] = '???'
593
598
594 if len(args) > 0:
599 if len(args) > 0:
595 if '..' in args[0]:
600 if '..' in args[0]:
596 since, until = args[0].split('..')
601 since, until = args[0].split('..')
597 cmd['-r'] = "'%s::%s'" % (since, until)
602 cmd['-r'] = "'%s::%s'" % (since, until)
598 del args[0]
603 del args[0]
599 cmd.extend(args)
604 cmd.extend(args)
600
605
601 ui.status((bytes(cmd)), "\n")
606 ui.status((bytes(cmd)), "\n")
602
607
603 def lsfiles(ui, repo, *args, **kwargs):
608 def lsfiles(ui, repo, *args, **kwargs):
604 cmdoptions = [
609 cmdoptions = [
605 ('c', 'cached', None, ''),
610 ('c', 'cached', None, ''),
606 ('d', 'deleted', None, ''),
611 ('d', 'deleted', None, ''),
607 ('m', 'modified', None, ''),
612 ('m', 'modified', None, ''),
608 ('o', 'others', None, ''),
613 ('o', 'others', None, ''),
609 ('i', 'ignored', None, ''),
614 ('i', 'ignored', None, ''),
610 ('s', 'stage', None, ''),
615 ('s', 'stage', None, ''),
611 ('z', '_zero', None, ''),
616 ('z', '_zero', None, ''),
612 ]
617 ]
613 args, opts = parseoptions(ui, cmdoptions, args)
618 args, opts = parseoptions(ui, cmdoptions, args)
614
619
615 if (opts.get('modified') or opts.get('deleted')
620 if (opts.get('modified') or opts.get('deleted')
616 or opts.get('others') or opts.get('ignored')):
621 or opts.get('others') or opts.get('ignored')):
617 cmd = Command('status')
622 cmd = Command('status')
618 if opts.get('deleted'):
623 if opts.get('deleted'):
619 cmd['-d'] = None
624 cmd['-d'] = None
620 if opts.get('modified'):
625 if opts.get('modified'):
621 cmd['-m'] = None
626 cmd['-m'] = None
622 if opts.get('others'):
627 if opts.get('others'):
623 cmd['-o'] = None
628 cmd['-o'] = None
624 if opts.get('ignored'):
629 if opts.get('ignored'):
625 cmd['-i'] = None
630 cmd['-i'] = None
626 else:
631 else:
627 cmd = Command('files')
632 cmd = Command('files')
628 if opts.get('stage'):
633 if opts.get('stage'):
629 ui.status(_("note: Mercurial doesn't have a staging area, ignoring "
634 ui.status(_("note: Mercurial doesn't have a staging area, ignoring "
630 "--stage\n"))
635 "--stage\n"))
631 if opts.get('_zero'):
636 if opts.get('_zero'):
632 cmd['-0'] = None
637 cmd['-0'] = None
633 cmd.append('.')
638 cmd.append('.')
634 for include in args:
639 for include in args:
635 cmd['-I'] = procutil.shellquote(include)
640 cmd['-I'] = procutil.shellquote(include)
636
641
637 ui.status((bytes(cmd)), "\n")
642 ui.status((bytes(cmd)), "\n")
638
643
639 def merge(ui, repo, *args, **kwargs):
644 def merge(ui, repo, *args, **kwargs):
640 cmdoptions = [
645 cmdoptions = [
641 ]
646 ]
642 args, opts = parseoptions(ui, cmdoptions, args)
647 args, opts = parseoptions(ui, cmdoptions, args)
643
648
644 cmd = Command('merge')
649 cmd = Command('merge')
645
650
646 if len(args) > 0:
651 if len(args) > 0:
647 cmd.append(args[len(args) - 1])
652 cmd.append(args[len(args) - 1])
648
653
649 ui.status((bytes(cmd)), "\n")
654 ui.status((bytes(cmd)), "\n")
650
655
651 def mergebase(ui, repo, *args, **kwargs):
656 def mergebase(ui, repo, *args, **kwargs):
652 cmdoptions = []
657 cmdoptions = []
653 args, opts = parseoptions(ui, cmdoptions, args)
658 args, opts = parseoptions(ui, cmdoptions, args)
654
659
655 if len(args) != 2:
660 if len(args) != 2:
656 args = ['A', 'B']
661 args = ['A', 'B']
657
662
658 cmd = Command("log -T '{node}\\n' -r 'ancestor(%s,%s)'"
663 cmd = Command("log -T '{node}\\n' -r 'ancestor(%s,%s)'"
659 % (args[0], args[1]))
664 % (args[0], args[1]))
660
665
661 ui.status(_('note: ancestors() is part of the revset language\n'),
666 ui.status(_('note: ancestors() is part of the revset language\n'),
662 _("(learn more about revsets with 'hg help revsets')\n\n"))
667 _("(learn more about revsets with 'hg help revsets')\n\n"))
663 ui.status((bytes(cmd)), "\n")
668 ui.status((bytes(cmd)), "\n")
664
669
665 def mergetool(ui, repo, *args, **kwargs):
670 def mergetool(ui, repo, *args, **kwargs):
666 cmdoptions = []
671 cmdoptions = []
667 args, opts = parseoptions(ui, cmdoptions, args)
672 args, opts = parseoptions(ui, cmdoptions, args)
668
673
669 cmd = Command("resolve")
674 cmd = Command("resolve")
670
675
671 if len(args) == 0:
676 if len(args) == 0:
672 cmd['--all'] = None
677 cmd['--all'] = None
673 cmd.extend(args)
678 cmd.extend(args)
674 ui.status((bytes(cmd)), "\n")
679 ui.status((bytes(cmd)), "\n")
675
680
676 def mv(ui, repo, *args, **kwargs):
681 def mv(ui, repo, *args, **kwargs):
677 cmdoptions = [
682 cmdoptions = [
678 ('f', 'force', None, ''),
683 ('f', 'force', None, ''),
679 ]
684 ]
680 args, opts = parseoptions(ui, cmdoptions, args)
685 args, opts = parseoptions(ui, cmdoptions, args)
681
686
682 cmd = Command('mv')
687 cmd = Command('mv')
683 cmd.extend(args)
688 cmd.extend(args)
684
689
685 if opts.get('force'):
690 if opts.get('force'):
686 cmd['-f'] = None
691 cmd['-f'] = None
687
692
688 ui.status((bytes(cmd)), "\n")
693 ui.status((bytes(cmd)), "\n")
689
694
690 def pull(ui, repo, *args, **kwargs):
695 def pull(ui, repo, *args, **kwargs):
691 cmdoptions = [
696 cmdoptions = [
692 ('', 'all', None, ''),
697 ('', 'all', None, ''),
693 ('f', 'force', None, ''),
698 ('f', 'force', None, ''),
694 ('r', 'rebase', None, ''),
699 ('r', 'rebase', None, ''),
695 ]
700 ]
696 args, opts = parseoptions(ui, cmdoptions, args)
701 args, opts = parseoptions(ui, cmdoptions, args)
697
702
698 cmd = Command('pull')
703 cmd = Command('pull')
699 cmd['--rebase'] = None
704 cmd['--rebase'] = None
700
705
701 if len(args) > 0:
706 if len(args) > 0:
702 cmd.append(args[0])
707 cmd.append(args[0])
703 if len(args) > 1:
708 if len(args) > 1:
704 ui.status(_("note: Mercurial doesn't have refspecs. "
709 ui.status(_("note: Mercurial doesn't have refspecs. "
705 "-r can be used to specify which commits you want to "
710 "-r can be used to specify which commits you want to "
706 "pull. -B can be used to specify which bookmark you "
711 "pull. -B can be used to specify which bookmark you "
707 "want to pull.\n\n"))
712 "want to pull.\n\n"))
708 for v in args[1:]:
713 for v in args[1:]:
709 if v in repo._bookmarks:
714 if v in repo._bookmarks:
710 cmd['-B'] = v
715 cmd['-B'] = v
711 else:
716 else:
712 cmd['-r'] = v
717 cmd['-r'] = v
713
718
714 ui.status((bytes(cmd)), "\n")
719 ui.status((bytes(cmd)), "\n")
715
720
716 def push(ui, repo, *args, **kwargs):
721 def push(ui, repo, *args, **kwargs):
717 cmdoptions = [
722 cmdoptions = [
718 ('', 'all', None, ''),
723 ('', 'all', None, ''),
719 ('f', 'force', None, ''),
724 ('f', 'force', None, ''),
720 ]
725 ]
721 args, opts = parseoptions(ui, cmdoptions, args)
726 args, opts = parseoptions(ui, cmdoptions, args)
722
727
723 cmd = Command('push')
728 cmd = Command('push')
724
729
725 if len(args) > 0:
730 if len(args) > 0:
726 cmd.append(args[0])
731 cmd.append(args[0])
727 if len(args) > 1:
732 if len(args) > 1:
728 ui.status(_("note: Mercurial doesn't have refspecs. "
733 ui.status(_("note: Mercurial doesn't have refspecs. "
729 "-r can be used to specify which commits you want "
734 "-r can be used to specify which commits you want "
730 "to push. -B can be used to specify which bookmark "
735 "to push. -B can be used to specify which bookmark "
731 "you want to push.\n\n"))
736 "you want to push.\n\n"))
732 for v in args[1:]:
737 for v in args[1:]:
733 if v in repo._bookmarks:
738 if v in repo._bookmarks:
734 cmd['-B'] = v
739 cmd['-B'] = v
735 else:
740 else:
736 cmd['-r'] = v
741 cmd['-r'] = v
737
742
738 if opts.get('force'):
743 if opts.get('force'):
739 cmd['-f'] = None
744 cmd['-f'] = None
740
745
741 ui.status((bytes(cmd)), "\n")
746 ui.status((bytes(cmd)), "\n")
742
747
743 def rebase(ui, repo, *args, **kwargs):
748 def rebase(ui, repo, *args, **kwargs):
744 cmdoptions = [
749 cmdoptions = [
745 ('', 'all', None, ''),
750 ('', 'all', None, ''),
746 ('i', 'interactive', None, ''),
751 ('i', 'interactive', None, ''),
747 ('', 'onto', '', ''),
752 ('', 'onto', '', ''),
748 ('', 'abort', None, ''),
753 ('', 'abort', None, ''),
749 ('', 'continue', None, ''),
754 ('', 'continue', None, ''),
750 ('', 'skip', None, ''),
755 ('', 'skip', None, ''),
751 ]
756 ]
752 args, opts = parseoptions(ui, cmdoptions, args)
757 args, opts = parseoptions(ui, cmdoptions, args)
753
758
754 if opts.get('interactive'):
759 if opts.get('interactive'):
755 ui.status(_("note: hg histedit does not perform a rebase. "
760 ui.status(_("note: hg histedit does not perform a rebase. "
756 "It just edits history.\n\n"))
761 "It just edits history.\n\n"))
757 cmd = Command('histedit')
762 cmd = Command('histedit')
758 if len(args) > 0:
763 if len(args) > 0:
759 ui.status(_("also note: 'hg histedit' will automatically detect"
764 ui.status(_("also note: 'hg histedit' will automatically detect"
760 " your stack, so no second argument is necessary\n\n"))
765 " your stack, so no second argument is necessary\n\n"))
761 ui.status((bytes(cmd)), "\n")
766 ui.status((bytes(cmd)), "\n")
762 return
767 return
763
768
764 if opts.get('skip'):
769 if opts.get('skip'):
765 cmd = Command('revert --all -r .')
770 cmd = Command('revert --all -r .')
766 ui.status((bytes(cmd)), "\n")
771 ui.status((bytes(cmd)), "\n")
767
772
768 cmd = Command('rebase')
773 cmd = Command('rebase')
769
774
770 if opts.get('continue') or opts.get('skip'):
775 if opts.get('continue') or opts.get('skip'):
771 cmd['--continue'] = None
776 cmd['--continue'] = None
772 if opts.get('abort'):
777 if opts.get('abort'):
773 cmd['--abort'] = None
778 cmd['--abort'] = None
774
779
775 if opts.get('onto'):
780 if opts.get('onto'):
776 ui.status(_("note: if you're trying to lift a commit off one branch, "
781 ui.status(_("note: if you're trying to lift a commit off one branch, "
777 "try hg rebase -d <destination commit> -s <commit to be "
782 "try hg rebase -d <destination commit> -s <commit to be "
778 "lifted>\n\n"))
783 "lifted>\n\n"))
779 cmd['-d'] = convert(opts.get('onto'))
784 cmd['-d'] = convert(opts.get('onto'))
780 if len(args) < 2:
785 if len(args) < 2:
781 raise error.Abort(_("expected format: git rebase --onto X Y Z"))
786 raise error.Abort(_("expected format: git rebase --onto X Y Z"))
782 cmd['-s'] = "'::%s - ::%s'" % (convert(args[1]), convert(args[0]))
787 cmd['-s'] = "'::%s - ::%s'" % (convert(args[1]), convert(args[0]))
783 else:
788 else:
784 if len(args) == 1:
789 if len(args) == 1:
785 cmd['-d'] = convert(args[0])
790 cmd['-d'] = convert(args[0])
786 elif len(args) == 2:
791 elif len(args) == 2:
787 cmd['-d'] = convert(args[0])
792 cmd['-d'] = convert(args[0])
788 cmd['-b'] = convert(args[1])
793 cmd['-b'] = convert(args[1])
789
794
790 ui.status((bytes(cmd)), "\n")
795 ui.status((bytes(cmd)), "\n")
791
796
792 def reflog(ui, repo, *args, **kwargs):
797 def reflog(ui, repo, *args, **kwargs):
793 cmdoptions = [
798 cmdoptions = [
794 ('', 'all', None, ''),
799 ('', 'all', None, ''),
795 ]
800 ]
796 args, opts = parseoptions(ui, cmdoptions, args)
801 args, opts = parseoptions(ui, cmdoptions, args)
797
802
798 cmd = Command('journal')
803 cmd = Command('journal')
799 if opts.get('all'):
804 if opts.get('all'):
800 cmd['--all'] = None
805 cmd['--all'] = None
801 if len(args) > 0:
806 if len(args) > 0:
802 cmd.append(args[0])
807 cmd.append(args[0])
803
808
804 ui.status(bytes(cmd), "\n\n")
809 ui.status(bytes(cmd), "\n\n")
805 ui.status(_("note: in hg commits can be deleted from repo but we always"
810 ui.status(_("note: in hg commits can be deleted from repo but we always"
806 " have backups\n"))
811 " have backups\n"))
807
812
808 def reset(ui, repo, *args, **kwargs):
813 def reset(ui, repo, *args, **kwargs):
809 cmdoptions = [
814 cmdoptions = [
810 ('', 'soft', None, ''),
815 ('', 'soft', None, ''),
811 ('', 'hard', None, ''),
816 ('', 'hard', None, ''),
812 ('', 'mixed', None, ''),
817 ('', 'mixed', None, ''),
813 ]
818 ]
814 args, opts = parseoptions(ui, cmdoptions, args)
819 args, opts = parseoptions(ui, cmdoptions, args)
815
820
816 commit = convert(args[0] if len(args) > 0 else '.')
821 commit = convert(args[0] if len(args) > 0 else '.')
817 hard = opts.get('hard')
822 hard = opts.get('hard')
818
823
819 if opts.get('mixed'):
824 if opts.get('mixed'):
820 ui.status(_('note: --mixed has no meaning since Mercurial has no '
825 ui.status(_('note: --mixed has no meaning since Mercurial has no '
821 'staging area\n\n'))
826 'staging area\n\n'))
822 if opts.get('soft'):
827 if opts.get('soft'):
823 ui.status(_('note: --soft has no meaning since Mercurial has no '
828 ui.status(_('note: --soft has no meaning since Mercurial has no '
824 'staging area\n\n'))
829 'staging area\n\n'))
825
830
826 cmd = Command('update')
831 cmd = Command('update')
827 if hard:
832 if hard:
828 cmd.append('--clean')
833 cmd.append('--clean')
829
834
830 cmd.append(commit)
835 cmd.append(commit)
831
836
832 ui.status((bytes(cmd)), "\n")
837 ui.status((bytes(cmd)), "\n")
833
838
834 def revert(ui, repo, *args, **kwargs):
839 def revert(ui, repo, *args, **kwargs):
835 cmdoptions = [
840 cmdoptions = [
836 ]
841 ]
837 args, opts = parseoptions(ui, cmdoptions, args)
842 args, opts = parseoptions(ui, cmdoptions, args)
838
843
839 if len(args) > 1:
844 if len(args) > 1:
840 ui.status(_("note: hg backout doesn't support multiple commits at "
845 ui.status(_("note: hg backout doesn't support multiple commits at "
841 "once\n\n"))
846 "once\n\n"))
842
847
843 cmd = Command('backout')
848 cmd = Command('backout')
844 if args:
849 if args:
845 cmd.append(args[0])
850 cmd.append(args[0])
846
851
847 ui.status((bytes(cmd)), "\n")
852 ui.status((bytes(cmd)), "\n")
848
853
849 def revparse(ui, repo, *args, **kwargs):
854 def revparse(ui, repo, *args, **kwargs):
850 cmdoptions = [
855 cmdoptions = [
851 ('', 'show-cdup', None, ''),
856 ('', 'show-cdup', None, ''),
852 ('', 'show-toplevel', None, ''),
857 ('', 'show-toplevel', None, ''),
853 ]
858 ]
854 args, opts = parseoptions(ui, cmdoptions, args)
859 args, opts = parseoptions(ui, cmdoptions, args)
855
860
856 if opts.get('show_cdup') or opts.get('show_toplevel'):
861 if opts.get('show_cdup') or opts.get('show_toplevel'):
857 cmd = Command('root')
862 cmd = Command('root')
858 if opts.get('show_cdup'):
863 if opts.get('show_cdup'):
859 ui.status(_("note: hg root prints the root of the repository\n\n"))
864 ui.status(_("note: hg root prints the root of the repository\n\n"))
860 ui.status((bytes(cmd)), "\n")
865 ui.status((bytes(cmd)), "\n")
861 else:
866 else:
862 ui.status(_("note: see hg help revset for how to refer to commits\n"))
867 ui.status(_("note: see hg help revset for how to refer to commits\n"))
863
868
864 def rm(ui, repo, *args, **kwargs):
869 def rm(ui, repo, *args, **kwargs):
865 cmdoptions = [
870 cmdoptions = [
866 ('f', 'force', None, ''),
871 ('f', 'force', None, ''),
867 ('n', 'dry-run', None, ''),
872 ('n', 'dry-run', None, ''),
868 ]
873 ]
869 args, opts = parseoptions(ui, cmdoptions, args)
874 args, opts = parseoptions(ui, cmdoptions, args)
870
875
871 cmd = Command('rm')
876 cmd = Command('rm')
872 cmd.extend(args)
877 cmd.extend(args)
873
878
874 if opts.get('force'):
879 if opts.get('force'):
875 cmd['-f'] = None
880 cmd['-f'] = None
876 if opts.get('dry_run'):
881 if opts.get('dry_run'):
877 cmd['-n'] = None
882 cmd['-n'] = None
878
883
879 ui.status((bytes(cmd)), "\n")
884 ui.status((bytes(cmd)), "\n")
880
885
881 def show(ui, repo, *args, **kwargs):
886 def show(ui, repo, *args, **kwargs):
882 cmdoptions = [
887 cmdoptions = [
883 ('', 'name-status', None, ''),
888 ('', 'name-status', None, ''),
884 ('', 'pretty', '', ''),
889 ('', 'pretty', '', ''),
885 ('U', 'unified', int, ''),
890 ('U', 'unified', int, ''),
886 ]
891 ]
887 args, opts = parseoptions(ui, cmdoptions, args)
892 args, opts = parseoptions(ui, cmdoptions, args)
888
893
889 if opts.get('name_status'):
894 if opts.get('name_status'):
890 if opts.get('pretty') == 'format:':
895 if opts.get('pretty') == 'format:':
891 cmd = Command('status')
896 cmd = Command('status')
892 cmd['--change'] = '.'
897 cmd['--change'] = '.'
893 else:
898 else:
894 cmd = Command('log')
899 cmd = Command('log')
895 cmd.append('--style status')
900 cmd.append('--style status')
896 cmd.append('-r .')
901 cmd.append('-r .')
897 elif len(args) > 0:
902 elif len(args) > 0:
898 if ispath(repo, args[0]):
903 if ispath(repo, args[0]):
899 cmd = Command('cat')
904 cmd = Command('cat')
900 else:
905 else:
901 cmd = Command('export')
906 cmd = Command('export')
902 cmd.extend(args)
907 cmd.extend(args)
903 if opts.get('unified'):
908 if opts.get('unified'):
904 cmd.append('--config diff.unified=%d' % (opts['unified'],))
909 cmd.append('--config diff.unified=%d' % (opts['unified'],))
905 elif opts.get('unified'):
910 elif opts.get('unified'):
906 cmd = Command('export')
911 cmd = Command('export')
907 cmd.append('--config diff.unified=%d' % (opts['unified'],))
912 cmd.append('--config diff.unified=%d' % (opts['unified'],))
908 else:
913 else:
909 cmd = Command('export')
914 cmd = Command('export')
910
915
911 ui.status((bytes(cmd)), "\n")
916 ui.status((bytes(cmd)), "\n")
912
917
913 def stash(ui, repo, *args, **kwargs):
918 def stash(ui, repo, *args, **kwargs):
914 cmdoptions = [
919 cmdoptions = [
915 ]
920 ]
916 args, opts = parseoptions(ui, cmdoptions, args)
921 args, opts = parseoptions(ui, cmdoptions, args)
917
922
918 cmd = Command('shelve')
923 cmd = Command('shelve')
919 action = args[0] if len(args) > 0 else None
924 action = args[0] if len(args) > 0 else None
920
925
921 if action == 'list':
926 if action == 'list':
922 cmd['-l'] = None
927 cmd['-l'] = None
923 elif action == 'drop':
928 elif action == 'drop':
924 cmd['-d'] = None
929 cmd['-d'] = None
925 if len(args) > 1:
930 if len(args) > 1:
926 cmd.append(args[1])
931 cmd.append(args[1])
927 else:
932 else:
928 cmd.append('<shelve name>')
933 cmd.append('<shelve name>')
929 elif action == 'pop' or action == 'apply':
934 elif action == 'pop' or action == 'apply':
930 cmd = Command('unshelve')
935 cmd = Command('unshelve')
931 if len(args) > 1:
936 if len(args) > 1:
932 cmd.append(args[1])
937 cmd.append(args[1])
933 if action == 'apply':
938 if action == 'apply':
934 cmd['--keep'] = None
939 cmd['--keep'] = None
935 elif (action == 'branch' or action == 'show' or action == 'clear'
940 elif (action == 'branch' or action == 'show' or action == 'clear'
936 or action == 'create'):
941 or action == 'create'):
937 ui.status(_("note: Mercurial doesn't have equivalents to the "
942 ui.status(_("note: Mercurial doesn't have equivalents to the "
938 "git stash branch, show, clear, or create actions\n\n"))
943 "git stash branch, show, clear, or create actions\n\n"))
939 return
944 return
940 else:
945 else:
941 if len(args) > 0:
946 if len(args) > 0:
942 if args[0] != 'save':
947 if args[0] != 'save':
943 cmd['--name'] = args[0]
948 cmd['--name'] = args[0]
944 elif len(args) > 1:
949 elif len(args) > 1:
945 cmd['--name'] = args[1]
950 cmd['--name'] = args[1]
946
951
947 ui.status((bytes(cmd)), "\n")
952 ui.status((bytes(cmd)), "\n")
948
953
949 def status(ui, repo, *args, **kwargs):
954 def status(ui, repo, *args, **kwargs):
950 cmdoptions = [
955 cmdoptions = [
951 ('', 'ignored', None, ''),
956 ('', 'ignored', None, ''),
952 ]
957 ]
953 args, opts = parseoptions(ui, cmdoptions, args)
958 args, opts = parseoptions(ui, cmdoptions, args)
954
959
955 cmd = Command('status')
960 cmd = Command('status')
956 cmd.extend(args)
961 cmd.extend(args)
957
962
958 if opts.get('ignored'):
963 if opts.get('ignored'):
959 cmd['-i'] = None
964 cmd['-i'] = None
960
965
961 ui.status((bytes(cmd)), "\n")
966 ui.status((bytes(cmd)), "\n")
962
967
963 def svn(ui, repo, *args, **kwargs):
968 def svn(ui, repo, *args, **kwargs):
964 if not args:
969 if not args:
965 raise error.Abort(_('missing svn command'))
970 raise error.Abort(_('missing svn command'))
966 svncmd = args[0]
971 svncmd = args[0]
967 if svncmd not in gitsvncommands:
972 if svncmd not in gitsvncommands:
968 raise error.Abort(_('unknown git svn command "%s"') % (svncmd))
973 raise error.Abort(_('unknown git svn command "%s"') % (svncmd))
969
974
970 args = args[1:]
975 args = args[1:]
971 return gitsvncommands[svncmd](ui, repo, *args, **kwargs)
976 return gitsvncommands[svncmd](ui, repo, *args, **kwargs)
972
977
973 def svndcommit(ui, repo, *args, **kwargs):
978 def svndcommit(ui, repo, *args, **kwargs):
974 cmdoptions = [
979 cmdoptions = [
975 ]
980 ]
976 args, opts = parseoptions(ui, cmdoptions, args)
981 args, opts = parseoptions(ui, cmdoptions, args)
977
982
978 cmd = Command('push')
983 cmd = Command('push')
979
984
980 ui.status((bytes(cmd)), "\n")
985 ui.status((bytes(cmd)), "\n")
981
986
982 def svnfetch(ui, repo, *args, **kwargs):
987 def svnfetch(ui, repo, *args, **kwargs):
983 cmdoptions = [
988 cmdoptions = [
984 ]
989 ]
985 args, opts = parseoptions(ui, cmdoptions, args)
990 args, opts = parseoptions(ui, cmdoptions, args)
986
991
987 cmd = Command('pull')
992 cmd = Command('pull')
988 cmd.append('default-push')
993 cmd.append('default-push')
989
994
990 ui.status((bytes(cmd)), "\n")
995 ui.status((bytes(cmd)), "\n")
991
996
992 def svnfindrev(ui, repo, *args, **kwargs):
997 def svnfindrev(ui, repo, *args, **kwargs):
993 cmdoptions = [
998 cmdoptions = [
994 ]
999 ]
995 args, opts = parseoptions(ui, cmdoptions, args)
1000 args, opts = parseoptions(ui, cmdoptions, args)
996
1001
997 if not args:
1002 if not args:
998 raise error.Abort(_('missing find-rev argument'))
1003 raise error.Abort(_('missing find-rev argument'))
999
1004
1000 cmd = Command('log')
1005 cmd = Command('log')
1001 cmd['-r'] = args[0]
1006 cmd['-r'] = args[0]
1002
1007
1003 ui.status((bytes(cmd)), "\n")
1008 ui.status((bytes(cmd)), "\n")
1004
1009
1005 def svnrebase(ui, repo, *args, **kwargs):
1010 def svnrebase(ui, repo, *args, **kwargs):
1006 cmdoptions = [
1011 cmdoptions = [
1007 ('l', 'local', None, ''),
1012 ('l', 'local', None, ''),
1008 ]
1013 ]
1009 args, opts = parseoptions(ui, cmdoptions, args)
1014 args, opts = parseoptions(ui, cmdoptions, args)
1010
1015
1011 pullcmd = Command('pull')
1016 pullcmd = Command('pull')
1012 pullcmd.append('default-push')
1017 pullcmd.append('default-push')
1013 rebasecmd = Command('rebase')
1018 rebasecmd = Command('rebase')
1014 rebasecmd.append('tip')
1019 rebasecmd.append('tip')
1015
1020
1016 cmd = pullcmd & rebasecmd
1021 cmd = pullcmd & rebasecmd
1017
1022
1018 ui.status((bytes(cmd)), "\n")
1023 ui.status((bytes(cmd)), "\n")
1019
1024
1020 def tag(ui, repo, *args, **kwargs):
1025 def tag(ui, repo, *args, **kwargs):
1021 cmdoptions = [
1026 cmdoptions = [
1022 ('f', 'force', None, ''),
1027 ('f', 'force', None, ''),
1023 ('l', 'list', None, ''),
1028 ('l', 'list', None, ''),
1024 ('d', 'delete', None, ''),
1029 ('d', 'delete', None, ''),
1025 ]
1030 ]
1026 args, opts = parseoptions(ui, cmdoptions, args)
1031 args, opts = parseoptions(ui, cmdoptions, args)
1027
1032
1028 if opts.get('list'):
1033 if opts.get('list'):
1029 cmd = Command('tags')
1034 cmd = Command('tags')
1030 else:
1035 else:
1031 cmd = Command('tag')
1036 cmd = Command('tag')
1032
1037
1033 if not args:
1038 if not args:
1034 raise error.Abort(_('missing tag argument'))
1039 raise error.Abort(_('missing tag argument'))
1035
1040
1036 cmd.append(args[0])
1041 cmd.append(args[0])
1037 if len(args) > 1:
1042 if len(args) > 1:
1038 cmd['-r'] = args[1]
1043 cmd['-r'] = args[1]
1039
1044
1040 if opts.get('delete'):
1045 if opts.get('delete'):
1041 cmd['--remove'] = None
1046 cmd['--remove'] = None
1042
1047
1043 if opts.get('force'):
1048 if opts.get('force'):
1044 cmd['-f'] = None
1049 cmd['-f'] = None
1045
1050
1046 ui.status((bytes(cmd)), "\n")
1051 ui.status((bytes(cmd)), "\n")
1047
1052
1048 gitcommands = {
1053 gitcommands = {
1049 'add': add,
1054 'add': add,
1050 'am': am,
1055 'am': am,
1051 'apply': apply,
1056 'apply': apply,
1052 'bisect': bisect,
1057 'bisect': bisect,
1053 'blame': blame,
1058 'blame': blame,
1054 'branch': branch,
1059 'branch': branch,
1055 'checkout': checkout,
1060 'checkout': checkout,
1056 'cherry-pick': cherrypick,
1061 'cherry-pick': cherrypick,
1057 'clean': clean,
1062 'clean': clean,
1058 'clone': clone,
1063 'clone': clone,
1059 'commit': commit,
1064 'commit': commit,
1060 'diff': diff,
1065 'diff': diff,
1061 'difftool': difftool,
1066 'difftool': difftool,
1062 'fetch': fetch,
1067 'fetch': fetch,
1063 'grep': grep,
1068 'grep': grep,
1064 'init': init,
1069 'init': init,
1065 'log': log,
1070 'log': log,
1066 'ls-files': lsfiles,
1071 'ls-files': lsfiles,
1067 'merge': merge,
1072 'merge': merge,
1068 'merge-base': mergebase,
1073 'merge-base': mergebase,
1069 'mergetool': mergetool,
1074 'mergetool': mergetool,
1070 'mv': mv,
1075 'mv': mv,
1071 'pull': pull,
1076 'pull': pull,
1072 'push': push,
1077 'push': push,
1073 'rebase': rebase,
1078 'rebase': rebase,
1074 'reflog': reflog,
1079 'reflog': reflog,
1075 'reset': reset,
1080 'reset': reset,
1076 'revert': revert,
1081 'revert': revert,
1077 'rev-parse': revparse,
1082 'rev-parse': revparse,
1078 'rm': rm,
1083 'rm': rm,
1079 'show': show,
1084 'show': show,
1080 'stash': stash,
1085 'stash': stash,
1081 'status': status,
1086 'status': status,
1082 'svn': svn,
1087 'svn': svn,
1083 'tag': tag,
1088 'tag': tag,
1084 'whatchanged': deprecated,
1089 'whatchanged': deprecated,
1085 }
1090 }
1086
1091
1087 gitsvncommands = {
1092 gitsvncommands = {
1088 'dcommit': svndcommit,
1093 'dcommit': svndcommit,
1089 'fetch': svnfetch,
1094 'fetch': svnfetch,
1090 'find-rev': svnfindrev,
1095 'find-rev': svnfindrev,
1091 'rebase': svnrebase,
1096 'rebase': svnrebase,
1092 }
1097 }
General Comments 0
You need to be logged in to leave comments. Login now