aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2016-05-11 16:19:06 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-07-01 16:08:51 +0100
commit4eaf434f885afbda03fe67ab6e9ff291c7a9c77e (patch)
tree3b3a2b917eee320fa2b2368c9eeab1c23267e010
parentd5bbcdaf332b2a15382672d6a40b2d2b807b9dde (diff)
downloadopenembedded-core-contrib-4eaf434f885afbda03fe67ab6e9ff291c7a9c77e.tar.gz
openembedded-core-contrib-4eaf434f885afbda03fe67ab6e9ff291c7a9c77e.tar.bz2
openembedded-core-contrib-4eaf434f885afbda03fe67ab6e9ff291c7a9c77e.zip
oeqa.utils: add git module
A new helper module for easier interaction with Git repositories. Provides GitRepo class that represents one local Git repository clone. The GitRepo class currently only has one method, run_cmd(), for running arbitrary git commands in the repository. More specialized methods for commonly used git operations can be added later. Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com>
-rw-r--r--meta/lib/oeqa/utils/git.py38
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 00000000000..a4c6741f4e5
--- /dev/null
+++ b/meta/lib/oeqa/utils/git.py
@@ -0,0 +1,38 @@
+#
+# Copyright (C) 2016 Intel Corporation
+#
+# Released under the MIT license (see COPYING.MIT)
+#
+"""Git repository interactions"""
+from oeqa.utils.commands import runCmd
+
+
+class GitError(Exception):
+ """Git error handling"""
+ pass
+
+class GitRepo(object):
+ """Class representing a Git repository clone"""
+ def __init__(self, cwd):
+ self.top_dir = self._run_git_cmd_at(['rev-parse', '--show-toplevel'],
+ cwd)
+
+ @staticmethod
+ def _run_git_cmd_at(git_args, cwd, **kwargs):
+ """Run git command at a specified directory"""
+ git_cmd = 'git ' if isinstance(git_args, str) else ['git']
+ git_cmd += git_args
+ ret = runCmd(git_cmd, ignore_status=True, cwd=cwd, **kwargs)
+ if ret.status:
+ cmd_str = git_cmd if isinstance(git_cmd, str) \
+ else ' '.join(git_cmd)
+ raise GitError("'{}' failed with exit code {}: {}".format(
+ cmd_str, ret.status, ret.output))
+ return ret.output.strip()
+
+ def run_cmd(self, git_args):
+ """Run Git command"""
+ return self._run_git_cmd_at(git_args, self.top_dir)
+
+
+