#1937 use git branch --contains instead show

This commit is contained in:
Thomas Krijnen
2021-12-18 16:16:21 +01:00
parent 37d20eb360
commit 364c2286d1
+7 -9
View File
@@ -795,17 +795,15 @@ find_package (Git)
if (GIT_FOUND)
message("git found: ${GIT_EXECUTABLE} with version ${GIT_VERSION_STRING}")
execute_process(
COMMAND ${GIT_EXECUTABLE} show -s --pretty=%D HEAD
COMMAND ${GIT_EXECUTABLE} branch --contains HEAD
OUTPUT_VARIABLE git_branches
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REPLACE ", " ";" git_branch_list "${git_branches}")
string(REPLACE " -> " ";" git_branch_list "${git_branch_list}")
string(REPLACE "\n" ";" git_branch_list "${git_branches}")
foreach(git_branch_candidate IN ITEMS ${git_branch_list})
if (NOT git_branch_candidate MATCHES "/")
if (NOT git_branch_candidate MATCHES "^HEAD$")
set(git_branch ${git_branch_candidate})
endif()
string(STRIP "${git_branch_candidate}" git_branch_candidate_2)
if (NOT git_branch_candidate_2 MATCHES "^HEAD$")
set(git_branch ${git_branch_candidate_2})
endif()
endforeach()
execute_process(
@@ -813,8 +811,8 @@ if (GIT_FOUND)
OUTPUT_VARIABLE git_sha
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "IfcOpenShell branch ${git_branch}")
message(STATUS "IfcOpenShell commit ${git_sha}")
message(STATUS "IfcOpenShell branch: \"${git_branch}\"")
message(STATUS "IfcOpenShell commit: \"${git_sha}\"")
add_definitions(-DIFCOPENSHELL_BRANCH=${git_branch})
add_definitions(-DIFCOPENSHELL_COMMIT=${git_sha})
endif()