poky/meta/lib/oeqa/utils/git.py
Markus Lehtonen 7fcc9f5ead oeqa.utils.git: support git commands with updated env
Extend GitRepo.run_cmd so that the caller may redefine and/or define
additional environment variables that will be used when the git command
is run.

(From OE-Core rev: 9b3c7c47f5d0fa473fe1db81b59b26531414781c)

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2016-08-25 23:03:46 +01:00

43 lines
1.3 KiB
Python

#
# 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, env_update=None):
"""Run Git command"""
env = None
if env_update:
env = os.environ.copy()
env.update(env_update)
return self._run_git_cmd_at(git_args, self.top_dir, env=env)