python/mozversioncontrol/mozversioncontrol/repoupdate.py
author Jan de Mooij <jdemooij@mozilla.com>
Mon, 18 Nov 2013 13:14:08 +0100
changeset 170686 a42ee99942e1be6d423689d1ff9eceb3c4d86b01
parent 152766 57bf6621279b17e24aa3a30fab1969f9695363b1
child 171556 7b29554d41e050ec681d1ade56a850bef33e405c
permissions -rw-r--r--
Bug 937540 part 6 - Pass TempAllocator to IonAllocPolicy. r=luke

# 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 http://mozilla.org/MPL/2.0/.

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."""
    if os.path.exists(path):
        subprocess.check_call([hg, 'pull', repo], cwd=path)
    else:
        subprocess.check_call([hg, '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)
    else:
        subprocess.check_call([git, 'clone', repo, path])

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