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
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 {}
19 for host
, fingerprint
in sorted(hostfingerprints
.items()):
20 args
.extend(['--config', 'hostfingerprints.%s=%s' % (host
,
23 if os
.path
.exists(path
):
24 subprocess
.check_call(args
+ ['pull', repo
], cwd
=path
)
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
)
36 subprocess
.check_call([git
, 'clone', repo
, path
])
38 subprocess
.check_call([git
, 'checkout', revision
], cwd
=path
)