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