mercurial/commands.py
changeset 1227 e3ea354d99b2
parent 1225 ea90162e210c
child 1229 2eb1cd695dd2
equal deleted inserted replaced
1226:f3837564ed03 1227:e3ea354d99b2
   590     """make a copy of an existing repository"""
   590     """make a copy of an existing repository"""
   591     if dest is None:
   591     if dest is None:
   592         dest = os.path.basename(os.path.normpath(source))
   592         dest = os.path.basename(os.path.normpath(source))
   593 
   593 
   594     if os.path.exists(dest):
   594     if os.path.exists(dest):
   595         ui.warn("abort: destination '%s' already exists\n" % dest)
   595         raise util.Abort("destination '%s' already exists")
   596         return 1
       
   597 
   596 
   598     dest = os.path.realpath(dest)
   597     dest = os.path.realpath(dest)
   599 
   598 
   600     class Dircleanup:
   599     class Dircleanup:
   601         def __init__(self, dir_):
   600         def __init__(self, dir_):
  1030     patches = (patch1,) + patches
  1029     patches = (patch1,) + patches
  1031 
  1030 
  1032     if not opts['force']:
  1031     if not opts['force']:
  1033         (c, a, d, u) = repo.changes()
  1032         (c, a, d, u) = repo.changes()
  1034         if c or a or d:
  1033         if c or a or d:
  1035             ui.warn("abort: outstanding uncommitted changes!\n")
  1034             raise util.Abort("outstanding uncommitted changes")
  1036             return 1
       
  1037 
  1035 
  1038     d = opts["base"]
  1036     d = opts["base"]
  1039     strip = opts["strip"]
  1037     strip = opts["strip"]
  1040 
  1038 
  1041     mailre = re.compile(r'(?:From |[\w-]+:)')
  1039     mailre = re.compile(r'(?:From |[\w-]+:)')
  1098 def incoming(ui, repo, source="default", **opts):
  1096 def incoming(ui, repo, source="default", **opts):
  1099     """show new changesets found in source"""
  1097     """show new changesets found in source"""
  1100     source = ui.expandpath(source)
  1098     source = ui.expandpath(source)
  1101     other = hg.repository(ui, source)
  1099     other = hg.repository(ui, source)
  1102     if not other.local():
  1100     if not other.local():
  1103         ui.warn("abort: incoming doesn't work for remote"
  1101         raise util.Abort("incoming doesn't work for remote repositories yet")
  1104                 + " repositories yet, sorry!\n")
       
  1105         return 1
       
  1106     o = repo.findincoming(other)
  1102     o = repo.findincoming(other)
  1107     if not o:
  1103     if not o:
  1108         return
  1104         return
  1109     o = other.newer(o)
  1105     o = other.newer(o)
  1110     o.reverse()
  1106     o.reverse()
  1282         try:
  1278         try:
  1283             message = open(rc['logfile']).read()
  1279             message = open(rc['logfile']).read()
  1284         except IOError:
  1280         except IOError:
  1285             pass
  1281             pass
  1286     if not message and not rc['logfile']:
  1282     if not message and not rc['logfile']:
  1287         ui.warn("abort: missing commit message\n")
  1283         raise util.Abort("missing commit message")
  1288         return 1
       
  1289 
  1284 
  1290     files = relpath(repo, list(flist))
  1285     files = relpath(repo, list(flist))
  1291     if rc['files']:
  1286     if rc['files']:
  1292         files += open(rc['files']).read().splitlines()
  1287         files += open(rc['files']).read().splitlines()
  1293 
  1288 
  1504     """add a tag for the current tip or a given revision"""
  1499     """add a tag for the current tip or a given revision"""
  1505     if opts['text']:
  1500     if opts['text']:
  1506         ui.warn("Warning: -t and --text is deprecated,"
  1501         ui.warn("Warning: -t and --text is deprecated,"
  1507                 " please use -m or --message instead.\n")
  1502                 " please use -m or --message instead.\n")
  1508     if name == "tip":
  1503     if name == "tip":
  1509         ui.warn("abort: 'tip' is a reserved name!\n")
  1504         raise util.Abort("the name 'tip' is reserved")
  1510         return -1
       
  1511     if rev:
  1505     if rev:
  1512         r = hex(repo.lookup(rev))
  1506         r = hex(repo.lookup(rev))
  1513     else:
  1507     else:
  1514         r = hex(repo.changelog.tip())
  1508         r = hex(repo.changelog.tip())
  1515 
  1509 
  1516     if name.find(revrangesep) >= 0:
  1510     if name.find(revrangesep) >= 0:
  1517         ui.warn("abort: '%s' cannot be used in a tag name\n" % revrangesep)
  1511         raise util.Abort("'%s' cannot be used in a tag name" % revrangesep)
  1518         return -1
       
  1519 
  1512 
  1520     if opts['local']:
  1513     if opts['local']:
  1521         repo.opener("localtags", "a").write("%s %s\n" % (r, name))
  1514         repo.opener("localtags", "a").write("%s %s\n" % (r, name))
  1522         return
  1515         return
  1523 
  1516 
  1524     (c, a, d, u) = repo.changes()
  1517     (c, a, d, u) = repo.changes()
  1525     for x in (c, a, d, u):
  1518     for x in (c, a, d, u):
  1526         if ".hgtags" in x:
  1519         if ".hgtags" in x:
  1527             ui.warn("abort: working copy of .hgtags is changed!\n")
  1520             raise util.Abort("working copy of .hgtags is changed "
  1528             ui.status("(please commit .hgtags manually)\n")
  1521                              "(please commit .hgtags manually)")
  1529             return -1
       
  1530 
  1522 
  1531     repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name))
  1523     repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name))
  1532     if repo.dirstate.state(".hgtags") == '?':
  1524     if repo.dirstate.state(".hgtags") == '?':
  1533         repo.add([".hgtags"])
  1525         repo.add([".hgtags"])
  1534 
  1526 
  1559 def unbundle(ui, repo, fname):
  1551 def unbundle(ui, repo, fname):
  1560     """apply a changegroup file"""
  1552     """apply a changegroup file"""
  1561     f = urllib.urlopen(fname)
  1553     f = urllib.urlopen(fname)
  1562 
  1554 
  1563     if f.read(4) != "HG10":
  1555     if f.read(4) != "HG10":
  1564         ui.warn("abort: not a Mercurial bundle file!\n")
  1556         raise util.Abort("%s: not a Mercurial bundle file" % fname)
  1565         return -1
       
  1566 
  1557 
  1567     class bzread:
  1558     class bzread:
  1568         def __init__(self, f):
  1559         def __init__(self, f):
  1569             self.zd = bz2.BZ2Decompressor()
  1560             self.zd = bz2.BZ2Decompressor()
  1570             self.f = f
  1561             self.f = f
  1989 
  1980 
  1990             if options['cwd']:
  1981             if options['cwd']:
  1991                 try:
  1982                 try:
  1992                     os.chdir(options['cwd'])
  1983                     os.chdir(options['cwd'])
  1993                 except OSError, inst:
  1984                 except OSError, inst:
  1994                     u.warn('abort: %s: %s\n' % (options['cwd'], inst.strerror))
  1985                     raise util.Abort('%s: %s' %
  1995                     sys.exit(1)
  1986                                      (options['cwd'], inst.strerror))
  1996 
  1987 
  1997             if cmd not in norepo.split():
  1988             if cmd not in norepo.split():
  1998                 path = options["repository"] or ""
  1989                 path = options["repository"] or ""
  1999                 repo = hg.repository(ui=u, path=path)
  1990                 repo = hg.repository(ui=u, path=path)
  2000                 for x in external:
  1991                 for x in external: