Skip to content

Commit

Permalink
Fix CMake version info bad quoting (#501)
Browse files Browse the repository at this point in the history
* Fix quote escaping in commit message

* This is a "Test
message"

* Update to latest cmake-git-version-tracking git_watcher cmake file

Listed permalink to make it easier to diff any future changes
  • Loading branch information
ekilmer authored Apr 3, 2021
1 parent 2eaf52c commit 142ab2f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cmake/git_watcher.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# git_watcher.cmake
# https://raw.githubusercontent.com/andrew-hardin/cmake-git-version-tracking/master/git_watcher.cmake
# https://github.com/andrew-hardin/cmake-git-version-tracking/blob/20c58d5d08bad70550d969b478943c962faa6264/git_watcher.cmake
#
# Released under the MIT License.
# https://raw.githubusercontent.com/andrew-hardin/cmake-git-version-tracking/master/LICENSE
Expand Down Expand Up @@ -158,13 +158,16 @@ function(GetGitState _working_dir)

RunGitCommand(show -s "--format=%s" ${object})
if(exit_code EQUAL 0)
# Escape quotes
string(REPLACE "\"" "\\\"" output "${output}")
set(ENV{GIT_COMMIT_SUBJECT} "${output}")
endif()

RunGitCommand(show -s "--format=%b" ${object})
if(exit_code EQUAL 0)
if(output)
# Escape quotes
string(REPLACE "\"" "\\\"" output "${output}")
# Escape line breaks in the commit message.
string(REPLACE "\r\n" "\\r\\n\\\r\n" safe "${output}")
if(safe STREQUAL output)
Expand All @@ -180,6 +183,14 @@ function(GetGitState _working_dir)
set(ENV{GIT_COMMIT_BODY} "\"\"") # empty string.
endif()

# Get output of git describe
RunGitCommand(describe --always ${object})
if(NOT exit_code EQUAL 0)
set(ENV{GIT_DESCRIBE} "unknown")
else()
set(ENV{GIT_DESCRIBE} "${output}")
endif()

# >>>
# 2. Additional git properties can be added here via the
# "execute_process()" command. Be sure to set them in
Expand Down

0 comments on commit 142ab2f

Please sign in to comment.