author Bob Owen <>
Thu, 19 Jun 2014 20:17:59 +0100
changeset 190155 120937b0d7c1683cb387d45a9cc786a87046ee1e
parent 156960 7b29554d41e050ec681d1ade56a850bef33e405c
child 192083 9ca6e87839f3bc428785466525cb5af8ea200fe6
permissions -rw-r--r--
Bug 1023969 - Part 3: Replace AutoPushJSContext in BluetoothManager GetAdapterTask::ParseSuccessfulReply. r=bholley

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this,
# file, You can obtain one at

from __future__ import unicode_literals

import os
import subprocess

# The logic here is far from robust. Improvements are welcome.

def update_mercurial_repo(hg, repo, path, revision='default',
    """Ensure a HG repository exists at a path and is up to date."""
    hostfingerprints = hostfingerprints or {}

    args = [hg]

    for host, fingerprint in sorted(hostfingerprints.items()):
        args.extend(['--config', 'hostfingerprints.%s=%s' % (host,

    if os.path.exists(path):
        subprocess.check_call(args + ['pull', repo], cwd=path)
        subprocess.check_call(args + ['clone', repo, path])

    subprocess.check_call([hg, 'update', '-r', revision], cwd=path)

def update_git_repo(git, repo, path, revision='origin/master'):
    """Ensure a Git repository exists at a path and is up to date."""
    if os.path.exists(path):
        subprocess.check_call([git, 'fetch', '--all'], cwd=path)
        subprocess.check_call([git, 'clone', repo, path])

    subprocess.check_call([git, 'checkout', revision], cwd=path)