From 8af4a16bea4e610caf75dc0adfd42de5cedcc243 Mon Sep 17 00:00:00 2001 From: Andreas Jaeger Date: Sun, 22 Sep 2013 10:53:36 +0200 Subject: [PATCH] Fix validate.py and test.py traversals The get_modified_files call needs to be run from the doc directory since we invoce it with --relative. I noticed that we skipped validation of files in some case and confirmed that this is now handled properly. Change-Id: Ieaa5bfb2f7ada6345dba8b6b4116f17dff582fe1 Closes-Bug: #1228777 --- test.py | 16 +++++++++++----- validate.py | 14 ++++++++++---- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/test.py b/test.py index af0f6435..c103ccf5 100755 --- a/test.py +++ b/test.py @@ -155,7 +155,14 @@ def only_www_touched(): return www_changed and not other_changed -def get_modified_files(): +def get_modified_files(rootdir): + """Get modified files below doc directory""" + + # There are several tree traversals in this program that do a + # chroot, we need to run this git command always from the rootdir, + # so assure that. + os.chdir(rootdir) + try: args = ["git", "diff", "--name-only", "--relative", "HEAD", "HEAD~1"] modified_files = check_output(args).strip().split() @@ -169,7 +176,7 @@ def check_deleted_files(rootdir, file_exceptions): """ print("\nChecking for removed files") - modified_files = get_modified_files() + modified_files = get_modified_files(rootdir) deleted_files = [] any_removed = False for f in modified_files: @@ -228,11 +235,10 @@ def validate_individual_files(rootdir, exceptions, force=False, niceness=False, schema = get_schema() any_failures = False - modified_files = get_modified_files() if force: print("\nValidating all files") else: - modified_files = get_modified_files() + modified_files = get_modified_files(rootdir) print("\nFollowing files will be validated:") for f in modified_files: print(">>> %s" % f) @@ -306,7 +312,7 @@ def build_affected_books(rootdir, book_exceptions, file_exceptions, force=False, This will throw an exception if a book fails to build """ - modified_files = get_modified_files() + modified_files = get_modified_files(rootdir) modified_files = map(lambda x: os.path.abspath(x), modified_files) affected_books = [] books = [] diff --git a/validate.py b/validate.py index 60c91b69..c70903b8 100755 --- a/validate.py +++ b/validate.py @@ -157,7 +157,13 @@ def only_www_touched(): return www_changed and not other_changed -def get_modified_files(): +def get_modified_files(rootdir): + """Get modified files below doc directory""" + + # There are several tree traversals in this program that do a + # chroot, we need to run this git command always from the rootdir, + # so assure that. + os.chdir(rootdir) try: args = ["git", "diff", "--name-only", "--relative", "HEAD", "HEAD~1"] modified_files = check_output(args).strip().split() @@ -172,7 +178,7 @@ def check_deleted_files(rootdir, file_exceptions): """ print("\nChecking for removed files") - modified_files = get_modified_files() + modified_files = get_modified_files(rootdir) deleted_files = [] any_removed = False for f in modified_files: @@ -235,7 +241,7 @@ def validate_individual_files(rootdir, exceptions, force): if force: print("\nValidating all files") else: - modified_files = get_modified_files() + modified_files = get_modified_files(rootdir) print("\nFollowing files will be validated:") for f in modified_files: print(">>> %s" % f) @@ -306,7 +312,7 @@ def build_affected_books(rootdir, book_exceptions, file_exceptions, force): This will throw an exception if a book fails to build """ - modified_files = get_modified_files() + modified_files = get_modified_files(rootdir) modified_files = map(lambda x: os.path.abspath(x), modified_files) affected_books = [] books = []