diff --git a/validate.py b/validate.py index 70975395..cf9b469d 100755 --- a/validate.py +++ b/validate.py @@ -135,6 +135,24 @@ def error_message(error_log): errs.reverse() return "\n".join(errs) +# Check whether only files in www got updated +def only_www_touched(): + try: + args = ["git", "diff", "--name-only", "HEAD", "HEAD~1"] + modified_files = check_output(args).strip().split() + except (CalledProcessError, OSError) as e: + print("git failed: %s" % e) + sys.exit(1) + + www_changed = False + other_changed = False + for f in modified_files: + if f.startswith("www/"): + www_changed = True + else: + other_changed = True + + return www_changed and not other_changed def get_modified_files(): try: @@ -345,6 +363,10 @@ def main(rootdir, force): if force: print("Validation of all files and build of all books will be forced.") + if not force and only_www_touched(): + print("Only files in www directory changed, no validation done.") + return + check_deleted_files(rootdir, FILE_EXCEPTIONS) validate_individual_files(rootdir, FILE_EXCEPTIONS, force) build_affected_books(rootdir, BOOK_EXCEPTIONS, FILE_EXCEPTIONS, force)