##// END OF EJS Templates
[PATCH] Clean up destination directory if a clone fails....
mpm@selenic.com -
r500:ebc4714a default
parent child Browse files
Show More
@@ -234,7 +234,7 b' def annotate(u, repo, file, *files, **op'
234 name = name[:f]
234 name = name[:f]
235 bcache[rev] = name
235 bcache[rev] = name
236 return name
236 return name
237
237
238 bcache = {}
238 bcache = {}
239 opmap = [['user', getname], ['number', str], ['changeset', getnode]]
239 opmap = [['user', getname], ['number', str], ['changeset', getnode]]
240 if not ops['user'] and not ops['changeset']:
240 if not ops['user'] and not ops['changeset']:
@@ -273,42 +273,53 b' def clone(ui, source, dest = None, **opt'
273
273
274 if source in paths: source = paths[source]
274 if source in paths: source = paths[source]
275
275
276 created = False
277
276 if dest is None:
278 if dest is None:
277 dest = os.getcwd()
279 dest = os.getcwd()
278 elif not os.path.exists(dest):
280 elif not os.path.exists(dest):
279 os.makedirs(dest)
281 os.mkdir(dest)
282 created = True
283
284 try:
285 dest = os.path.realpath(dest)
280
286
281 link = 0
287 link = 0
282 if not source.startswith("http://"):
288 if not source.startswith("http://"):
283 source = os.path.realpath(source)
289 source = os.path.realpath(source)
284 d1 = os.stat(dest).st_dev
290 d1 = os.stat(dest).st_dev
285 d2 = os.stat(source).st_dev
291 d2 = os.stat(source).st_dev
286 if d1 == d2: link = 1
292 if d1 == d2: link = 1
287
293
288 os.chdir(dest)
294 os.chdir(dest)
289
295
290 if link:
296 if link:
291 ui.debug("copying by hardlink\n")
297 ui.debug("copying by hardlink\n")
292 os.system("cp -al %s/.hg .hg" % source)
298 os.system("cp -al %s/.hg .hg" % source)
293 try:
299 try:
294 os.remove(".hg/dirstate")
300 os.remove(".hg/dirstate")
295 except: pass
301 except: pass
296
302
297 repo = hg.repository(ui, ".")
303 repo = hg.repository(ui, ".")
298
304
299 else:
305 else:
300 repo = hg.repository(ui, ".", create=1)
306 repo = hg.repository(ui, ".", create=1)
301 other = hg.repository(ui, source)
307 other = hg.repository(ui, source)
302 cg = repo.getchangegroup(other)
308 cg = repo.getchangegroup(other)
303 repo.addchangegroup(cg)
309 repo.addchangegroup(cg)
304
310
305 f = repo.opener("hgrc", "w")
311 f = repo.opener("hgrc", "w")
306 f.write("[paths]\n")
312 f.write("[paths]\n")
307 f.write("default = %s\n" % source)
313 f.write("default = %s\n" % source)
308
314
309 if not opts['no-update']:
315 if not opts['no-update']:
310 update(ui, repo)
316 update(ui, repo)
311
317 except:
318 if created:
319 import shutil
320 shutil.rmtree(dest, True)
321 raise
322
312 def commit(ui, repo, *files, **opts):
323 def commit(ui, repo, *files, **opts):
313 """commit the specified files or all outstanding changes"""
324 """commit the specified files or all outstanding changes"""
314 text = opts['text']
325 text = opts['text']
@@ -459,7 +470,7 b' def import_(ui, repo, patch1, *patches, '
459 pass
470 pass
460
471
461 patches = (patch1,) + patches
472 patches = (patch1,) + patches
462
473
463 d = opts["base"]
474 d = opts["base"]
464 strip = opts["strip"]
475 strip = opts["strip"]
465
476
@@ -543,7 +554,7 b' def pull(ui, repo, source="default", **o'
543 source = paths[source]
554 source = paths[source]
544
555
545 ui.status('pulling from %s\n' % (source))
556 ui.status('pulling from %s\n' % (source))
546
557
547 other = hg.repository(ui, source)
558 other = hg.repository(ui, source)
548 cg = repo.getchangegroup(other)
559 cg = repo.getchangegroup(other)
549 r = repo.addchangegroup(cg)
560 r = repo.addchangegroup(cg)
@@ -562,7 +573,7 b' def push(ui, repo, dest="default-push"):'
562 paths[name] = path
573 paths[name] = path
563
574
564 if dest in paths: dest = paths[dest]
575 if dest in paths: dest = paths[dest]
565
576
566 if not dest.startswith("ssh://"):
577 if not dest.startswith("ssh://"):
567 ui.warn("abort: can only push to ssh:// destinations currently\n")
578 ui.warn("abort: can only push to ssh:// destinations currently\n")
568 return 1
579 return 1
@@ -607,9 +618,9 b' def rawcommit(ui, repo, *flist, **rc):'
607 files += open(rc['files']).read().splitlines()
618 files += open(rc['files']).read().splitlines()
608
619
609 rc['parent'] = map(repo.lookup, rc['parent'])
620 rc['parent'] = map(repo.lookup, rc['parent'])
610
621
611 repo.rawcommit(files, text, rc['user'], rc['date'], *rc['parent'])
622 repo.rawcommit(files, text, rc['user'], rc['date'], *rc['parent'])
612
623
613 def recover(ui, repo):
624 def recover(ui, repo):
614 """roll back an interrupted transaction"""
625 """roll back an interrupted transaction"""
615 repo.recover()
626 repo.recover()
@@ -626,7 +637,7 b' def serve(ui, repo, **opts):'
626 """export the repository via HTTP"""
637 """export the repository via HTTP"""
627 hgweb.server(repo.root, opts["name"], opts["templates"],
638 hgweb.server(repo.root, opts["name"], opts["templates"],
628 opts["address"], opts["port"])
639 opts["address"], opts["port"])
629
640
630 def status(ui, repo):
641 def status(ui, repo):
631 '''show changed files in the working directory
642 '''show changed files in the working directory
632
643
@@ -645,7 +656,7 b' def status(ui, repo):'
645
656
646 def tag(ui, repo, name, rev = None, **opts):
657 def tag(ui, repo, name, rev = None, **opts):
647 """add a tag for the current tip or a given revision"""
658 """add a tag for the current tip or a given revision"""
648
659
649 if name == "tip":
660 if name == "tip":
650 ui.warn("abort: 'tip' is a reserved name!\n")
661 ui.warn("abort: 'tip' is a reserved name!\n")
651 return -1
662 return -1
@@ -755,7 +766,7 b' table = {'
755 "log": (log, [], 'hg log <file>'),
766 "log": (log, [], 'hg log <file>'),
756 "manifest": (manifest, [], 'hg manifest [rev]'),
767 "manifest": (manifest, [], 'hg manifest [rev]'),
757 "parents": (parents, [], 'hg parents [node]'),
768 "parents": (parents, [], 'hg parents [node]'),
758 "pull": (pull,
769 "pull": (pull,
759 [('u', 'update', None, 'update working directory')],
770 [('u', 'update', None, 'update working directory')],
760 'hg pull [options] [source]'),
771 'hg pull [options] [source]'),
761 "push": (push, [], 'hg push <destination>'),
772 "push": (push, [], 'hg push <destination>'),
General Comments 0
You need to be logged in to leave comments. Login now