How to use custom git command when building on remote host?

Answered

I am in the process of transferring a project from being built with MinGW to using a remote host on a Linux VM because of how much faster the build times are. Everything so far has been smooth except for one issue.

My project uses a git command to get the current commit hash for inserting into a version.h file, but when git runs on the remote host, it fails out with 

fatal: not a git repository (or any of the parent directories): .git

Which makes sense, as CLION didn't send any git information over to the remote host. Is there an easy solution to this? For reference, the command I'm using is below:

# Get the hash for HEAD.
set(_success "true")
execute_process(COMMAND
"${GIT_EXECUTABLE}" rev-parse --verify HEAD
WORKING_DIRECTORY "${_working_dir}"
RESULT_VARIABLE res
OUTPUT_VARIABLE _hashvar
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT res EQUAL 0)
set(_success "false")
set(_hashvar "GIT-NOTFOUND")
endif()
execute_process(COMMAND
"${GIT_EXECUTABLE}" describe --dirty
WORKING_DIRECTORY "${_working_dir}"
RESULT_VARIABLE res
OUTPUT_VARIABLE _version
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
2 comments
Comment actions Permalink

Hello!

Remote VCS support is not implemented yet: https://youtrack.jetbrains.com/issue/CPP-14482. Feel free to comment or upvote the issue in order to get updates. See https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications if you are not familiar with YouTrack.

If it's critical for your project you can remove .git from "Exclude items by name" list and then re-upload your project again. Please see this comment for more details.

0
Comment actions Permalink

Thank you so much for your response! I will test this out and see if it works.

0

Please sign in to leave a comment.