Skip to content

Commit

Permalink
CMake: identify detached head state
Browse files Browse the repository at this point in the history
when describing repository branch/tag/commit
  • Loading branch information
dyfer committed Mar 2, 2022
1 parent 712c32e commit 8b18880
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions SCVersion.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
set(GIT_REF_TYPE "branch")

if(GIT_BRANCH_OR_TAG STREQUAL "HEAD")
set(GIT_REF_TYPE "tag")
execute_process(
COMMAND git describe --tags
COMMAND git describe --tags 2>/dev/null
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH_OR_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(GIT_BRANCH_OR_TAG STREQUAL "")
set(GIT_REF_TYPE "detached")
set(GIT_BRANCH_OR_TAG "HEAD")
else()
set(GIT_REF_TYPE "tag")
endif()
endif()

execute_process(
Expand Down

0 comments on commit 8b18880

Please sign in to comment.