Simplify Git class in ansible-test.

pull/58485/head
Matt Clay 6 years ago
parent cf7ee8eb12
commit 4403f866e3

@ -304,7 +304,7 @@ def get_git_details(args):
return git_details return git_details
def get_merged_commit(args, commit): def get_merged_commit(args, commit): # pylint: disable=unused-argument
""" """
:type args: CommonConfig :type args: CommonConfig
:type commit: str :type commit: str
@ -313,7 +313,7 @@ def get_merged_commit(args, commit):
if not commit: if not commit:
return None return None
git = Git(args) git = Git()
try: try:
show_commit = git.run_git(['show', '--no-patch', '--no-abbrev', commit]) show_commit = git.run_git(['show', '--no-patch', '--no-abbrev', commit])

@ -1419,7 +1419,7 @@ def detect_changes_shippable(args):
:type args: TestConfig :type args: TestConfig
:rtype: list[str] | None :rtype: list[str] | None
""" """
git = Git(args) git = Git()
result = ShippableChanges(args, git) result = ShippableChanges(args, git)
if result.is_pr: if result.is_pr:
@ -1442,7 +1442,7 @@ def detect_changes_local(args):
:type args: TestConfig :type args: TestConfig
:rtype: list[str] :rtype: list[str]
""" """
git = Git(args) git = Git()
result = LocalChanges(args, git) result = LocalChanges(args, git)
display.info('Detected branch %s forked from %s at commit %s' % ( display.info('Detected branch %s forked from %s at commit %s' % (

@ -2,21 +2,25 @@
from __future__ import absolute_import, print_function from __future__ import absolute_import, print_function
try:
# noinspection PyUnresolvedReferences
from typing import (
Optional,
)
except ImportError:
pass
from lib.util import ( from lib.util import (
CommonConfig,
SubprocessError, SubprocessError,
run_command, raw_command,
) )
class Git(object): class Git(object):
"""Wrapper around git command-line tools.""" """Wrapper around git command-line tools."""
def __init__(self, args): def __init__(self, root=None): # type: (Optional[str]) -> None
"""
:type args: CommonConfig
"""
self.args = args
self.git = 'git' self.git = 'git'
self.root = root
def get_diff(self, args, git_options=None): def get_diff(self, args, git_options=None):
""" """
@ -117,4 +121,4 @@ class Git(object):
:type str_errors: str :type str_errors: str
:rtype: 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]

Loading…
Cancel
Save