From 4403f866e3d1ec3d7fbcc6b208cd690e0e754955 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Thu, 27 Jun 2019 12:00:26 -0700 Subject: [PATCH] Simplify Git class in ansible-test. --- test/runner/lib/env.py | 4 ++-- test/runner/lib/executor.py | 4 ++-- test/runner/lib/git.py | 20 ++++++++++++-------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/test/runner/lib/env.py b/test/runner/lib/env.py index 03cfc0daa35..f73bb608b63 100644 --- a/test/runner/lib/env.py +++ b/test/runner/lib/env.py @@ -304,7 +304,7 @@ def get_git_details(args): return git_details -def get_merged_commit(args, commit): +def get_merged_commit(args, commit): # pylint: disable=unused-argument """ :type args: CommonConfig :type commit: str @@ -313,7 +313,7 @@ def get_merged_commit(args, commit): if not commit: return None - git = Git(args) + git = Git() try: show_commit = git.run_git(['show', '--no-patch', '--no-abbrev', commit]) diff --git a/test/runner/lib/executor.py b/test/runner/lib/executor.py index c3442b5562b..70359cb54ee 100644 --- a/test/runner/lib/executor.py +++ b/test/runner/lib/executor.py @@ -1419,7 +1419,7 @@ def detect_changes_shippable(args): :type args: TestConfig :rtype: list[str] | None """ - git = Git(args) + git = Git() result = ShippableChanges(args, git) if result.is_pr: @@ -1442,7 +1442,7 @@ def detect_changes_local(args): :type args: TestConfig :rtype: list[str] """ - git = Git(args) + git = Git() result = LocalChanges(args, git) display.info('Detected branch %s forked from %s at commit %s' % ( diff --git a/test/runner/lib/git.py b/test/runner/lib/git.py index a06e4c8162b..f195f959639 100644 --- a/test/runner/lib/git.py +++ b/test/runner/lib/git.py @@ -2,21 +2,25 @@ from __future__ import absolute_import, print_function +try: + # noinspection PyUnresolvedReferences + from typing import ( + Optional, + ) +except ImportError: + pass + from lib.util import ( - CommonConfig, SubprocessError, - run_command, + raw_command, ) class Git(object): """Wrapper around git command-line tools.""" - def __init__(self, args): - """ - :type args: CommonConfig - """ - self.args = args + def __init__(self, root=None): # type: (Optional[str]) -> None self.git = 'git' + self.root = root def get_diff(self, args, git_options=None): """ @@ -117,4 +121,4 @@ class Git(object): :type str_errors: str :rtype: str """ - return run_command(self.args, [self.git] + cmd, capture=True, always=True, str_errors=str_errors)[0] + return raw_command([self.git] + cmd, cwd=self.root, capture=True, str_errors=str_errors)[0]