mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-16 22:27:41 -05:00
* Check that the cache working directory is clean * cpm_check_working_dir_is_clean for non git repo will not terminate cmake * sileneced check for git repo, in case of error * style(CPM.cmake): fixed indentation for ERROR_QUIET * refactor(CPM.cmake): added logic to handle a cache folder inside a (not correlated) git repo this is accomplished by checking if we are in the directory where .git lives * style(CPM.cmake): stray tab to spaces * test(dirty-cache-check): added unit test to check cpm_check_working_dir_is_clean the test creates a file in a folder and then uses git to create a repo in that folder, to check various conditions * Update test/unit/dirty-cache-check.cmake added user.name and user.email to comply with test machine where git is not completely configured Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com> * feat(cpm_check_working_dir_is_clean): now it takes a git tag (works with hashes too) to check for uncommitted and commited changes * refactor(cpm_check_working_dir_is_clean): early return for the most common case of uncommited changes in a repo * refactor(cpm_check_git_working_dir_is_clean): removed edgecase detection (a non-git folder in an unrelated git repo) now the contract is that com_check_git_working_dir_is_clean is given the base folder of a git repo Co-authored-by: Andrew Gribble <ag131012@renishaw.com> Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>
50 lines
1.5 KiB
CMake
50 lines
1.5 KiB
CMake
include(${CPM_PATH}/CPM.cmake)
|
|
include(${CPM_PATH}/testing.cmake)
|
|
|
|
set(baseDir "${CMAKE_CURRENT_BINARY_DIR}/test_dirty_cache")
|
|
|
|
find_package(Git REQUIRED)
|
|
|
|
function(git_do dir)
|
|
execute_process(
|
|
COMMAND ${GIT_EXECUTABLE} -c user.name='User' -c user.email='user@email.org' ${ARGN}
|
|
RESULT_VARIABLE result
|
|
OUTPUT_VARIABLE status
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
WORKING_DIRECTORY "${dir}"
|
|
)
|
|
if(result)
|
|
message(FATAL_ERROR "git ${ARGN} fail: ${result} ${status}")
|
|
endif()
|
|
endfunction()
|
|
|
|
file(MAKE_DIRECTORY "${baseDir}")
|
|
|
|
file(WRITE "${baseDir}/draft.txt" "this is a test")
|
|
|
|
git_do("${baseDir}" init -b main)
|
|
git_do("${baseDir}" commit --allow-empty -m "empty repo")
|
|
message(STATUS "empty repo with file")
|
|
cpm_check_git_working_dir_is_clean(${baseDir} HEAD emptygit_test)
|
|
assert_falsy(emptygit_test)
|
|
|
|
git_do("${baseDir}" add draft.txt)
|
|
git_do("${baseDir}" commit -m "test change")
|
|
git_do("${baseDir}" tag v0.0.0)
|
|
message(STATUS "commit a change")
|
|
cpm_check_git_working_dir_is_clean(${baseDir} v0.0.0 onecommit_test)
|
|
assert_truthy(onecommit_test)
|
|
|
|
file(WRITE "${baseDir}/draft.txt" "a modification")
|
|
message(STATUS "dirty repo")
|
|
cpm_check_git_working_dir_is_clean(${baseDir} v0.0.0 nonemptygit_test)
|
|
assert_falsy(nonemptygit_test)
|
|
|
|
git_do("${baseDir}" add draft.txt)
|
|
git_do("${baseDir}" commit -m "another change")
|
|
message(STATUS "repo clean")
|
|
cpm_check_git_working_dir_is_clean(${baseDir} v0.0.0 twocommit_test)
|
|
assert_falsy(twocommit_test)
|
|
|
|
file(REMOVE_RECURSE "${baseDir}")
|