Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check If Git Checked Out Completely in Testing #19

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions test/GitAssert.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Asserts whether a Git repository is checked out completely.
#
# Arguments:
# - DIRECTORY: The path of the directory to check out the Git repository.
function(assert_git_complete_checkout DIRECTORY)
if(NOT EXISTS ${DIRECTORY})
message(FATAL_ERROR "the '${DIRECTORY}' directory should exist")
endif()

execute_process(
COMMAND git -C ${DIRECTORY} diff --no-patch --exit-code
RESULT_VARIABLE RES
)
if(NOT RES EQUAL 0)
message(FATAL_ERROR "the repository should be checked out completely (${RES})")
endif()
endfunction()
22 changes: 8 additions & 14 deletions test/GitCheckoutTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@ endif()

set(TEST_COUNT 0)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})

include(GitAssert)
include(GitCheckout)

if("Check out a Git repository" MATCHES ${TEST_MATCHES})
math(EXPR TEST_COUNT "${TEST_COUNT} + 1")

if(EXISTS project-starter)
file(REMOVE_RECURSE project-starter)
endif()

include(GitCheckout)
git_checkout(https://github.com/threeal/project-starter)

if(NOT EXISTS project-starter)
message(FATAL_ERROR "The 'project-starter' directory should exist")
endif()
assert_git_complete_checkout(project-starter)
endif()

if("Check out an invalid Git repository" MATCHES ${TEST_MATCHES})
math(EXPR TEST_COUNT "${TEST_COUNT} + 1")

include(GitCheckout)
git_checkout(
https://github.com/threeal/invalid-project
ERROR_VARIABLE ERR
Expand All @@ -42,12 +43,9 @@ if("Check out a Git repository to a specific directory" MATCHES ${TEST_MATCHES})
file(REMOVE_RECURSE some-directory)
endif()

include(GitCheckout)
git_checkout(https://github.com/threeal/project-starter DIRECTORY some-directory)

if(NOT EXISTS some-directory)
message(FATAL_ERROR "The 'some-directory' directory should exist")
endif()
assert_git_complete_checkout(some-directory)
endif()

if("Check out a Git repository on a specific ref" MATCHES ${TEST_MATCHES})
Expand All @@ -57,12 +55,9 @@ if("Check out a Git repository on a specific ref" MATCHES ${TEST_MATCHES})
file(REMOVE_RECURSE project-starter)
endif()

include(GitCheckout)
git_checkout(https://github.com/threeal/project-starter REF 5a80d20)

if(NOT EXISTS project-starter)
message(FATAL_ERROR "The 'project-starter' directory should exist")
endif()
assert_git_complete_checkout(project-starter)

execute_process(
COMMAND git -C project-starter rev-parse --short HEAD
Expand All @@ -81,7 +76,6 @@ if("Check out a Git repository on a specific invalid ref" MATCHES ${TEST_MATCHES
file(REMOVE_RECURSE project-starter)
endif()

include(GitCheckout)
git_checkout(
https://github.com/threeal/project-starter
REF invalid-ref
Expand Down