diff --git a/test/lib/ansible_test/_internal/git.py b/test/lib/ansible_test/_internal/git.py index 28d946ade43..ae2388b452f 100644 --- a/test/lib/ansible_test/_internal/git.py +++ b/test/lib/ansible_test/_internal/git.py @@ -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[^ ]+)', line).group('path') for line in output] + return submodule_paths + def get_file_names(self, args): """ :type args: list[str] diff --git a/test/lib/ansible_test/_internal/provider/source/git.py b/test/lib/ansible_test/_internal/provider/source/git.py index 59ad6bdea75..7ad2b97fa45 100644 --- a/test/lib/ansible_test/_internal/provider/source/git.py +++ b/test/lib/ansible_test/_internal/provider/source/git.py @@ -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))