<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def files_to_check(commit_only):
 """ Validate the commit diff. Make copies of the staged changes for analysis. """

    global TEMP_FOLDER
    safe_directory = tempfile.mkdtemp()
    TEMP_FOLDER = safe_directory

    files = get_files(commit_only=commit_only, copy_dest=safe_directory)

    try:
        yield files
    finally:
        shutil.rmtree(safe_directory)