mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
cmake: refactor GitUtilities.cmake
Remote branch name can now be resolved from detached HEAD.
This commit is contained in:
parent
2533ebba23
commit
aaecabf4d6
1 changed files with 35 additions and 35 deletions
|
|
@ -6,54 +6,54 @@ endif()
|
|||
|
||||
set(__GitUtilities ON)
|
||||
|
||||
function(git_describe variable path)
|
||||
execute_process(COMMAND "${GIT_EXECUTABLE}" "describe"
|
||||
WORKING_DIRECTORY "${path}"
|
||||
RESULT_VARIABLE result
|
||||
macro(_git_command)
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" ${ARGN}
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
OUTPUT_VARIABLE output
|
||||
ERROR_QUIET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
endmacro()
|
||||
|
||||
macro(_git_easy_command)
|
||||
_git_command(${ARGN})
|
||||
set(${variable} "${output}" PARENT_SCOPE)
|
||||
endmacro()
|
||||
|
||||
function(git_current_branch variable)
|
||||
_git_command(symbolic-ref -q --short HEAD)
|
||||
|
||||
# If a detached head, a ref could still be resolved.
|
||||
if("${output}" STREQUAL "")
|
||||
_git_command(describe --all --exact-match)
|
||||
|
||||
# Get the ref, in the form heads/master or
|
||||
# remotes/origin/master so isolate the final part.
|
||||
string(REGEX REPLACE ".*/" "" output "${output}")
|
||||
endif()
|
||||
|
||||
set(${variable} "${output}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(git_current_branch variable path)
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} "symbolic-ref" "--short" "HEAD"
|
||||
WORKING_DIRECTORY "${path}"
|
||||
RESULT_VARIABLE result
|
||||
OUTPUT_VARIABLE output
|
||||
ERROR_QUIET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
set(${variable} "${output}" PARENT_SCOPE)
|
||||
function(git_latest_commit variable)
|
||||
_git_easy_command(rev-parse --short HEAD)
|
||||
endfunction()
|
||||
|
||||
function(git_latest_commit variable path)
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} "rev-parse" "--short" "HEAD"
|
||||
WORKING_DIRECTORY "${path}"
|
||||
RESULT_VARIABLE result
|
||||
OUTPUT_VARIABLE output
|
||||
ERROR_QUIET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
set(${variable} "${output}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(git_working_tree_dirty variable path)
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} "status" "--porcelain" "-uno"
|
||||
WORKING_DIRECTORY "${path}"
|
||||
RESULT_VARIABLE result
|
||||
OUTPUT_VARIABLE output
|
||||
ERROR_QUIET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
function(git_working_tree_dirty variable)
|
||||
_git_command(status --porcelain -uno)
|
||||
|
||||
if(output STREQUAL "")
|
||||
set(${variable} FALSE PARENT_SCOPE)
|
||||
else()
|
||||
set(${variable} TRUE PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
endfunction()
|
||||
|
||||
function(git_summary variable)
|
||||
_git_easy_command(log -1 "--format=%h %s")
|
||||
endfunction()
|
||||
|
||||
function(get_git_dir variable)
|
||||
_git_easy_command(rev-parse --git-dir)
|
||||
endfunction()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue