Files
CMake/Tests/CheckSourceTree/check.cmake
Brad King 8d453ee751 Tests: Improve CheckSourceTree test
Re-implement the test using simpler approach.  Enable it only when doing
an out-of-source build with a `.git` source.  Run it last, serially.
Re-use the `git` tool found for version computation.  Print the output
from `git status` without modification.  Rely on `.gitignore` instead
of filtering out paths ourselves.
2022-10-05 12:38:12 -04:00

23 lines
690 B
CMake

# Give Git access to the real home directory to get user's settings.
if(DEFINED ENV{CTEST_REAL_HOME})
set(ENV{HOME} "$ENV{CTEST_REAL_HOME}")
endif()
execute_process(
COMMAND "${GIT_EXECUTABLE}" status
WORKING_DIRECTORY "${CMake_SOURCE_DIR}"
OUTPUT_VARIABLE output
ERROR_VARIABLE output
RESULT_VARIABLE result
)
string(REPLACE "\n" "\n " output " ${output}")
if(NOT result EQUAL 0)
message(FATAL_ERROR "'git status' failed (${result}):\n${output}")
endif()
if(output MATCHES "\n[ \t#]*(Changes |new file:|modified:|Untracked )")
message(FATAL_ERROR "The source tree is not clean. 'git status' reports:\n${output}")
endif()
message(STATUS "The source tree is clean.")