Bumping manifests a=b2g-bump
[gecko.git] / python / mozversioncontrol / mozversioncontrol / repoupdate.py
blob604db4b6672c0d7bc724eab3ced603e9b559ffee
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this,
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 from __future__ import unicode_literals
7 import os
8 import subprocess
10 # The logic here is far from robust. Improvements are welcome.
12 def update_mercurial_repo(hg, repo, path, revision='default',
13 hostfingerprints=None):
14 """Ensure a HG repository exists at a path and is up to date."""
15 hostfingerprints = hostfingerprints or {}
17 args = [hg]
19 for host, fingerprint in sorted(hostfingerprints.items()):
20 args.extend(['--config', 'hostfingerprints.%s=%s' % (host,
21 fingerprint)])
23 if os.path.exists(path):
24 subprocess.check_call(args + ['pull', repo], cwd=path)
25 else:
26 subprocess.check_call(args + ['clone', repo, path])
28 subprocess.check_call([hg, 'update', '-r', revision], cwd=path)
31 def update_git_repo(git, repo, path, revision='origin/master'):
32 """Ensure a Git repository exists at a path and is up to date."""
33 if os.path.exists(path):
34 subprocess.check_call([git, 'fetch', '--all'], cwd=path)
35 else:
36 subprocess.check_call([git, 'clone', repo, path])
38 subprocess.check_call([git, 'checkout', revision], cwd=path)