From 293e624235ecf969b7ba8faf3549cb6caa4ad95a Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Fri, 3 Mar 2017 16:51:01 -0600 Subject: [PATCH] Support matching original path for a moved module location --- test/sanity/validate-modules/validate-modules | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/sanity/validate-modules/validate-modules b/test/sanity/validate-modules/validate-modules index ff8da79c2d0..ac7c1779e16 100755 --- a/test/sanity/validate-modules/validate-modules +++ b/test/sanity/validate-modules/validate-modules @@ -270,8 +270,23 @@ class ModuleValidator(Validator): except AttributeError: return False + def _get_base_branch_module_path(self): + """List all paths within lib/ansible/modules to try and match a moved module""" + command = ['git', 'ls-tree', '-r', '--name-only', self.base_branch, 'lib/ansible/modules/'] + p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = p.communicate() + + for path in stdout.splitlines(): + if path.endswith('/%s' % self.object_name): + return path + + return None + def _get_base_file(self): - command = ['git', 'show', '%s:%s' % (self.base_branch, self.path)] + # In case of module moves, look for the original location + base_path = self._get_base_branch_module_path() + + command = ['git', 'show', '%s:%s' % (self.base_branch, base_path or self.path)] p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate()