Fix ccrash if remote is not set (#2291)

This commit is contained in:
kalaposfos13 2025-01-30 23:14:13 +01:00 committed by GitHub
parent b5d63a31cc
commit be74f65864
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 6 deletions

View file

@ -106,21 +106,27 @@ git_describe(GIT_DESC --always --long --dirty)
git_branch_name(GIT_BRANCH)
string(TIMESTAMP BUILD_DATE "%Y-%m-%d %H:%M:%S")
# Get current remote name and branch
# Try to get the upstream remote and branch
execute_process(
COMMAND git rev-parse --abbrev-ref --symbolic-full-name @{u}
OUTPUT_VARIABLE GIT_REMOTE_NAME
RESULT_VARIABLE GIT_BRANCH_RESULT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Default to origin if branch is not set
# Default to origin if there's no upstream set or if the command failed
if (GIT_BRANCH_RESULT OR GIT_REMOTE_NAME STREQUAL "")
set(GIT_REMOTE_NAME "origin")
else()
# Extract remote name from full name
# Extract remote name if the output contains a remote/branch format
string(FIND "${GIT_REMOTE_NAME}" "/" INDEX)
string(SUBSTRING "${GIT_REMOTE_NAME}" 0 "${INDEX}" GIT_REMOTE_NAME)
if (INDEX GREATER -1)
string(SUBSTRING "${GIT_REMOTE_NAME}" 0 "${INDEX}" GIT_REMOTE_NAME)
else()
# If no remote is present (only a branch name), default to origin
set(GIT_REMOTE_NAME "origin")
endif()
endif()
# Get remote link