Skip to content

Commit 4989a3c

Browse files
committed
[SofaMacros] Improve sofa_install_git_infos (#2373)
1 parent 00a0979 commit 4989a3c

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

SofaKernel/modules/Sofa.Config/cmake/SofaMacrosInstall.cmake

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -908,31 +908,53 @@ function(sofa_install_git_infos name sourcedir)
908908
endif()
909909
install(CODE "
910910
find_package(Git REQUIRED)
911-
# get the current working branch
911+
# get the current commit sha
912912
execute_process(
913-
COMMAND \${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
913+
COMMAND \${GIT_EXECUTABLE} rev-parse HEAD
914+
WORKING_DIRECTORY \"${sourcedir}\"
915+
OUTPUT_VARIABLE CURRENT_GIT_COMMIT
916+
OUTPUT_STRIP_TRAILING_WHITESPACE
917+
)
918+
# get the branches containing current commit
919+
execute_process(
920+
COMMAND \${GIT_EXECUTABLE} branch -a --contains \"\${CURRENT_GIT_COMMIT}\"
914921
WORKING_DIRECTORY \"${sourcedir}\"
915922
OUTPUT_VARIABLE CURRENT_GIT_BRANCH
916923
OUTPUT_STRIP_TRAILING_WHITESPACE
917924
)
918-
# get the current commit info (hash, author, date, comment)
925+
# get the current remotes
926+
execute_process(
927+
COMMAND \${GIT_EXECUTABLE} remote -vv
928+
WORKING_DIRECTORY \"${sourcedir}\"
929+
OUTPUT_VARIABLE CURRENT_GIT_REMOTE
930+
OUTPUT_STRIP_TRAILING_WHITESPACE
931+
)
932+
# get more info (hash, author, date, comment)
919933
execute_process(
920934
COMMAND \${GIT_EXECUTABLE} log --pretty -n 1
921935
WORKING_DIRECTORY \"${sourcedir}\"
922936
OUTPUT_VARIABLE CURRENT_GIT_INFO
923937
OUTPUT_STRIP_TRAILING_WHITESPACE
924938
)
925-
# write all infos in git-infos.txt
926-
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/git-infos.txt\"
927-
\"------ Git infos for ${name} ------\" \\n
928-
\\n
929-
\"---- Branch ----\" \\n
930-
\"\${CURRENT_GIT_BRANCH}\" \\n
931-
\\n
932-
\"---- Latest commit ----\" \\n
933-
\"\${CURRENT_GIT_INFO}\" \\n
934-
\\n
935-
\"-----------------------------------\" \\n
939+
# write all info in git-info.txt
940+
file(WRITE \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/git-info.txt\"
941+
\"# Git info for ${name}\" \\n
942+
\\n
943+
\"## Current commit\" \\n
944+
\"## git rev-parse --abbrev-ref HEAD\" \\n
945+
\"\${CURRENT_GIT_COMMIT}\" \\n
946+
\\n
947+
\"## Branches containing current commit\" \\n
948+
\"## git branch -a --contains \${CURRENT_GIT_COMMIT} \" \\n
949+
\"\${CURRENT_GIT_BRANCH}\" \\n
950+
\\n
951+
\"## Remotes\" \\n
952+
\"## git remote -vv \" \\n
953+
\"\${CURRENT_GIT_REMOTE}\" \\n
954+
\\n
955+
\"## More info\" \\n
956+
\"## git log --pretty -n 1\" \\n
957+
\"\${CURRENT_GIT_INFO}\" \\n
936958
)
937959
"
938960
COMPONENT resources

0 commit comments

Comments
 (0)