Bug 1287439 - Update robustcheckout extension with upstream; r?Callek
Synchronized with hgext/robustcheckout/__init.py
from https://hg.mozilla.org/hgcustom/version-control-tools at revision
d2140637eaf3f91fefa7c2f44cbaabf4c19faeb3.
MozReview-Commit-ID: 2rczw0BNL99
--- a/hgext/robustcheckout.py
+++ b/hgext/robustcheckout.py
@@ -13,16 +13,17 @@ from __future__ import absolute_import
import contextlib
import errno
import functools
import os
import re
from mercurial.i18n import _
+from mercurial.node import hex
from mercurial import (
commands,
error,
exchange,
extensions,
cmdutil,
hg,
scmutil,
@@ -254,27 +255,37 @@ def _docheckout(ui, url, dest, upstream,
if revision and revision in repo:
ctx = repo[revision]
if not ctx.hex().startswith(revision):
raise error.Abort('--revision argument is ambiguous',
hint='must be the first 12+ characters of a '
'SHA-1 fragment')
+ checkoutrevision = ctx.hex()
havewantedrev = True
if not havewantedrev:
ui.write('(pulling to obtain %s)\n' % (revision or branch,))
try:
remote = hg.peer(repo, {}, url)
pullrevs = [remote.lookup(revision or branch)]
- pullop = exchange.pull(repo, remote, heads=pullrevs)
- if not pullop.rheads:
- raise error.Abort('unable to pull requested revision')
+ checkoutrevision = hex(pullrevs[0])
+ if branch:
+ ui.warn('(remote resolved %s to %s; '
+ 'result is not deterministic)\n' %
+ (branch, checkoutrevision))
+
+ if checkoutrevision in repo:
+ ui.warn('(revision already present locally; not pulling)\n')
+ else:
+ pullop = exchange.pull(repo, remote, heads=pullrevs)
+ if not pullop.rheads:
+ raise error.Abort('unable to pull requested revision')
except error.Abort as e:
if e.message == _('repository is unrelated'):
ui.warn('(repository is unrelated; deleting)\n')
destvfs.rmtree(forcibly=True)
return callself()
raise
except error.RepoError as e:
@@ -298,21 +309,20 @@ def _docheckout(ui, url, dest, upstream,
if purgeext.purge(ui, repo, all=True, abort_on_err=True,
# The function expects all arguments to be
# defined.
**{'print': None, 'print0': None, 'dirs': None,
'files': None}):
raise error.Abort('error purging')
# Update the working directory.
- if commands.update(ui, repo, rev=revision or branch, clean=True):
+ if commands.update(ui, repo, rev=checkoutrevision, clean=True):
raise error.Abort('error updating')
- ctx = repo[revision or branch]
- ui.write('updated to %s\n' % ctx.hex())
+ ui.write('updated to %s\n' % checkoutrevision)
return None
def extsetup(ui):
# Ensure required extensions are loaded.
for ext in ('purge', 'share'):
try:
extensions.find(ext)