Skip to content

Commit

Permalink
Don't let get_git_head_revision go above the CMAKE_SOURCE_DIR, for sa…
Browse files Browse the repository at this point in the history
…fety.

Think this should fix #58
  • Loading branch information
rpavlik committed Aug 5, 2020
1 parent fc454f1 commit 43a50aa
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion GetGitRevisionDescription.cmake
Expand Up @@ -78,8 +78,16 @@ endfunction()

function(get_git_head_revision _refspecvar _hashvar)
find_closest_git_dir("${CMAKE_CURRENT_SOURCE_DIR}" GIT_DIR)

if(NOT "${GIT_DIR}" STREQUAL "")
file(RELATIVE_PATH _relative_to_source_dir "${CMAKE_SOURCE_DIR}" "${GIT_DIR}")
if("${_relative_to_source_dir}" MATCHES "[.][.]")
# We've gone above the CMake root dir.
set(GIT_DIR "")
endif()
endif()
if("${GIT_DIR}" STREQUAL "")
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
return()
endif()
Expand Down

0 comments on commit 43a50aa

Please sign in to comment.