comparison mercurial/commands.py @ 11177:6a64813276ed

commands: initial audit of exit codes bisect: clarify None return bundle: return 1 on no changes clone: return result code copy: limit errors to 0/1 commit: return 1 on no changes forget: return 1 on errors grep: return 1 if no match found remove: return 1 on errors resolve: return 1 if something fails to resolve rollback: return 1 if no rollback data
author Matt Mackall <mpm@selenic.com>
date Sat, 15 May 2010 17:48:49 -0500
parents 5b48d819d5f9
children aad0c319b96e
comparison
equal deleted inserted replaced
11176:ed5d2a7c4b73 11177:6a64813276ed
73 parameter greater than 0, this compares every removed file with 73 parameter greater than 0, this compares every removed file with
74 every added file and records those similar enough as renames. This 74 every added file and records those similar enough as renames. This
75 option takes a percentage between 0 (disabled) and 100 (files must 75 option takes a percentage between 0 (disabled) and 100 (files must
76 be identical) as its parameter. Detecting renamed files this way 76 be identical) as its parameter. Detecting renamed files this way
77 can be expensive. 77 can be expensive.
78
79 Returns 0 if all files are successfully added.
78 """ 80 """
79 try: 81 try:
80 sim = float(opts.get('similarity') or 0) 82 sim = float(opts.get('similarity') or 0)
81 except ValueError: 83 except ValueError:
82 raise util.Abort(_('similarity must be a number')) 84 raise util.Abort(_('similarity must be a number'))
95 97
96 Without the -a/--text option, annotate will avoid processing files 98 Without the -a/--text option, annotate will avoid processing files
97 it detects as binary. With -a, annotate will annotate the file 99 it detects as binary. With -a, annotate will annotate the file
98 anyway, although the results will probably be neither useful 100 anyway, although the results will probably be neither useful
99 nor desirable. 101 nor desirable.
102
103 Returns 0 on success.
100 """ 104 """
101 if opts.get('follow'): 105 if opts.get('follow'):
102 # --follow is deprecated and now just an alias for -f/--file 106 # --follow is deprecated and now just an alias for -f/--file
103 # to mimic the behavior of Mercurial before version 1.5 107 # to mimic the behavior of Mercurial before version 1.5
104 opts['file'] = 1 108 opts['file'] = 1
174 178
175 Each member added to an archive file has a directory prefix 179 Each member added to an archive file has a directory prefix
176 prepended. Use -p/--prefix to specify a format string for the 180 prepended. Use -p/--prefix to specify a format string for the
177 prefix. The default is the basename of the archive, with suffixes 181 prefix. The default is the basename of the archive, with suffixes
178 removed. 182 removed.
183
184 Returns 0 on success.
179 ''' 185 '''
180 186
181 ctx = repo[opts.get('rev')] 187 ctx = repo[opts.get('rev')]
182 if not ctx: 188 if not ctx:
183 raise util.Abort(_('no working directory: please specify a revision')) 189 raise util.Abort(_('no working directory: please specify a revision'))
228 before starting the backout, then merges the new head with that 234 before starting the backout, then merges the new head with that
229 changeset afterwards. This saves you from doing the merge by hand. 235 changeset afterwards. This saves you from doing the merge by hand.
230 The result of this merge is not committed, as with a normal merge. 236 The result of this merge is not committed, as with a normal merge.
231 237
232 See :hg:`help dates` for a list of formats valid for -d/--date. 238 See :hg:`help dates` for a list of formats valid for -d/--date.
239
240 Returns 0 on success.
233 ''' 241 '''
234 if rev and node: 242 if rev and node:
235 raise util.Abort(_("please specify just one revision")) 243 raise util.Abort(_("please specify just one revision"))
236 244
237 if not rev: 245 if not rev:
321 If you supply a command, it will be used for automatic bisection. 329 If you supply a command, it will be used for automatic bisection.
322 Its exit status will be used to mark revisions as good or bad: 330 Its exit status will be used to mark revisions as good or bad:
323 status 0 means good, 125 means to skip the revision, 127 331 status 0 means good, 125 means to skip the revision, 127
324 (command not found) will abort the bisection, and any other 332 (command not found) will abort the bisection, and any other
325 non-zero exit status means the revision is bad. 333 non-zero exit status means the revision is bad.
334
335 Returns 0 on success.
326 """ 336 """
327 def print_result(nodes, good): 337 def print_result(nodes, good):
328 displayer = cmdutil.show_changeset(ui, repo, {}) 338 displayer = cmdutil.show_changeset(ui, repo, {})
329 if len(nodes) == 1: 339 if len(nodes) == 1:
330 # narrowed it down to a single revision 340 # narrowed it down to a single revision
402 # update to next check 412 # update to next check
403 cmdutil.bail_if_changed(repo) 413 cmdutil.bail_if_changed(repo)
404 hg.clean(repo, nodes[0], show_stats=False) 414 hg.clean(repo, nodes[0], show_stats=False)
405 finally: 415 finally:
406 hbisect.save_state(repo, state) 416 hbisect.save_state(repo, state)
407 return print_result(nodes, good) 417 print_result(nodes, good)
418 return
408 419
409 # update state 420 # update state
410 node = repo.lookup(rev or '.') 421 node = repo.lookup(rev or '.')
411 if good or bad or skip: 422 if good or bad or skip:
412 if good: 423 if good:
455 the parent of the working directory, negating a previous branch 466 the parent of the working directory, negating a previous branch
456 change. 467 change.
457 468
458 Use the command :hg:`update` to switch to an existing branch. Use 469 Use the command :hg:`update` to switch to an existing branch. Use
459 :hg:`commit --close-branch` to mark this branch as closed. 470 :hg:`commit --close-branch` to mark this branch as closed.
471
472 Returns 0 on success.
460 """ 473 """
461 474
462 if opts.get('clean'): 475 if opts.get('clean'):
463 label = repo[None].parents()[0].branch() 476 label = repo[None].parents()[0].branch()
464 repo.dirstate.setbranch(label) 477 repo.dirstate.setbranch(label)
483 496
484 If -a/--active is specified, only show active branches. A branch 497 If -a/--active is specified, only show active branches. A branch
485 is considered active if it contains repository heads. 498 is considered active if it contains repository heads.
486 499
487 Use the command :hg:`update` to switch to an existing branch. 500 Use the command :hg:`update` to switch to an existing branch.
501
502 Returns 0.
488 """ 503 """
489 504
490 hexfunc = ui.debugflag and hex or short 505 hexfunc = ui.debugflag and hex or short
491 activebranches = [repo[n].branch() for n in repo.heads()] 506 activebranches = [repo[n].branch() for n in repo.heads()]
492 def testactive(tag, node): 507 def testactive(tag, node):
536 command. This is useful when direct push and pull are not 551 command. This is useful when direct push and pull are not
537 available or when exporting an entire repository is undesirable. 552 available or when exporting an entire repository is undesirable.
538 553
539 Applying bundles preserves all changeset contents including 554 Applying bundles preserves all changeset contents including
540 permissions, copy/rename information, and revision history. 555 permissions, copy/rename information, and revision history.
556
557 Returns 0 on success, 1 if no changes found.
541 """ 558 """
542 revs = opts.get('rev') or None 559 revs = opts.get('rev') or None
543 if revs: 560 if revs:
544 revs = [repo.lookup(rev) for rev in revs] 561 revs = [repo.lookup(rev) for rev in revs]
545 if opts.get('all'): 562 if opts.get('all'):
581 revs, checkout = hg.addbranchrevs(repo, other, branches, revs) 598 revs, checkout = hg.addbranchrevs(repo, other, branches, revs)
582 o = repo.findoutgoing(other, force=opts.get('force')) 599 o = repo.findoutgoing(other, force=opts.get('force'))
583 600
584 if not o: 601 if not o:
585 ui.status(_("no changes found\n")) 602 ui.status(_("no changes found\n"))
586 return 603 return 1
587 604
588 if revs: 605 if revs:
589 cg = repo.changegroupsubset(o, revs, 'bundle') 606 cg = repo.changegroupsubset(o, revs, 'bundle')
590 else: 607 else:
591 cg = repo.changegroup(o, 'bundle') 608 cg = repo.changegroup(o, 'bundle')
610 for the export command, with the following additions: 627 for the export command, with the following additions:
611 628
612 :``%s``: basename of file being printed 629 :``%s``: basename of file being printed
613 :``%d``: dirname of file being printed, or '.' if in repository root 630 :``%d``: dirname of file being printed, or '.' if in repository root
614 :``%p``: root-relative path name of file being printed 631 :``%p``: root-relative path name of file being printed
632
633 Returns 0 on success.
615 """ 634 """
616 ctx = repo[opts.get('rev')] 635 ctx = repo[opts.get('rev')]
617 err = 1 636 err = 1
618 m = cmdutil.match(repo, (file1,) + pats, opts) 637 m = cmdutil.match(repo, (file1,) + pats, opts)
619 for abs in ctx.walk(m): 638 for abs in ctx.walk(m):
684 d) the changeset specified with -r 703 d) the changeset specified with -r
685 e) the tipmost head specified with -b 704 e) the tipmost head specified with -b
686 f) the tipmost head specified with the url#branch source syntax 705 f) the tipmost head specified with the url#branch source syntax
687 g) the tipmost head of the default branch 706 g) the tipmost head of the default branch
688 h) tip 707 h) tip
708
709 Returns 0 on success.
689 """ 710 """
690 if opts.get('noupdate') and opts.get('updaterev'): 711 if opts.get('noupdate') and opts.get('updaterev'):
691 raise util.Abort(_("cannot specify both --noupdate and --updaterev")) 712 raise util.Abort(_("cannot specify both --noupdate and --updaterev"))
692 713
693 hg.clone(cmdutil.remoteui(ui, opts), source, dest, 714 r = hg.clone(cmdutil.remoteui(ui, opts), source, dest,
694 pull=opts.get('pull'), 715 pull=opts.get('pull'),
695 stream=opts.get('uncompressed'), 716 stream=opts.get('uncompressed'),
696 rev=opts.get('rev'), 717 rev=opts.get('rev'),
697 update=opts.get('updaterev') or not opts.get('noupdate'), 718 update=opts.get('updaterev') or not opts.get('noupdate'),
698 branch=opts.get('branch')) 719 branch=opts.get('branch'))
720
721 return r is None
699 722
700 def commit(ui, repo, *pats, **opts): 723 def commit(ui, repo, *pats, **opts):
701 """commit the specified files or all outstanding changes 724 """commit the specified files or all outstanding changes
702 725
703 Commit changes to the given files into the repository. Unlike a 726 Commit changes to the given files into the repository. Unlike a
712 735
713 If no commit message is specified, the configured editor is 736 If no commit message is specified, the configured editor is
714 started to prompt you for a message. 737 started to prompt you for a message.
715 738
716 See :hg:`help dates` for a list of formats valid for -d/--date. 739 See :hg:`help dates` for a list of formats valid for -d/--date.
740
741 Returns 0 on success, 1 if nothing changed.
717 """ 742 """
718 extra = {} 743 extra = {}
719 if opts.get('close_branch'): 744 if opts.get('close_branch'):
720 if repo['.'].node() not in repo.branchheads(): 745 if repo['.'].node() not in repo.branchheads():
721 # The topo heads set is included in the branch heads set of the 746 # The topo heads set is included in the branch heads set of the
734 bheads = repo.branchheads(branch) 759 bheads = repo.branchheads(branch)
735 760
736 node = cmdutil.commit(ui, repo, commitfunc, pats, opts) 761 node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
737 if not node: 762 if not node:
738 ui.status(_("nothing changed\n")) 763 ui.status(_("nothing changed\n"))
739 return 764 return 1
740 765
741 ctx = repo[node] 766 ctx = repo[node]
742 parents = ctx.parents() 767 parents = ctx.parents()
743 768
744 if bheads and [x for x in parents if x.node() not in bheads]: 769 if bheads and [x for x in parents if x.node() not in bheads]:
765 exist in the working directory. If invoked with -A/--after, the 790 exist in the working directory. If invoked with -A/--after, the
766 operation is recorded, but no copying is performed. 791 operation is recorded, but no copying is performed.
767 792
768 This command takes effect with the next commit. To undo a copy 793 This command takes effect with the next commit. To undo a copy
769 before that, see hg revert. 794 before that, see hg revert.
795
796 Returns 0 on success, 1 if errors are encountered.
770 """ 797 """
771 wlock = repo.wlock(False) 798 wlock = repo.wlock(False)
772 try: 799 try:
773 return cmdutil.copy(ui, repo, pats, opts) 800 return cmdutil.copy(ui, repo, pats, opts)
774 finally: 801 finally:
791 raise util.Abort(_('either two or three arguments required')) 818 raise util.Abort(_('either two or three arguments required'))
792 a = r.ancestor(lookup(rev1), lookup(rev2)) 819 a = r.ancestor(lookup(rev1), lookup(rev2))
793 ui.write("%d:%s\n" % (r.rev(a), hex(a))) 820 ui.write("%d:%s\n" % (r.rev(a), hex(a)))
794 821
795 def debugcommands(ui, cmd='', *args): 822 def debugcommands(ui, cmd='', *args):
823 """list all available commands and options"""
796 for cmd, vals in sorted(table.iteritems()): 824 for cmd, vals in sorted(table.iteritems()):
797 cmd = cmd.split('|')[0].strip('^') 825 cmd = cmd.split('|')[0].strip('^')
798 opts = ', '.join([i[1] for i in vals[1]]) 826 opts = ', '.join([i[1] for i in vals[1]])
799 ui.write('%s: %s\n' % (cmd, opts)) 827 ui.write('%s: %s\n' % (cmd, opts))
800 828
821 if ui.verbose: 849 if ui.verbose:
822 cmdlist = [' '.join(c[0]) for c in cmdlist.values()] 850 cmdlist = [' '.join(c[0]) for c in cmdlist.values()]
823 ui.write("%s\n" % "\n".join(sorted(cmdlist))) 851 ui.write("%s\n" % "\n".join(sorted(cmdlist)))
824 852
825 def debugfsinfo(ui, path = "."): 853 def debugfsinfo(ui, path = "."):
854 """show information detected about current filesystem"""
826 open('.debugfsinfo', 'w').write('') 855 open('.debugfsinfo', 'w').write('')
827 ui.write('exec: %s\n' % (util.checkexec(path) and 'yes' or 'no')) 856 ui.write('exec: %s\n' % (util.checkexec(path) and 'yes' or 'no'))
828 ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no')) 857 ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no'))
829 ui.write('case-sensitive: %s\n' % (util.checkcase('.debugfsinfo') 858 ui.write('case-sensitive: %s\n' % (util.checkcase('.debugfsinfo')
830 and 'yes' or 'no')) 859 and 'yes' or 'no'))
877 With multiple arguments, print names and values of all config 906 With multiple arguments, print names and values of all config
878 items with matching section names. 907 items with matching section names.
879 908
880 With --debug, the source (filename and line number) is printed 909 With --debug, the source (filename and line number) is printed
881 for each config item. 910 for each config item.
911
912 Returns 0 on success.
882 """ 913 """
883 914
884 for f in util.rcpath(): 915 for f in util.rcpath():
885 ui.debug(_('read config from: %s\n') % f) 916 ui.debug(_('read config from: %s\n') % f)
886 untrusted = bool(opts.get('untrusted')) 917 untrusted = bool(opts.get('untrusted'))
907 def debugsetparents(ui, repo, rev1, rev2=None): 938 def debugsetparents(ui, repo, rev1, rev2=None):
908 """manually set the parents of the current working directory 939 """manually set the parents of the current working directory
909 940
910 This is useful for writing repository conversion tools, but should 941 This is useful for writing repository conversion tools, but should
911 be used with care. 942 be used with care.
943
944 Returns 0 on success.
912 """ 945 """
913 946
914 if not rev2: 947 if not rev2:
915 rev2 = hex(nullid) 948 rev2 = hex(nullid)
916 949
998 if pp[1] != nullid: 1031 if pp[1] != nullid:
999 ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i)) 1032 ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i))
1000 ui.write("}\n") 1033 ui.write("}\n")
1001 1034
1002 def debuginstall(ui): 1035 def debuginstall(ui):
1003 '''test Mercurial installation''' 1036 '''test Mercurial installation
1037
1038 Returns 0 on success.
1039 '''
1004 1040
1005 def writetemp(contents): 1041 def writetemp(contents):
1006 (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-") 1042 (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-")
1007 f = os.fdopen(fd, "wb") 1043 f = os.fdopen(fd, "wb")
1008 f.write(contents) 1044 f.write(contents)
1159 files it detects as binary. With -a, diff will generate a diff 1195 files it detects as binary. With -a, diff will generate a diff
1160 anyway, probably with undesirable results. 1196 anyway, probably with undesirable results.
1161 1197
1162 Use the -g/--git option to generate diffs in the git extended diff 1198 Use the -g/--git option to generate diffs in the git extended diff
1163 format. For more information, read :hg:`help diffs`. 1199 format. For more information, read :hg:`help diffs`.
1200
1201 Returns 0 on success.
1164 """ 1202 """
1165 1203
1166 revs = opts.get('rev') 1204 revs = opts.get('rev')
1167 change = opts.get('change') 1205 change = opts.get('change')
1168 stat = opts.get('stat') 1206 stat = opts.get('stat')
1216 Use the -g/--git option to generate diffs in the git extended diff 1254 Use the -g/--git option to generate diffs in the git extended diff
1217 format. See :hg:`help diffs` for more information. 1255 format. See :hg:`help diffs` for more information.
1218 1256
1219 With the --switch-parent option, the diff will be against the 1257 With the --switch-parent option, the diff will be against the
1220 second parent. It can be useful to review a merge. 1258 second parent. It can be useful to review a merge.
1259
1260 Returns 0 on success.
1221 """ 1261 """
1222 changesets += tuple(opts.get('rev', [])) 1262 changesets += tuple(opts.get('rev', []))
1223 if not changesets: 1263 if not changesets:
1224 raise util.Abort(_("export requires at least one changeset")) 1264 raise util.Abort(_("export requires at least one changeset"))
1225 revs = cmdutil.revrange(repo, changesets) 1265 revs = cmdutil.revrange(repo, changesets)
1240 This only removes files from the current branch, not from the 1280 This only removes files from the current branch, not from the
1241 entire project history, and it does not delete them from the 1281 entire project history, and it does not delete them from the
1242 working directory. 1282 working directory.
1243 1283
1244 To undo a forget before the next commit, see hg add. 1284 To undo a forget before the next commit, see hg add.
1285
1286 Returns 0 on success.
1245 """ 1287 """
1246 1288
1247 if not pats: 1289 if not pats:
1248 raise util.Abort(_('no files specified')) 1290 raise util.Abort(_('no files specified'))
1249 1291
1250 m = cmdutil.match(repo, pats, opts) 1292 m = cmdutil.match(repo, pats, opts)
1251 s = repo.status(match=m, clean=True) 1293 s = repo.status(match=m, clean=True)
1252 forget = sorted(s[0] + s[1] + s[3] + s[6]) 1294 forget = sorted(s[0] + s[1] + s[3] + s[6])
1295 errs = 0
1253 1296
1254 for f in m.files(): 1297 for f in m.files():
1255 if f not in repo.dirstate and not os.path.isdir(m.rel(f)): 1298 if f not in repo.dirstate and not os.path.isdir(m.rel(f)):
1256 ui.warn(_('not removing %s: file is already untracked\n') 1299 ui.warn(_('not removing %s: file is already untracked\n')
1257 % m.rel(f)) 1300 % m.rel(f))
1301 errs = 1
1258 1302
1259 for f in forget: 1303 for f in forget:
1260 if ui.verbose or not m.exact(f): 1304 if ui.verbose or not m.exact(f):
1261 ui.status(_('removing %s\n') % m.rel(f)) 1305 ui.status(_('removing %s\n') % m.rel(f))
1262 1306
1263 repo.remove(forget, unlink=False) 1307 repo.remove(forget, unlink=False)
1308 return errs
1264 1309
1265 def grep(ui, repo, pattern, *pats, **opts): 1310 def grep(ui, repo, pattern, *pats, **opts):
1266 """search for a pattern in specified files and revisions 1311 """search for a pattern in specified files and revisions
1267 1312
1268 Search revisions of files for a regular expression. 1313 Search revisions of files for a regular expression.
1275 By default, grep only prints output for the first revision of a 1320 By default, grep only prints output for the first revision of a
1276 file in which it finds a match. To get it to print every revision 1321 file in which it finds a match. To get it to print every revision
1277 that contains a change in match status ("-" for a match that 1322 that contains a change in match status ("-" for a match that
1278 becomes a non-match, or "+" for a non-match that becomes a match), 1323 becomes a non-match, or "+" for a non-match that becomes a match),
1279 use the --all flag. 1324 use the --all flag.
1325
1326 Returns 0 if a match is found, 1 otherwise.
1280 """ 1327 """
1281 reflags = 0 1328 reflags = 0
1282 if opts.get('ignore_case'): 1329 if opts.get('ignore_case'):
1283 reflags |= re.I 1330 reflags |= re.I
1284 try: 1331 try:
1285 regexp = re.compile(pattern, reflags) 1332 regexp = re.compile(pattern, reflags)
1286 except Exception, inst: 1333 except Exception, inst:
1287 ui.warn(_("grep: invalid match pattern: %s\n") % inst) 1334 ui.warn(_("grep: invalid match pattern: %s\n") % inst)
1288 return None 1335 return 1
1289 sep, eol = ':', '\n' 1336 sep, eol = ':', '\n'
1290 if opts.get('print0'): 1337 if opts.get('print0'):
1291 sep = eol = '\0' 1338 sep = eol = '\0'
1292 1339
1293 getfile = util.lrucachefunc(repo.file) 1340 getfile = util.lrucachefunc(repo.file)
1441 if copy: 1488 if copy:
1442 skip[copy] = True 1489 skip[copy] = True
1443 del matches[rev] 1490 del matches[rev]
1444 del revfiles[rev] 1491 del revfiles[rev]
1445 1492
1493 return not found
1494
1446 def heads(ui, repo, *branchrevs, **opts): 1495 def heads(ui, repo, *branchrevs, **opts):
1447 """show current repository heads or show branch heads 1496 """show current repository heads or show branch heads
1448 1497
1449 With no arguments, show all repository branch heads. 1498 With no arguments, show all repository branch heads.
1450 1499
1462 If STARTREV is specified, only those heads that are descendants of 1511 If STARTREV is specified, only those heads that are descendants of
1463 STARTREV will be displayed. 1512 STARTREV will be displayed.
1464 1513
1465 If -t/--topo is specified, named branch mechanics will be ignored and only 1514 If -t/--topo is specified, named branch mechanics will be ignored and only
1466 changesets without children will be shown. 1515 changesets without children will be shown.
1516
1517 Returns 0 if matching heads are found, 1 if not.
1467 """ 1518 """
1468 1519
1469 if opts.get('rev'): 1520 if opts.get('rev'):
1470 start = repo.lookup(opts['rev']) 1521 start = repo.lookup(opts['rev'])
1471 else: 1522 else:
1519 """show help for a given topic or a help overview 1570 """show help for a given topic or a help overview
1520 1571
1521 With no arguments, print a list of commands with short help messages. 1572 With no arguments, print a list of commands with short help messages.
1522 1573
1523 Given a topic, extension, or command name, print help for that 1574 Given a topic, extension, or command name, print help for that
1524 topic.""" 1575 topic.
1576
1577 Returns 0 if successful.
1578 """
1525 option_lists = [] 1579 option_lists = []
1526 textwidth = util.termwidth() - 2 1580 textwidth = util.termwidth() - 2
1527 1581
1528 def addglobalopts(aliases): 1582 def addglobalopts(aliases):
1529 if ui.verbose: 1583 if ui.verbose:
1777 1831
1778 This summary identifies the repository state using one or two 1832 This summary identifies the repository state using one or two
1779 parent hash identifiers, followed by a "+" if there are 1833 parent hash identifiers, followed by a "+" if there are
1780 uncommitted changes in the working directory, a list of tags for 1834 uncommitted changes in the working directory, a list of tags for
1781 this revision and a branch name for non-default branches. 1835 this revision and a branch name for non-default branches.
1836
1837 Returns 0 if successful.
1782 """ 1838 """
1783 1839
1784 if not repo and not source: 1840 if not repo and not source:
1785 raise util.Abort(_("There is no Mercurial repository here " 1841 raise util.Abort(_("There is no Mercurial repository here "
1786 "(.hg not found)")) 1842 "(.hg not found)"))
1872 copies in the patch in the same way as 'addremove'. 1928 copies in the patch in the same way as 'addremove'.
1873 1929
1874 To read a patch from standard input, use "-" as the patch name. If 1930 To read a patch from standard input, use "-" as the patch name. If
1875 a URL is specified, the patch will be downloaded from it. 1931 a URL is specified, the patch will be downloaded from it.
1876 See :hg:`help dates` for a list of formats valid for -d/--date. 1932 See :hg:`help dates` for a list of formats valid for -d/--date.
1933
1934 Returns 0 on success.
1877 """ 1935 """
1878 patches = (patch1,) + patches 1936 patches = (patch1,) + patches
1879 1937
1880 date = opts.get('date') 1938 date = opts.get('date')
1881 if date: 1939 if date:
2005 2063
2006 For remote repository, using --bundle avoids downloading the 2064 For remote repository, using --bundle avoids downloading the
2007 changesets twice if the incoming is followed by a pull. 2065 changesets twice if the incoming is followed by a pull.
2008 2066
2009 See pull for valid source format details. 2067 See pull for valid source format details.
2068
2069 Returns 0 if there are incoming changes, 1 otherwise.
2010 """ 2070 """
2011 limit = cmdutil.loglimit(opts) 2071 limit = cmdutil.loglimit(opts)
2012 source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch')) 2072 source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch'))
2013 other = hg.repository(cmdutil.remoteui(repo, opts), source) 2073 other = hg.repository(cmdutil.remoteui(repo, opts), source)
2014 ui.status(_('comparing with %s\n') % url.hidepassword(source)) 2074 ui.status(_('comparing with %s\n') % url.hidepassword(source))
2075 2135
2076 If no directory is given, the current directory is used. 2136 If no directory is given, the current directory is used.
2077 2137
2078 It is possible to specify an ``ssh://`` URL as the destination. 2138 It is possible to specify an ``ssh://`` URL as the destination.
2079 See :hg:`help urls` for more information. 2139 See :hg:`help urls` for more information.
2140
2141 Returns 0 on success.
2080 """ 2142 """
2081 hg.repository(cmdutil.remoteui(ui, opts), dest, create=1) 2143 hg.repository(cmdutil.remoteui(ui, opts), dest, create=1)
2082 2144
2083 def locate(ui, repo, *pats, **opts): 2145 def locate(ui, repo, *pats, **opts):
2084 """locate files matching specific patterns 2146 """locate files matching specific patterns
2095 2157
2096 If you want to feed the output of this command into the "xargs" 2158 If you want to feed the output of this command into the "xargs"
2097 command, use the -0 option to both this command and "xargs". This 2159 command, use the -0 option to both this command and "xargs". This
2098 will avoid the problem of "xargs" treating single filenames that 2160 will avoid the problem of "xargs" treating single filenames that
2099 contain whitespace as multiple filenames. 2161 contain whitespace as multiple filenames.
2162
2163 Returns 0 if a match is found, 1 otherwise.
2100 """ 2164 """
2101 end = opts.get('print0') and '\0' or '\n' 2165 end = opts.get('print0') and '\0' or '\n'
2102 rev = opts.get('rev') or None 2166 rev = opts.get('rev') or None
2103 2167
2104 ret = 1 2168 ret = 1
2140 2204
2141 NOTE: log -p/--patch may generate unexpected diff output for merge 2205 NOTE: log -p/--patch may generate unexpected diff output for merge
2142 changesets, as it will only compare the merge changeset against 2206 changesets, as it will only compare the merge changeset against
2143 its first parent. Also, only files different from BOTH parents 2207 its first parent. Also, only files different from BOTH parents
2144 will appear in files:. 2208 will appear in files:.
2209
2210 Returns 0 on success.
2145 """ 2211 """
2146 2212
2147 matchfn = cmdutil.match(repo, pats, opts) 2213 matchfn = cmdutil.match(repo, pats, opts)
2148 limit = cmdutil.loglimit(opts) 2214 limit = cmdutil.loglimit(opts)
2149 count = 0 2215 count = 0
2208 If no revision is given, the first parent of the working directory 2274 If no revision is given, the first parent of the working directory
2209 is used, or the null revision if no revision is checked out. 2275 is used, or the null revision if no revision is checked out.
2210 2276
2211 With -v, print file permissions, symlink and executable bits. 2277 With -v, print file permissions, symlink and executable bits.
2212 With --debug, print file revision hashes. 2278 With --debug, print file revision hashes.
2279
2280 Returns 0 on success.
2213 """ 2281 """
2214 2282
2215 if rev and node: 2283 if rev and node:
2216 raise util.Abort(_("please specify just one revision")) 2284 raise util.Abort(_("please specify just one revision"))
2217 2285
2240 2308
2241 If no revision is specified, the working directory's parent is a 2309 If no revision is specified, the working directory's parent is a
2242 head revision, and the current branch contains exactly one other 2310 head revision, and the current branch contains exactly one other
2243 head, the other head is merged with by default. Otherwise, an 2311 head, the other head is merged with by default. Otherwise, an
2244 explicit revision with which to merge with must be provided. 2312 explicit revision with which to merge with must be provided.
2313
2314 Returns 0 on success, 1 if there are unresolved files.
2245 """ 2315 """
2246 2316
2247 if opts.get('rev') and node: 2317 if opts.get('rev') and node:
2248 raise util.Abort(_("please specify just one revision")) 2318 raise util.Abort(_("please specify just one revision"))
2249 if not node: 2319 if not node:
2296 Show changesets not found in the specified destination repository 2366 Show changesets not found in the specified destination repository
2297 or the default push location. These are the changesets that would 2367 or the default push location. These are the changesets that would
2298 be pushed if a push was requested. 2368 be pushed if a push was requested.
2299 2369
2300 See pull for details of valid destination formats. 2370 See pull for details of valid destination formats.
2371
2372 Returns 0 if there are outgoing changes, 1 otherwise.
2301 """ 2373 """
2302 limit = cmdutil.loglimit(opts) 2374 limit = cmdutil.loglimit(opts)
2303 dest = ui.expandpath(dest or 'default-push', dest or 'default') 2375 dest = ui.expandpath(dest or 'default-push', dest or 'default')
2304 dest, branches = hg.parseurl(dest, opts.get('branch')) 2376 dest, branches = hg.parseurl(dest, opts.get('branch'))
2305 revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev')) 2377 revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev'))
2333 Print the working directory's parent revisions. If a revision is 2405 Print the working directory's parent revisions. If a revision is
2334 given via -r/--rev, the parent of that revision will be printed. 2406 given via -r/--rev, the parent of that revision will be printed.
2335 If a file argument is given, the revision in which the file was 2407 If a file argument is given, the revision in which the file was
2336 last changed (before the working directory revision or the 2408 last changed (before the working directory revision or the
2337 argument to --rev if given) is printed. 2409 argument to --rev if given) is printed.
2410
2411 Returns 0 on success.
2338 """ 2412 """
2339 rev = opts.get('rev') 2413 rev = opts.get('rev')
2340 if rev: 2414 if rev:
2341 ctx = repo[rev] 2415 ctx = repo[rev]
2342 else: 2416 else:
2430 added those changes to the repository, you should use pull -r X 2504 added those changes to the repository, you should use pull -r X
2431 where X is the last changeset listed by hg incoming. 2505 where X is the last changeset listed by hg incoming.
2432 2506
2433 If SOURCE is omitted, the 'default' path will be used. 2507 If SOURCE is omitted, the 'default' path will be used.
2434 See :hg:`help urls` for more information. 2508 See :hg:`help urls` for more information.
2509
2510 Returns 0 on success, 1 if an update had unresolved files.
2435 """ 2511 """
2436 source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch')) 2512 source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch'))
2437 other = hg.repository(cmdutil.remoteui(repo, opts), source) 2513 other = hg.repository(cmdutil.remoteui(repo, opts), source)
2438 ui.status(_('pulling from %s\n') % url.hidepassword(source)) 2514 ui.status(_('pulling from %s\n') % url.hidepassword(source))
2439 revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev')) 2515 revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev'))
2467 If -r/--rev is used, the named revision and all its ancestors will 2543 If -r/--rev is used, the named revision and all its ancestors will
2468 be pushed to the remote repository. 2544 be pushed to the remote repository.
2469 2545
2470 Please see :hg:`help urls` for important details about ``ssh://`` 2546 Please see :hg:`help urls` for important details about ``ssh://``
2471 URLs. If DESTINATION is omitted, a default path will be used. 2547 URLs. If DESTINATION is omitted, a default path will be used.
2548
2549 Returns 0 if push was successful, 1 if nothing to push.
2472 """ 2550 """
2473 dest = ui.expandpath(dest or 'default-push', dest or 'default') 2551 dest = ui.expandpath(dest or 'default-push', dest or 'default')
2474 dest, branches = hg.parseurl(dest, opts.get('branch')) 2552 dest, branches = hg.parseurl(dest, opts.get('branch'))
2475 revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev')) 2553 revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev'))
2476 other = hg.repository(cmdutil.remoteui(repo, opts), dest) 2554 other = hg.repository(cmdutil.remoteui(repo, opts), dest)
2494 Recover from an interrupted commit or pull. 2572 Recover from an interrupted commit or pull.
2495 2573
2496 This command tries to fix the repository status after an 2574 This command tries to fix the repository status after an
2497 interrupted operation. It should only be necessary when Mercurial 2575 interrupted operation. It should only be necessary when Mercurial
2498 suggests it. 2576 suggests it.
2577
2578 Returns 0 if successful, 1 if nothing to recover or verify fails.
2499 """ 2579 """
2500 if repo.recover(): 2580 if repo.recover():
2501 return hg.verify(repo) 2581 return hg.verify(repo)
2502 return 1 2582 return 1
2503 2583
2524 -A W W W R 2604 -A W W W R
2525 -Af R R R R 2605 -Af R R R R
2526 2606
2527 This command schedules the files to be removed at the next commit. 2607 This command schedules the files to be removed at the next commit.
2528 To undo a remove before that, see hg revert. 2608 To undo a remove before that, see hg revert.
2529 """ 2609
2530 2610 Returns 0 on success, 1 if any warnings encountered.
2611 """
2612
2613 ret = 0
2531 after, force = opts.get('after'), opts.get('force') 2614 after, force = opts.get('after'), opts.get('force')
2532 if not pats and not after: 2615 if not pats and not after:
2533 raise util.Abort(_('no files specified')) 2616 raise util.Abort(_('no files specified'))
2534 2617
2535 m = cmdutil.match(repo, pats, opts) 2618 m = cmdutil.match(repo, pats, opts)
2537 modified, added, deleted, clean = s[0], s[1], s[3], s[6] 2620 modified, added, deleted, clean = s[0], s[1], s[3], s[6]
2538 2621
2539 for f in m.files(): 2622 for f in m.files():
2540 if f not in repo.dirstate and not os.path.isdir(m.rel(f)): 2623 if f not in repo.dirstate and not os.path.isdir(m.rel(f)):
2541 ui.warn(_('not removing %s: file is untracked\n') % m.rel(f)) 2624 ui.warn(_('not removing %s: file is untracked\n') % m.rel(f))
2625 ret = 1
2542 2626
2543 def warn(files, reason): 2627 def warn(files, reason):
2544 for f in files: 2628 for f in files:
2545 ui.warn(_('not removing %s: file %s (use -f to force removal)\n') 2629 ui.warn(_('not removing %s: file %s (use -f to force removal)\n')
2546 % (m.rel(f), reason)) 2630 % (m.rel(f), reason))
2631 ret = 1
2547 2632
2548 if force: 2633 if force:
2549 remove, forget = modified + deleted + clean, added 2634 remove, forget = modified + deleted + clean, added
2550 elif after: 2635 elif after:
2551 remove, forget = deleted, [] 2636 remove, forget = deleted, []
2559 if ui.verbose or not m.exact(f): 2644 if ui.verbose or not m.exact(f):
2560 ui.status(_('removing %s\n') % m.rel(f)) 2645 ui.status(_('removing %s\n') % m.rel(f))
2561 2646
2562 repo.forget(forget) 2647 repo.forget(forget)
2563 repo.remove(remove, unlink=not after) 2648 repo.remove(remove, unlink=not after)
2649 return ret
2564 2650
2565 def rename(ui, repo, *pats, **opts): 2651 def rename(ui, repo, *pats, **opts):
2566 """rename files; equivalent of copy + remove 2652 """rename files; equivalent of copy + remove
2567 2653
2568 Mark dest as copies of sources; mark sources for deletion. If dest 2654 Mark dest as copies of sources; mark sources for deletion. If dest
2573 exist in the working directory. If invoked with -A/--after, the 2659 exist in the working directory. If invoked with -A/--after, the
2574 operation is recorded, but no copying is performed. 2660 operation is recorded, but no copying is performed.
2575 2661
2576 This command takes effect at the next commit. To undo a rename 2662 This command takes effect at the next commit. To undo a rename
2577 before that, see hg revert. 2663 before that, see hg revert.
2664
2665 Returns 0 on success, 1 if errors are encountered.
2578 """ 2666 """
2579 wlock = repo.wlock(False) 2667 wlock = repo.wlock(False)
2580 try: 2668 try:
2581 return cmdutil.copy(ui, repo, pats, opts, rename=True) 2669 return cmdutil.copy(ui, repo, pats, opts, rename=True)
2582 finally: 2670 finally:
2606 (or ``-a`` for all unresolved files) 2694 (or ``-a`` for all unresolved files)
2607 2695
2608 Note that Mercurial will not let you commit files with unresolved merge 2696 Note that Mercurial will not let you commit files with unresolved merge
2609 conflicts. You must use ``hg resolve -m ...`` before you can commit 2697 conflicts. You must use ``hg resolve -m ...`` before you can commit
2610 after a conflicting merge. 2698 after a conflicting merge.
2699
2700 Returns 0 on success, 1 if any files fail a resolve attempt.
2611 """ 2701 """
2612 2702
2613 all, mark, unmark, show, nostatus = \ 2703 all, mark, unmark, show, nostatus = \
2614 [opts.get(o) for o in 'all mark unmark list no_status'.split()] 2704 [opts.get(o) for o in 'all mark unmark list no_status'.split()]
2615 2705
2621 raise util.Abort(_('no files or directories specified; ' 2711 raise util.Abort(_('no files or directories specified; '
2622 'use --all to remerge all files')) 2712 'use --all to remerge all files'))
2623 2713
2624 ms = mergemod.mergestate(repo) 2714 ms = mergemod.mergestate(repo)
2625 m = cmdutil.match(repo, pats, opts) 2715 m = cmdutil.match(repo, pats, opts)
2716 ret = 0
2626 2717
2627 for f in ms: 2718 for f in ms:
2628 if m(f): 2719 if m(f):
2629 if show: 2720 if show:
2630 if nostatus: 2721 if nostatus:
2644 # backup pre-resolve (merge uses .orig for its own purposes) 2735 # backup pre-resolve (merge uses .orig for its own purposes)
2645 a = repo.wjoin(f) 2736 a = repo.wjoin(f)
2646 util.copyfile(a, a + ".resolve") 2737 util.copyfile(a, a + ".resolve")
2647 2738
2648 # resolve file 2739 # resolve file
2649 ms.resolve(f, wctx, mctx) 2740 if ms.resolve(f, wctx, mctx):
2741 ret = 1
2650 2742
2651 # replace filemerge's .orig file with our resolve file 2743 # replace filemerge's .orig file with our resolve file
2652 util.rename(a + ".resolve", a + ".orig") 2744 util.rename(a + ".resolve", a + ".orig")
2745 return ret
2653 2746
2654 def revert(ui, repo, *pats, **opts): 2747 def revert(ui, repo, *pats, **opts):
2655 """restore individual files or directories to an earlier state 2748 """restore individual files or directories to an earlier state
2656 2749
2657 (Use update -r to check out earlier revisions, revert does not 2750 (Use update -r to check out earlier revisions, revert does not
2681 If names are given, all files matching the names are reverted. 2774 If names are given, all files matching the names are reverted.
2682 If no arguments are given, no files are reverted. 2775 If no arguments are given, no files are reverted.
2683 2776
2684 Modified files are saved with a .orig suffix before reverting. 2777 Modified files are saved with a .orig suffix before reverting.
2685 To disable these backups, use --no-backup. 2778 To disable these backups, use --no-backup.
2779
2780 Returns 0 on success.
2686 """ 2781 """
2687 2782
2688 if opts["date"]: 2783 if opts["date"]:
2689 if opts["rev"]: 2784 if opts["rev"]:
2690 raise util.Abort(_("you can't specify a revision and a date")) 2785 raise util.Abort(_("you can't specify a revision and a date"))
2893 changes are visible for pull by other users, rolling a transaction 2988 changes are visible for pull by other users, rolling a transaction
2894 back locally is ineffective (someone else may already have pulled 2989 back locally is ineffective (someone else may already have pulled
2895 the changes). Furthermore, a race is possible with readers of the 2990 the changes). Furthermore, a race is possible with readers of the
2896 repository; for example an in-progress pull from the repository 2991 repository; for example an in-progress pull from the repository
2897 may fail if a rollback is performed. 2992 may fail if a rollback is performed.
2898 """ 2993
2899 repo.rollback(opts.get('dry_run')) 2994 Returns 0 on success, 1 if no rollback data is available.
2995 """
2996 return repo.rollback(opts.get('dry_run'))
2900 2997
2901 def root(ui, repo): 2998 def root(ui, repo):
2902 """print the root (top) of the current working directory 2999 """print the root (top) of the current working directory
2903 3000
2904 Print the root directory of the current repository. 3001 Print the root directory of the current repository.
3002
3003 Returns 0 on success.
2905 """ 3004 """
2906 ui.write(repo.root + "\n") 3005 ui.write(repo.root + "\n")
2907 3006
2908 def serve(ui, repo, **opts): 3007 def serve(ui, repo, **opts):
2909 """start stand-alone webserver 3008 """start stand-alone webserver
2924 files. 3023 files.
2925 3024
2926 To have the server choose a free port number to listen on, specify 3025 To have the server choose a free port number to listen on, specify
2927 a port number of 0; in this case, the server will print the port 3026 a port number of 0; in this case, the server will print the port
2928 number it uses. 3027 number it uses.
3028
3029 Returns 0 on success.
2929 """ 3030 """
2930 3031
2931 if opts["stdio"]: 3032 if opts["stdio"]:
2932 if repo is None: 3033 if repo is None:
2933 raise error.RepoError(_("There is no Mercurial repository here" 3034 raise error.RepoError(_("There is no Mercurial repository here"
3030 C = clean 3131 C = clean
3031 ! = missing (deleted by non-hg command, but still tracked) 3132 ! = missing (deleted by non-hg command, but still tracked)
3032 ? = not tracked 3133 ? = not tracked
3033 I = ignored 3134 I = ignored
3034 = origin of the previous file listed as A (added) 3135 = origin of the previous file listed as A (added)
3136
3137 Returns 0 on success.
3035 """ 3138 """
3036 3139
3037 revs = opts.get('rev') 3140 revs = opts.get('rev')
3038 change = opts.get('change') 3141 change = opts.get('change')
3039 3142
3093 This generates a brief summary of the working directory state, 3196 This generates a brief summary of the working directory state,
3094 including parents, branch, commit status, and available updates. 3197 including parents, branch, commit status, and available updates.
3095 3198
3096 With the --remote option, this will check the default paths for 3199 With the --remote option, this will check the default paths for
3097 incoming and outgoing changes. This can be time-consuming. 3200 incoming and outgoing changes. This can be time-consuming.
3201
3202 Returns 0 on success.
3098 """ 3203 """
3099 3204
3100 ctx = repo[None] 3205 ctx = repo[None]
3101 parents = ctx.parents() 3206 parents = ctx.parents()
3102 pnode = parents[0].node() 3207 pnode = parents[0].node()
3237 3342
3238 See :hg:`help dates` for a list of formats valid for -d/--date. 3343 See :hg:`help dates` for a list of formats valid for -d/--date.
3239 3344
3240 Since tag names have priority over branch names during revision 3345 Since tag names have priority over branch names during revision
3241 lookup, using an existing branch name as a tag name is discouraged. 3346 lookup, using an existing branch name as a tag name is discouraged.
3347
3348 Returns 0 on success.
3242 """ 3349 """
3243 3350
3244 rev_ = "." 3351 rev_ = "."
3245 names = [t.strip() for t in (name1,) + names] 3352 names = [t.strip() for t in (name1,) + names]
3246 if len(names) != len(set(names)): 3353 if len(names) != len(set(names)):
3291 def tags(ui, repo): 3398 def tags(ui, repo):
3292 """list repository tags 3399 """list repository tags
3293 3400
3294 This lists both regular and local tags. When the -v/--verbose 3401 This lists both regular and local tags. When the -v/--verbose
3295 switch is used, a third column "local" is printed for local tags. 3402 switch is used, a third column "local" is printed for local tags.
3403
3404 Returns 0 on success.
3296 """ 3405 """
3297 3406
3298 hexfunc = ui.debugflag and hex or short 3407 hexfunc = ui.debugflag and hex or short
3299 tagtype = "" 3408 tagtype = ""
3300 3409
3326 3435
3327 If you have just made a commit, that commit will be the tip. If 3436 If you have just made a commit, that commit will be the tip. If
3328 you have just pulled changes from another repository, the tip of 3437 you have just pulled changes from another repository, the tip of
3329 that repository becomes the current tip. The "tip" tag is special 3438 that repository becomes the current tip. The "tip" tag is special
3330 and cannot be renamed or assigned to a different changeset. 3439 and cannot be renamed or assigned to a different changeset.
3440
3441 Returns 0 on success.
3331 """ 3442 """
3332 displayer = cmdutil.show_changeset(ui, repo, opts) 3443 displayer = cmdutil.show_changeset(ui, repo, opts)
3333 displayer.show(repo[len(repo) - 1]) 3444 displayer.show(repo[len(repo) - 1])
3334 displayer.close() 3445 displayer.close()
3335 3446
3336 def unbundle(ui, repo, fname1, *fnames, **opts): 3447 def unbundle(ui, repo, fname1, *fnames, **opts):
3337 """apply one or more changegroup files 3448 """apply one or more changegroup files
3338 3449
3339 Apply one or more compressed changegroup files generated by the 3450 Apply one or more compressed changegroup files generated by the
3340 bundle command. 3451 bundle command.
3452
3453 Returns 0 on success, 1 if an update has unresolved files.
3341 """ 3454 """
3342 fnames = (fname1,) + fnames 3455 fnames = (fname1,) + fnames
3343 3456
3344 lock = repo.lock() 3457 lock = repo.lock()
3345 try: 3458 try:
3384 :hg:`clone -U`). 3497 :hg:`clone -U`).
3385 3498
3386 If you want to update just one file to an older changeset, use :hg:`revert`. 3499 If you want to update just one file to an older changeset, use :hg:`revert`.
3387 3500
3388 See :hg:`help dates` for a list of formats valid for -d/--date. 3501 See :hg:`help dates` for a list of formats valid for -d/--date.
3502
3503 Returns 0 on success, 1 if there are unresolved files.
3389 """ 3504 """
3390 if rev and node: 3505 if rev and node:
3391 raise util.Abort(_("please specify just one revision")) 3506 raise util.Abort(_("please specify just one revision"))
3392 3507
3393 if not rev: 3508 if not rev:
3419 3534
3420 This will perform an extensive check of the repository's 3535 This will perform an extensive check of the repository's
3421 integrity, validating the hashes and checksums of each entry in 3536 integrity, validating the hashes and checksums of each entry in
3422 the changelog, manifest, and tracked files, as well as the 3537 the changelog, manifest, and tracked files, as well as the
3423 integrity of their crosslinks and indices. 3538 integrity of their crosslinks and indices.
3539
3540 Returns 0 on success, 1 if errors are encountered.
3424 """ 3541 """
3425 return hg.verify(repo) 3542 return hg.verify(repo)
3426 3543
3427 def version_(ui): 3544 def version_(ui):
3428 """output version and copyright information""" 3545 """output version and copyright information"""