Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bug 744200 - hg pull shouldn't use -r $REV. r=catlee

  • Loading branch information...
commit 8763a517a94cac916051a696e6304e9bde9f0768 1 parent ac0b42e
@rail rail authored
View
1  lib/python/mozilla_buildtools/test/init_hgrepo.sh
@@ -14,6 +14,7 @@ hg init
echo "Hello world $RANDOM" > hello.txt
hg add hello.txt
hg commit -m "Adding hello"
+hg tag TAG1
hg branch branch2 > /dev/null
echo "So long, farewell" >> hello.txt
View
57 lib/python/mozilla_buildtools/test/test_util_hg.py
@@ -7,7 +7,7 @@
import util.hg as hg
from util.hg import clone, pull, update, hg_ver, mercurial, _make_absolute, \
share, push, apply_and_push, HgUtilError, make_hg_url, get_branch, \
- get_branches, path, init, unbundle, adjust_paths
+ get_branches, path, init, unbundle, adjust_paths, is_hg_cset
from util.commands import run_cmd, get_output
def getRevisions(dest):
@@ -35,6 +35,34 @@ def testAbsoluteFilePath(self):
def testRelativeFilePath(self):
self.assertEquals(_make_absolute("file://foo/bar"), "file://%s/foo/bar" % os.getcwd())
+
+class TestIsHgCset(unittest.TestCase):
+
+ def testShortCset(self):
+ self.assertTrue(is_hg_cset('fd06332733e5'))
+
+ def testLongCset(self):
+ self.assertTrue(is_hg_cset('bf37aabfd9367aec573487ebe1f784108bbef73f'))
+
+ def testMediumCset(self):
+ self.assertTrue(is_hg_cset('1e3391794bac9d0e707a7681de3'))
+
+ def testInt(self):
+ self.assertFalse(is_hg_cset(1234567890))
+
+ def testTag(self):
+ self.assertFalse(is_hg_cset('FIREFOX_50_0_RELEASE'))
+
+ def testDefault(self):
+ self.assertFalse(is_hg_cset('default'))
+
+ def testTip(self):
+ self.assertFalse(is_hg_cset('tip'))
+
+ def testBranch(self):
+ self.assertFalse(is_hg_cset('GECKO77_203512230833_RELBRANCH'))
+
+
class TestHg(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
@@ -147,6 +175,33 @@ def testPullBranch(self):
else:
self.assertEquals(getRevisions(self.wc), self.revisions)
+ def testPullTag(self):
+ clone(self.repodir, self.wc)
+ run_cmd(['hg', 'tag', '-f', 'TAG1'], cwd=self.repodir)
+ revisions = getRevisions(self.repodir)
+
+ rev = pull(self.repodir, self.wc, revision='TAG1')
+ self.assertEquals(rev, revisions[1])
+ self.assertEquals(getRevisions(self.wc), revisions)
+
+ def testPullTip(self):
+ clone(self.repodir, self.wc)
+ run_cmd(['hg', 'tag', '-f', 'TAG1'], cwd=self.repodir)
+ revisions = getRevisions(self.repodir)
+
+ rev = pull(self.repodir, self.wc, revision='tip')
+ self.assertEquals(rev, revisions[0])
+ self.assertEquals(getRevisions(self.wc), revisions)
+
+ def testPullDefault(self):
+ clone(self.repodir, self.wc)
+ run_cmd(['hg', 'tag', '-f', 'TAG1'], cwd=self.repodir)
+ revisions = getRevisions(self.repodir)
+
+ rev = pull(self.repodir, self.wc, revision='default')
+ self.assertEquals(rev, revisions[0])
+ self.assertEquals(getRevisions(self.wc), revisions)
+
def testPullUnrelated(self):
# Create a new repo
repo2 = os.path.join(self.tmpdir, 'repo2')
View
26 lib/python/util/hg.py
@@ -62,6 +62,15 @@ def get_branches(path):
branches.append(line.split()[0])
return branches
+def is_hg_cset(rev):
+ """Retruns True if passed revision represents a valid HG revision
+ (long or short(er) 40 bit hex)"""
+ try:
+ _ = int(rev, 16)
+ return True
+ except (TypeError, ValueError):
+ return False
+
def hg_ver():
"""Returns the current version of hg, as a tuple of
(major, minor, build)"""
@@ -203,9 +212,6 @@ def common_args(revision=None, branch=None, ssh_username=None, ssh_key=None):
def pull(repo, dest, update_dest=True, mirrors=None, **kwargs):
"""Pulls changes from hg repo and places it in `dest`.
- If `revision` is set, only the specified revision and its ancestors will
- be pulled.
-
If `update_dest` is set, then `dest` will be updated to `revision` if
set, otherwise to `branch`, otherwise to the head of default.
@@ -215,8 +221,7 @@ def pull(repo, dest, update_dest=True, mirrors=None, **kwargs):
if mirrors:
for mirror in mirrors:
try:
- retval = pull(mirror, dest, update_dest=update_dest, **kwargs)
- return retval
+ return pull(mirror, dest, update_dest=update_dest, **kwargs)
except:
log.exception("Problem pulling from mirror %s", mirror)
continue
@@ -226,7 +231,16 @@ def pull(repo, dest, update_dest=True, mirrors=None, **kwargs):
# Convert repo to an absolute path if it's a local repository
repo = _make_absolute(repo)
cmd = ['hg', 'pull']
- cmd.extend(common_args(**kwargs))
+ # Don't pass -r to "hg pull", except when it's a valid HG revision.
+ # Pulling using tag names is dangerous: it uses the local .hgtags, so if
+ # the tag has moved on the remote side you won't pull the new revision the
+ # remote tag refers to.
+ pull_kwargs = kwargs.copy()
+ if 'revision' in pull_kwargs and \
+ not is_hg_cset(pull_kwargs['revision']):
+ del pull_kwargs['revision']
+
+ cmd.extend(common_args(**pull_kwargs))
cmd.append(repo)
run_cmd(cmd, cwd=dest)
Please sign in to comment.
Something went wrong with that request. Please try again.