Fix ansible-test handling of submodules.

Resolves https://github.com/ansible/ansible/issues/61550
pull/61566/head
Matt Clay 5 years ago committed by Toshio Kuratomi
parent 3881326ae2
commit 2215a62057

@ -2,6 +2,8 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import re
from . import types as t
from .util import (
@ -35,6 +37,13 @@ class Git:
cmd = ['diff', '--name-only', '--no-renames', '-z'] + args
return self.run_git_split(cmd, '\0')
def get_submodule_paths(self): # type: () -> t.List[str]
"""Return a list of submodule paths recursively."""
cmd = ['submodule', 'status', '--recursive']
output = self.run_git_split(cmd, '\n')
submodule_paths = [re.search(r'^.[0-9a-f]+ (?P<path>[^ ]+)', line).group('path') for line in output]
return submodule_paths
def get_file_names(self, args):
"""
:type args: list[str]

@ -30,6 +30,19 @@ class GitSource(SourceProvider):
"""Return the list of available content paths under the given path."""
git = Git(path)
paths = self.__get_paths(path)
submodule_paths = git.get_submodule_paths()
for submodule_path in submodule_paths:
paths.extend(os.path.join(submodule_path, p) for p in self.__get_paths(os.path.join(path, submodule_path)))
return paths
@staticmethod
def __get_paths(path): # type: (str) -> t.List[str]
"""Return the list of available content paths under the given path."""
git = Git(path)
paths = git.get_file_names(['--cached', '--others', '--exclude-standard'])
deleted_paths = git.get_file_names(['--deleted'])
paths = sorted(set(paths) - set(deleted_paths))

Loading…
Cancel
Save