diff options
-rw-r--r-- | meta/lib/oeqa/utils/git.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/meta/lib/oeqa/utils/git.py b/meta/lib/oeqa/utils/git.py new file mode 100644 index 0000000000..a4c6741f4e --- /dev/null +++ b/meta/lib/oeqa/utils/git.py | |||
@@ -0,0 +1,38 @@ | |||
1 | # | ||
2 | # Copyright (C) 2016 Intel Corporation | ||
3 | # | ||
4 | # Released under the MIT license (see COPYING.MIT) | ||
5 | # | ||
6 | """Git repository interactions""" | ||
7 | from oeqa.utils.commands import runCmd | ||
8 | |||
9 | |||
10 | class GitError(Exception): | ||
11 | """Git error handling""" | ||
12 | pass | ||
13 | |||
14 | class GitRepo(object): | ||
15 | """Class representing a Git repository clone""" | ||
16 | def __init__(self, cwd): | ||
17 | self.top_dir = self._run_git_cmd_at(['rev-parse', '--show-toplevel'], | ||
18 | cwd) | ||
19 | |||
20 | @staticmethod | ||
21 | def _run_git_cmd_at(git_args, cwd, **kwargs): | ||
22 | """Run git command at a specified directory""" | ||
23 | git_cmd = 'git ' if isinstance(git_args, str) else ['git'] | ||
24 | git_cmd += git_args | ||
25 | ret = runCmd(git_cmd, ignore_status=True, cwd=cwd, **kwargs) | ||
26 | if ret.status: | ||
27 | cmd_str = git_cmd if isinstance(git_cmd, str) \ | ||
28 | else ' '.join(git_cmd) | ||
29 | raise GitError("'{}' failed with exit code {}: {}".format( | ||
30 | cmd_str, ret.status, ret.output)) | ||
31 | return ret.output.strip() | ||
32 | |||
33 | def run_cmd(self, git_args): | ||
34 | """Run Git command""" | ||
35 | return self._run_git_cmd_at(git_args, self.top_dir) | ||
36 | |||
37 | |||
38 | |||