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