Backed out 4 changesets (bug 1825722) for causing reftest failures CLOSED TREE
[gecko.git] / testing / web-platform / vcs.py
blobae555cd2bcb0269299d3e7ace81e83b3f269b7ff
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 import os
6 import subprocess
9 class Mercurial(object):
10 def __init__(self, repo_root):
11 self.root = os.path.abspath(repo_root)
12 self.hg = Mercurial.get_func(repo_root)
14 @staticmethod
15 def get_func(repo_root):
16 def hg(cmd, *args):
17 full_cmd = ["hg", cmd] + list(args)
18 return subprocess.check_output(full_cmd, cwd=repo_root)
19 # TODO: Test on Windows.
21 return hg
23 @staticmethod
24 def is_hg_repo(repo_root):
25 try:
26 with open(os.devnull, "w") as devnull:
27 subprocess.check_call(
28 ["hg", "root"], cwd=repo_root, stdout=devnull, stderr=devnull
30 except subprocess.CalledProcessError:
31 return False
32 except OSError:
33 return False
34 # TODO: Test on windows
35 return True
38 class Git(object):
39 def __init__(self, repo_root, url_base):
40 self.root = os.path.abspath(repo_root)
41 self.git = Git.get_func(repo_root)
43 @staticmethod
44 def get_func(repo_root):
45 def git(cmd, *args):
46 full_cmd = ["git", cmd] + list(args)
47 return subprocess.check_output(full_cmd, cwd=repo_root)
48 # TODO: Test on Windows.
50 return git
52 @staticmethod
53 def is_git_repo(repo_root):
54 try:
55 with open(os.devnull, "w") as devnull:
56 subprocess.check_call(
57 ["git", "rev-parse", "--show-cdup"],
58 cwd=repo_root,
59 stdout=devnull,
60 stderr=devnull,
62 except subprocess.CalledProcessError:
63 return False
64 except OSError:
65 return False
66 # TODO: Test on windows
67 return True