Bug 1287439 - Update robustcheckout extension with upstream; r?Callek draft
authorGregory Szorc <gps@mozilla.com>
Mon, 18 Jul 2016 10:24:27 -0700
changeset 389116 71391599ccd9fbd925f0d086175b95a6e020d32f
parent 389110 69a9474a32061e0afc22ad93f0683934cff0c531
child 525662 c6332e0be3b423269d986f390337f0dd699d31b5
push id23306
push userbmo:gps@mozilla.com
push dateMon, 18 Jul 2016 17:24:43 +0000
reviewersCallek
bugs1287439
milestone50.0a1
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: 676o5IVE536
testing/mozharness/external_tools/robustcheckout.py
--- a/testing/mozharness/external_tools/robustcheckout.py
+++ b/testing/mozharness/external_tools/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)