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