Skip to content
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.

Commit

Permalink
Bug 685124, hgtool needs to recover from being killed, r=bhearsum, nt…
Browse files Browse the repository at this point in the history
…homas
  • Loading branch information
Chris AtLee committed Sep 9, 2011
1 parent 2efb6a8 commit 5c14d40
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
29 changes: 28 additions & 1 deletion lib/python/buildtools/test/test_util_hg.py
Expand Up @@ -6,7 +6,7 @@

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
get_branches, path
from util.commands import run_cmd, get_output

def getRevisions(dest):
Expand Down Expand Up @@ -418,3 +418,30 @@ def testApplyAndPushWithNoChange(self):
def c(r,a):
pass
self.assertRaises(HgUtilError, apply_and_push, self.wc, self.repodir, c)

def testPath(self):
clone(self.repodir, self.wc)
p = path(self.wc)
self.assertEquals(p, self.repodir)

def testBustedHgrc(self):
# Test that we can recover from hgrc being lost
shareBase = os.path.join(self.tmpdir, 'share')
sharerepo = os.path.join(shareBase, self.repodir.lstrip("/"))
os.mkdir(shareBase)
mercurial(self.repodir, self.wc, shareBase=shareBase)

# Delete .hg/hgrc
for d in sharerepo, self.wc:
f = os.path.join(d, '.hg', 'hgrc')
os.unlink(f)

# path is busted now
p = path(self.wc)
self.assertEquals(p, None)

# cloning again should fix this up
mercurial(self.repodir, self.wc, shareBase=shareBase)

p = path(self.wc)
self.assertEquals(p, self.repodir)
20 changes: 20 additions & 0 deletions lib/python/util/hg.py
Expand Up @@ -258,6 +258,18 @@ def mercurial(repo, dest, branch=None, revision=None, update_dest=True,
if shareBase:
sharedRepo = os.path.join(shareBase, get_repo_path(repo))
dest_sharedPath = os.path.join(dest, '.hg', 'sharedpath')

if os.path.exists(sharedRepo):
hgpath = path(sharedRepo, "default")

# Make sure that our default path is correct
if hgpath != _make_absolute(repo):
log.info("hg path isn't correct (%s should be %s); clobbering", hgpath, _make_absolute(repo))
# we need to clobber both the shared checkout and the dest,
# since hgrc needs to be in both places
remove_path(sharedRepo)
remove_path(dest)

if os.path.exists(dest_sharedPath):
# Make sure that the sharedpath points to sharedRepo
dest_sharedPath_data = os.path.normpath(open(dest_sharedPath).read())
Expand All @@ -267,6 +279,7 @@ def mercurial(repo, dest, branch=None, revision=None, update_dest=True,
log.info("We're currently shared from %s, but are being requested to pull from %s (%s); clobbering", dest_sharedPath_data, repo, norm_sharedRepo)
remove_path(dest)


try:
log.info("Updating shared repo")
mercurial(repo, sharedRepo, branch=branch, revision=revision,
Expand Down Expand Up @@ -354,3 +367,10 @@ def cleanOutgoingRevs(reponame, remote, username, sshKey):
ssh_key=sshKey))
for r in reversed(outgoingRevs):
run_cmd(['hg', 'strip', '-n', r[REVISION]], cwd=reponame)

def path(src, name='default'):
"""Returns the remote path associated with "name" """
try:
return get_output(['hg', 'path', name], cwd=src).strip()
except subprocess.CalledProcessError:
return None

0 comments on commit 5c14d40

Please sign in to comment.