Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
RingRacers
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lactozilla
RingRacers
Commits
aaecabf4
Commit
aaecabf4
authored
2 years ago
by
James R.
Browse files
Options
Downloads
Patches
Plain Diff
cmake: refactor GitUtilities.cmake
Remote branch name can now be resolved from detached HEAD.
parent
2533ebba
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cmake/Modules/GitUtilities.cmake
+32
-32
32 additions, 32 deletions
cmake/Modules/GitUtilities.cmake
with
32 additions
and
32 deletions
cmake/Modules/GitUtilities.cmake
+
32
−
32
View file @
aaecabf4
...
...
@@ -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
)
end
function
()
end
macro
()
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
)
function
(
git_current_branch variable
)
_git_command
(
symbolic-ref -q --short HEAD
)
set
(
${
variable
}
"
${
output
}
"
PARENT_SCOPE
)
endfunction
()
# If a detached head, a ref could still be resolved.
if
(
"
${
output
}
"
STREQUAL
""
)
_git_command
(
describe --all --exact-match
)
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
)
# 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_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_latest_commit variable
)
_git_easy_command
(
rev-parse --short HEAD
)
endfunction
()
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
()
\ No newline at end of file
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
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment