diff options
Diffstat (limited to 'python/mozversioncontrol/mozversioncontrol/repoupdate.py')
-rw-r--r-- | python/mozversioncontrol/mozversioncontrol/repoupdate.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/python/mozversioncontrol/mozversioncontrol/repoupdate.py b/python/mozversioncontrol/mozversioncontrol/repoupdate.py new file mode 100644 index 0000000000..5336263794 --- /dev/null +++ b/python/mozversioncontrol/mozversioncontrol/repoupdate.py @@ -0,0 +1,37 @@ +# 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/. + +import subprocess +from pathlib import Path +from typing import Union + +# The logic here is far from robust. Improvements are welcome. + + +def update_mercurial_repo( + hg: str, + repo, + path: Union[str, Path], + revision="default", + hostfingerprints=None, + global_args=None, +): + """Ensure a HG repository exists at a path and is up to date.""" + hostfingerprints = hostfingerprints or {} + + path = Path(path) + + args = [hg] + if global_args: + args.extend(global_args) + + for host, fingerprint in sorted(hostfingerprints.items()): + args.extend(["--config", "hostfingerprints.%s=%s" % (host, fingerprint)]) + + if path.exists(): + subprocess.check_call(args + ["pull", repo], cwd=str(path)) + else: + subprocess.check_call(args + ["clone", repo, str(path)]) + + subprocess.check_call([hg, "update", "-r", revision], cwd=str(path)) |