提交 6323773d 编写于 作者: C Cleber Rosa

avocado/core/job.py: don't attempt to run git if .git doesn't exist

When looking for the GIT commit info to log in the Avocado job log,
we can optmize things a little by not running git if the ".git" directory
doesn't exist at the top level.

py2to3 is not being used anymore, so we don't need to check if we're
running from modules from the build directory.

Also, as another optmization, let's not look for the git binary until
we're sure we'll be running it.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 051d7277
......@@ -329,23 +329,28 @@ class Job(object):
@staticmethod
def _get_avocado_git_version():
# if running from git sources, there will be a ".git" directory
# 3 levels up
base_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
git_dir = os.path.join(base_dir, '.git')
if not os.path.isdir(git_dir):
return
if not os.path.exists(os.path.join(base_dir, 'python-avocado.spec')):
return
try:
git = path.find_command('git')
except path.CmdNotFoundError:
return
# We need to get git root as `py2to3` creates this file in BUILD
olddir = os.getcwd()
try:
os.chdir(os.path.dirname(__file__))
git_root = process.run('%s rev-parse --show-toplevel' % git,
ignore_status=True, verbose=False)
if git_root.exit_status == 0 and os.path.exists(os.path.join(
git_root.stdout.strip(), 'python-avocado.spec')):
cmd = "%s show --summary --pretty='%%H'" % git
res = process.run(cmd, ignore_status=True, verbose=False)
if res.exit_status == 0:
top_commit = res.stdout.splitlines()[0][:8]
return " (GIT commit %s)" % top_commit
os.chdir(base_dir)
cmd = "%s show --summary --pretty='%%H'" % git
res = process.run(cmd, ignore_status=True, verbose=False)
if res.exit_status == 0:
top_commit = res.stdout.splitlines()[0][:8]
return " (GIT commit %s)" % top_commit
finally:
os.chdir(olddir)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册